Exemplo n.º 1
0
        public static void Multiply(ref SphericalDirectionF d, ref QuaternionF q, out SphericalDirectionF result)
        {
            Vector3F vector;

            d.GetVector(out vector);
            Vector3F vector2;

            QuaternionF.Multiply(ref vector, ref q, out vector2);
            SphericalDirectionF.FromVector(ref vector2, out result);
        }
Exemplo n.º 2
0
        public static void Slerp(ref QuaternionF from, ref QuaternionF to, float t, out QuaternionF result)
        {
            QuaternionF temp;
            float       omega, cosom, sinom, scale0, scale1;

            if (t <= 0.0f)
            {
                result = from;
            }
            if (t >= 1.0f)
            {
                result = to;
            }
            if (from == to)
            {
                result = to;
            }

            cosom = from.X * to.X + from.Y * to.Y + from.Z * to.Z + from.W * to.W;
            if (cosom < 0.0f)
            {
                temp  = -to;
                cosom = -cosom;
            }
            else
            {
                temp = to;
            }

            if ((1.0f - cosom) > MathEx.Epsilon)
            {
                scale0 = 1.0f - cosom * cosom;
                sinom  = MathEx.InvSqrt(scale0);
                omega  = MathEx.Atan2(scale0 * sinom, cosom);
                scale0 = MathEx.Sin((1.0f - t) * omega) * sinom;
                scale1 = MathEx.Sin(t * omega) * sinom;
            }
            else
            {
                scale0 = 1.0f - t;
                scale1 = t;
            }

            QuaternionF s1, s2;

            QuaternionF.Multiply(scale0, ref from, out s1);
            QuaternionF.Multiply(scale1, ref temp, out s2);
            QuaternionF.Add(ref s1, ref s2, out result);
            //return ( scale0 * from ) + ( scale1 * temp );
        }