예제 #1
0
    public static FP Angle(TSQuaternion a, TSQuaternion b)
    {
        TSQuaternion aInv = TSQuaternion.Inverse(a);
        TSQuaternion f    = b * aInv;

        FP angle = FP.Acos(f.w) * 2 * FP.Rad2Deg;

        if (angle > 180)
        {
            angle = 360 - angle;
        }

        return(angle);
    }
예제 #2
0
    public static TSQuaternion Slerp(TSQuaternion from, TSQuaternion to, FP t)
    {
        t = TSMath.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)));
    }
예제 #3
0
    public static TSQuaternion RotateTowards(TSQuaternion from, TSQuaternion to, FP maxDegreesDelta)
    {
        FP dot = Dot(from, to);

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

        FP halfTheta = FP.Acos(dot);
        FP theta     = halfTheta * 2;

        maxDegreesDelta *= FP.Deg2Rad;

        if (maxDegreesDelta >= theta)
        {
            return(to);
        }

        maxDegreesDelta /= theta;

        return(Multiply(Multiply(from, FP.Sin((1 - maxDegreesDelta) * halfTheta)) + Multiply(to, FP.Sin(maxDegreesDelta * halfTheta)), 1 / FP.Sin(halfTheta)));
    }
예제 #4
0
 /// <summary>
 /// Returns the arc cosine of value.
 /// </summary>
 public static FP Acos(FP value)
 {
     return(FP.Acos(value));
 }
예제 #5
0
 public static FP Angle(TSVector2 a, TSVector2 b)
 {
     return(FP.Acos(a.normalized * b.normalized) * FP.Rad2Deg);
 }