Ejemplo n.º 1
0
        public static TSQuaternion Slerp(TSQuaternion from, TSQuaternion to, FP t)
        {
            t = TSMath.Clamp(t, 0, 1);
            //t = 0.5f;
            //if (t == 0)
            //    return from;
            FP dot = Dot(from, to);

            if (dot < 0.0f)
            {
                to  = Multiply(to, -1);
                dot = -dot;
            }
            if (dot >= FP.NearOne)
            {
                // If the inputs are too close for comfort, linearly interpolate
                // and normalize the result.
                TSQuaternion result = Lerp(from, to, t);
                return(result);
            }
            FP halfTheta = FP.Acos(dot);

            //UnityEngine.Debug.LogWarning("halfTheta:"+ halfTheta+" dot:"+dot+ " FP.Sin(halfTheta):"+ FP.Sin(halfTheta));
            return(Multiply(Multiply(from, FP.Sin((1 - t) * halfTheta)) + Multiply(to, FP.Sin(t * halfTheta)), 1 / FP.Sin(halfTheta)));
        }
Ejemplo n.º 2
0
        public static FP Angle(TSQuaternion a, TSQuaternion b)
        {
            TSQuaternion value        = TSQuaternion.Inverse(a);
            TSQuaternion tSQuaternion = b * value;
            FP           result       = FP.Acos(tSQuaternion.w) * 2 * FP.Rad2Deg;
            bool         flag         = result > 180;

            if (flag)
            {
                result = 360 - result;
            }
            return(result);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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)));
        }
Ejemplo n.º 5
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)));
        }
Ejemplo n.º 6
0
 /// <summary>
 /// Returns the arc cosine of value.
 /// </summary>
 public static FP Acos(FP value)
 {
     return(FP.Acos(value));
 }
Ejemplo n.º 7
0
 public static FP Angle(TSVector a, TSVector b)
 {
     return(FP.Acos(a.normalized * b.normalized) * FP.Rad2Deg);
 }