Exemplo n.º 1
0
        //  Given a matrix, decompose that matrix into a Keyframe.
        //  This works for matrices that don't contain shear or off-axis scale.
        public static Keyframe CreateFromMatrix(ref Matrix mat)
        {
            Keyframe k = new Keyframe();

            return(CreateFromMatrix(ref mat, k));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Given a base keyframe, and a "delta" keyframe, construct a keyframe that
        /// represents the first transformation followed by a weighted amount of the
        /// second keyframe.
        /// </summary>
        /// <param name="first">The base keyframe. Cannot be the same object as "result."</param>
        /// <param name="second">The delta keyframe. Can be the same object as "result."</param>
        /// <param name="weight">How much of the delta keyframe to apply (typically 0 .. 1)</param>
        /// <param name="result">The composed keyframe data will be stored here.</param>
        /// <returns>result (for convenience)</returns>
        public static Keyframe Compose(Keyframe first, Keyframe second, float weight, Keyframe result)
        {
#if DEBUG
            //  "first" and "result" can't be the same objects, although
            //  "second" and "result" can be.
            System.Diagnostics.Debug.Assert(first != result);
            if (first == null)
            {
                throw new ArgumentNullException("left");
            }
            if (second == null)
            {
                throw new ArgumentNullException("right");
            }
            if (result == null)
            {
                throw new ArgumentNullException("result");
            }
#endif
#if !MATRIXFRAMES
            Interpolate(Identity, second, weight, result);
            Vector3 pos;
            Vector3.Transform(ref result.pos_, ref first.ori_, out pos);
            result.pos_   = first.pos_ + pos;
            result.scale_ = first.scale_ * second.scale_;
            //  Yes, XNA does quaternions in a different order from matrices. Blech.
            result.ori_ = second.ori_ * first.ori_;
#else
            result.transform_ = first.transform_ * (Matrix.Identity * (1 - weight) + second.transform_ * weight);
#endif
            return(result);
        }