예제 #1
0
        // The smaller of the two possible angles between the two vectors is returned, therefore the result will never be greater than 180 degrees or smaller than -180 degrees.
        // If you imagine the from and to vectors as lines on a piece of paper, both originating from the same point, then the /axis/ vector would point up out of the paper.
        // The measured angle between the two vectors would be positive in a clockwise direction and negative in an anti-clockwise direction.
        public static FP SignedAngle(FPVector from, FPVector to, FPVector axis)
        {
            FPVector fromNorm = from.normalized, toNorm = to.normalized;
            FP       unsignedAngle = FPMath.Acos(FPMath.Clamp(Dot(fromNorm, toNorm), -FP.ONE, FP.ONE)) * FPMath.Rad2Deg;
            FP       sign          = FPMath.Sign(Dot(axis, Cross(fromNorm, toNorm)));

            return(unsignedAngle * sign);
        }
        public static FPVector2 Lerp(FPVector2 value1, FPVector2 value2, FP amount)
        {
            amount = FPMath.Clamp(amount, 0, 1);

            return(new FPVector2(
                       FPMath.Lerp(value1.x, value2.x, amount),
                       FPMath.Lerp(value1.y, value2.y, amount)));
        }
예제 #3
0
        public static FPQuaternion Slerp(FPQuaternion from, FPQuaternion to, FP t)
        {
            t = FPMath.Clamp(t, 0, 1);

            FP dot = Dot(from, to);

            if (dot < 0.0f)
            {
                to  = Multiply(to, -1);
                dot = -dot;
            }

            FP halfTheta = FP.Acos(dot);

            return(Multiply(Multiply(from, FP.Sin((1 - t) * halfTheta)) + Multiply(to, FP.Sin(t * halfTheta)), 1 / FP.Sin(halfTheta)));
        }
 public static void Clamp(ref FPVector2 value1, ref FPVector2 min, ref FPVector2 max, out FPVector2 result)
 {
     result = new FPVector2(
         FPMath.Clamp(value1.x, min.x, max.x),
         FPMath.Clamp(value1.y, min.y, max.y));
 }
 public static FPVector2 Clamp(FPVector2 value1, FPVector2 min, FPVector2 max)
 {
     return(new FPVector2(
                FPMath.Clamp(value1.x, min.x, max.x),
                FPMath.Clamp(value1.y, min.y, max.y)));
 }
예제 #6
0
 // Returns the angle in degrees between /from/ and /to/. This is always the smallest
 public static FP Angle(FPVector from, FPVector to)
 {
     return(FPMath.Acos(FPMath.Clamp(Dot(from.normalized, to.normalized), -FP.ONE, FP.ONE)) * FPMath.Rad2Deg);
 }
예제 #7
0
        public static FPQuaternion Lerp(FPQuaternion a, FPQuaternion b, FP t)
        {
            t = FPMath.Clamp(t, FP.Zero, FP.One);

            return(LerpUnclamped(a, b, t));
        }