Ejemplo n.º 1
0
        public static Fixed64 Angle(Fixed64Quaternion a, Fixed64Quaternion b)
        {
            Fixed64Quaternion aInv = Inverse(a);
            Fixed64Quaternion f    = b * aInv;

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

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

            return(angle);
        }
Ejemplo n.º 2
0
        public static Fixed64Quaternion Slerp(Fixed64Quaternion from, Fixed64Quaternion to, Fixed64 t)
        {
            t = FixedMath.Clamp(t, 0, 1);

            Fixed64 dot = Dot(from, to);

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

            Fixed64 halfTheta = Fixed64.Acos(dot);

            return(Multiply(Multiply(from, Fixed64.Sin((1 - t) * halfTheta)) + Multiply(to, Fixed64.Sin(t * halfTheta)), 1 / Fixed64.Sin(halfTheta)));
        }
Ejemplo n.º 3
0
        public static Fixed64Quaternion RotateTowards(Fixed64Quaternion from, Fixed64Quaternion to, Fixed64 maxDegreesDelta)
        {
            Fixed64 dot = Dot(from, to);

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

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

            maxDegreesDelta *= Fixed64.Deg2Rad;

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

            maxDegreesDelta /= theta;

            return(Multiply(Multiply(from, Fixed64.Sin((1 - maxDegreesDelta) * halfTheta)) + Multiply(to, Fixed64.Sin(maxDegreesDelta * halfTheta)), 1 / Fixed64.Sin(halfTheta)));
        }
Ejemplo n.º 4
0
 public static Fixed64 Angle(Fixed64Vector3 a, Fixed64Vector3 b)
 {
     return(Fixed64.Acos(a.Normalized * b.Normalized) * Fixed64.Rad2Deg);
 }