예제 #1
0
        private Quaternion GetRotation(Quaternion inputRotation)
        {
            Vector3 resultDirection = _splineResult.direction;

            if (direction == Spline.Direction.Backward && !targetUser.averageResultVectors) //Handle orientation for backwards tracers
            {
                double clippedPercent = targetUser.ClipPercent(_splineResult.percent);
                int    clippedIndex   = targetUser.GetClippedSampleIndex(clippedPercent);
                for (int i = DMath.CeilInt(clippedPercent * (targetUser.clippedSamples.Length - 1)); i >= 0; i--)
                {
                    clippedIndex = i;
                    if (targetUser.ClipPercent(targetUser.clippedSamples[i].percent) < clippedPercent)
                    {
                        break;
                    }
                }
                //Find the two upcomming samples and lerp between their directions
                int          dirIndex = clippedIndex;
                SplineResult fromDir  = targetUser.clippedSamples[dirIndex];
                dirIndex--;
                if (dirIndex < 0)
                {
                    if (targetUser.span == 1.0 && targetUser.rootUser.computer.isClosed)
                    {
                        dirIndex = Mathf.Max(targetUser.clippedSamples.Length - 2, 0);
                    }
                    else
                    {
                        dirIndex = 0;
                    }
                }
                SplineResult toDir = targetUser.clippedSamples[dirIndex];
                resultDirection = Vector3.Slerp(fromDir.direction, toDir.direction, (float)DMath.InverseLerp(targetUser.ClipPercent(targetUser.clippedSamples[clippedIndex + 1].percent), targetUser.ClipPercent(targetUser.clippedSamples[clippedIndex].percent), targetUser.ClipPercent(_splineResult.percent)));
            }


            rotation = Quaternion.LookRotation(resultDirection * (direction == Spline.Direction.Forward ? 1f : -1f), _splineResult.normal);
            if (_rotationOffset != Vector3.zero)
            {
                rotation = rotation * Quaternion.Euler(_rotationOffset);
            }
            if (customRotation != null)
            {
                rotation = customRotation.Evaluate(rotation, _splineResult.percent);
            }
            if (!applyRotationX || !applyRotationY)
            {
                Vector3 euler = rotation.eulerAngles;
                if (!applyRotationX)
                {
                    euler.x = inputRotation.eulerAngles.x;
                }
                if (!applyRotationY)
                {
                    euler.y = inputRotation.eulerAngles.y;
                }
                if (!applyRotationZ)
                {
                    euler.z = inputRotation.eulerAngles.z;
                }
                inputRotation.eulerAngles = euler;
            }
            else
            {
                inputRotation = rotation;
            }
            return(inputRotation);
        }
예제 #2
0
        private Quaternion GetRotation(Quaternion inputRotation)
        {
            Vector3 a = _splineResult.direction;

            if (direction == Spline.Direction.Backward && !targetUser.averageResultVectors)
            {
                double num  = targetUser.ClipPercent(_splineResult.percent);
                int    num2 = targetUser.GetClippedSampleIndex(num);
                for (int num3 = DMath.CeilInt(num * (double)(targetUser.clippedSamples.Length - 1)); num3 >= 0; num3--)
                {
                    num2 = num3;
                    if (targetUser.ClipPercent(targetUser.clippedSamples[num3].percent) < num)
                    {
                        break;
                    }
                }
                int          num4         = num2;
                SplineResult splineResult = targetUser.clippedSamples[num4];
                num4--;
                if (num4 < 0)
                {
                    num4 = ((targetUser.span == 1.0 && targetUser.rootUser.computer.isClosed) ? Mathf.Max(targetUser.clippedSamples.Length - 2, 0) : 0);
                }
                SplineResult splineResult2 = targetUser.clippedSamples[num4];
                a = Vector3.Slerp(splineResult.direction, splineResult2.direction, (float)DMath.InverseLerp(targetUser.ClipPercent(targetUser.clippedSamples[num2 + 1].percent), targetUser.ClipPercent(targetUser.clippedSamples[num2].percent), targetUser.ClipPercent(_splineResult.percent)));
            }
            rotation = Quaternion.LookRotation(a * ((direction != Spline.Direction.Forward) ? (-1f) : 1f), _splineResult.normal);
            if (_rotationOffset != Vector3.zero)
            {
                rotation *= Quaternion.Euler(_rotationOffset);
            }
            if (customRotation != null)
            {
                rotation = customRotation.Evaluate(rotation, _splineResult.percent);
            }
            if (!applyRotationX || !applyRotationY)
            {
                Vector3 eulerAngles = rotation.eulerAngles;
                if (!applyRotationX)
                {
                    Vector3 eulerAngles2 = inputRotation.eulerAngles;
                    eulerAngles.x = eulerAngles2.x;
                }
                if (!applyRotationY)
                {
                    Vector3 eulerAngles3 = inputRotation.eulerAngles;
                    eulerAngles.y = eulerAngles3.y;
                }
                if (!applyRotationZ)
                {
                    Vector3 eulerAngles4 = inputRotation.eulerAngles;
                    eulerAngles.z = eulerAngles4.z;
                }
                inputRotation.eulerAngles = eulerAngles;
            }
            else
            {
                inputRotation = rotation;
            }
            return(inputRotation);
        }