Exemplo n.º 1
0
        /// <summary>
        /// Retrieves all transforms related to this bone's model
        /// Some Transformations are not used (because they are insignificant) for this bone's parents (scale / orientation correction)
        /// </summary>
        /// <param name="isLeaf"></param>
        /// <returns></returns>
        public Matrix GetTransformation(bool isLeaf)
        {
            Matrix transform = Matrix.Identity;

            if (isLeaf)                                                   // if this is the leaf model,
            {
                transform *= Matrix.CreateScale(ModelScaleCorrection);    // include the scale correction
            }
            transform *= Matrix.CreateTranslation(ModelOriginCorrection); // shift the Model away from its native origin here

            Quaternion qRot = Orient;                                     // represents orientation of the model based on animation / user input

            if (isLeaf)                                                   // if this is the leaf model,
            {
                qRot *= OrientCorrection;                                 // represent shifting the model away from native orientation
            }
            // the rot variable represents all manipulations in a single vector for Yaw, Pitch, Roll
            // Merging Yaw/Pitch/Roll vectors, then getting a Quaternion, and then a Matrix works
            // Multiplying two Quaternions and then getting a Matrix would work
            // Multiplying to Matrices does not work because the first changes the affect of the second.
            Matrix mRot = Matrix.CreateFromQuaternion(qRot);       //

            transform *= mRot;                                     // Rotate the model
            //X:-0.35 Y:0.1 Z:-0.26
            transform *= Matrix.CreateTranslation(RelativeOrigin); // Move the model

            if (ParentBone != null)
            {
                transform *= ParentBone.GetTransformation(false); // Apply parent's transforms
            }
            return(transform);
        }