Example #1
0
        /// <summary>
        /// Get the spherically interpolated quaternion at position t between
        /// a and b (UNVERIFIED)
        /// </summary>
        /// <param name="a"></param>
        /// <param name="b"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        static public Quaternion Slerp(Quaternion a, Quaternion b, float t)
        {
            // TODO: verify the validity of this function
            Debug.WriteLine("Quaternion.Slerp() - warning, this function has not be checked for validity.");

            // Calculate the cosine of the angle between the two
            float  fScale0, fScale1;
            double dCos = Quaternion.DotProduct(a, b);

            // If the angle is significant, use the spherical interpolation
            if ((1.0 - Math.Abs(dCos)) > 1e-6f)
            {
                double dTemp = Math.Acos(Math.Abs(dCos));
                double dSin  = Math.Sin(dTemp);
                fScale0 = (float)(Math.Sin((1.0 - t) * dTemp) / dSin);
                fScale1 = (float)(Math.Sin(t * dTemp) / dSin);
            }
            // Else use the cheaper linear interpolation
            else
            {
                fScale0 = 1.0f - t;
                fScale1 = t;
            }
            if (dCos < 0.0)
            {
                fScale1 = -fScale1;
            }

            // Return the interpolated result
            return((a * fScale0) + (b * fScale1));
        }