Esempio n. 1
0
 /// <summary>
 /// Performs a 2D linear interpolation between four values values, FracX, FracY ranges from 0-1
 /// </summary>
 public static FQuat BiLerp(FQuat p00, FQuat p10, FQuat p01, FQuat p11, float fracX, float fracY)
 {
     return(Lerp(
                FQuat.Slerp_NotNormalized(p00, p10, fracX),
                FQuat.Slerp_NotNormalized(p01, p11, fracX),
                fracY));
 }
Esempio n. 2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="inVal">input value that corresponds to this key</param>
 /// <param name="outVal">Output value of templated type</param>
 public FInterpCurvePointQuat(float inVal, FQuat outVal)
 {
     InVal         = inVal;
     OutVal        = outVal;
     ArriveTangent = default(FQuat);
     LeaveTangent  = default(FQuat);
     InterpMode    = EInterpCurveMode.Linear;
 }
Esempio n. 3
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="inVal">input value that corresponds to this key</param>
 /// <param name="outVal">Output value of templated type</param>
 /// <param name="arriveTangent">Tangent of curve arriving at this point. </param>
 /// <param name="leaveTangent">Tangent of curve leaving from this point.</param>
 /// <param name="interpMode">interpolation mode to use</param>
 public FInterpCurvePointQuat(float inVal, FQuat outVal,
                              FQuat arriveTangent, FQuat leaveTangent, EInterpCurveMode interpMode)
 {
     InVal         = inVal;
     OutVal        = outVal;
     ArriveTangent = arriveTangent;
     LeaveTangent  = leaveTangent;
     InterpMode    = interpMode;
 }
Esempio n. 4
0
        /// <summary>
        /// Interpolate quaternion from Current to Target. Scaled by angle to Target, so it has a strong start speed and ease out.
        /// </summary>
        public static FQuat QInterpTo(FQuat current, FQuat target, float deltaTime, float interpSpeed)
        {
            // If no interp speed, jump to target value
            if (interpSpeed <= 0.0f)
            {
                return(target);
            }

            // If the values are nearly equal, just return Target and assume we have reached our destination.
            if (current.Equals(target))
            {
                return(target);
            }

            return(FQuat.Slerp(current, target, FMath.Clamp(interpSpeed * deltaTime, 0.0f, 1.0f)));
        }
Esempio n. 5
0
        /// <summary>
        /// Interpolate quaternion from Current to Target with constant step (in radians)
        /// </summary>
        public static FQuat QInterpConstantTo(FQuat current, FQuat target, float deltaTime, float interpSpeed)
        {
            // If no interp speed, jump to target value
            if (interpSpeed <= 0.0f)
            {
                return(target);
            }

            // If the values are nearly equal, just return Target and assume we have reached our destination.
            if (current.Equals(target))
            {
                return(target);
            }

            float deltaInterpSpeed = FMath.Clamp(deltaTime * interpSpeed, 0.0f, 1.0f);
            float angularDistance  = FMath.Max(SmallNumber, target.AngularDistance(current));
            float alpha            = FMath.Clamp(deltaInterpSpeed / angularDistance, 0.0f, 1.0f);

            return(FQuat.Slerp(current, target, alpha));
        }
Esempio n. 6
0
        // Special-case interpolation

        /// <summary>
        /// Interpolate a normal vector Current to Target, by interpolating the angle between those vectors with constant step.
        /// </summary>
        public static FVector VInterpNormalRotationTo(FVector current, FVector target, float deltaTime, float rotationSpeedDegrees)
        {
            // Find delta rotation between both normals.
            FQuat deltaQuat = FQuat.FindBetween(current, target);

            // Decompose into an axis and angle for rotation
            FVector deltaAxis;
            float   deltaAngle;

            deltaQuat.ToAxisAndAngle(out deltaAxis, out deltaAngle);

            // Find rotation step for this frame
            float rotationStepRadians = rotationSpeedDegrees * (PI / 180) * deltaTime;

            if (FMath.Abs(deltaAngle) > rotationStepRadians)
            {
                deltaAngle = FMath.Clamp(deltaAngle, -rotationStepRadians, rotationStepRadians);
                deltaQuat  = new FQuat(deltaAxis, deltaAngle);
                return(deltaQuat.RotateVector(current));
            }
            return(target);
        }
Esempio n. 7
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="quat">Quaternion used to specify rotation.</param>
 public FRotator(FQuat quat)
 {
     this = quat.Rotator();
     DiagnosticCheckNaN();
 }
Esempio n. 8
0
 /// <summary>
 /// This actually returns the control point not a tangent. This is expected by the CubicInterp function for Quaternions
 /// </summary>
 public static void AutoCalcTangent(FQuat prevP, FQuat p, FQuat nextP, float tension, out FQuat outTan)
 {
     FQuat.CalcTangents(prevP, p, nextP, tension, out outTan);
 }
Esempio n. 9
0
 /// <summary>
 /// Performs a cubic interpolation - In the case of quaternions, we use a bezier like approach.
 /// </summary>
 /// <param name="p0">end points</param>
 /// <param name="t0">tangent directions at end points</param>
 /// <param name="p1">end points</param>
 /// <param name="t1">tangent directions at end points</param>
 /// <param name="alpha">distance along spline</param>
 /// <returns>Interpolated value</returns>
 public static FQuat CubicInterp(FQuat p0, FQuat t0, FQuat p1, FQuat t1, float alpha)
 {
     return(FQuat.Squad(p0, t0, p1, t1, alpha));
 }
Esempio n. 10
0
        // Quat-specific interpolation

        /// <summary>
        /// Performs a linear interpolation between two values, Alpha ranges from 0-1
        /// </summary>
        public static FQuat Lerp(FQuat a, FQuat b, float alpha)
        {
            return(FQuat.Slerp(a, b, alpha));
        }