Пример #1
0
        /// <summary>
        /// Calculates the current transform, based on the animations, for the bone
        /// represented by the BonePose object.
        /// </summary>
        public Matrix GetCurrentTransform()
        {
            // If the bone is not currently affected by an animation
            if (currentAnimation == null || !doesAnimContainChannel)
            {
                // If the bone is affected by a blend animation,
                // blend the defaultTransform with the blend animation
                if (currentBlendAnimation != null && doesBlendContainChannel)
                {
                    blendMatrix = currentBlendAnimation.GetCurrentBoneTransform(this);
                    Util.SlerpMatrix(
                        ref defaultMatrix,
                        ref blendMatrix,
                        BlendFactor,
                        out returnMatrix);
                }
                // else return the default transform
                else
                {
                    return(defaultMatrix);
                }
            }
            // The bone is affected by an animation
            else
            {
                // Find the current transform in the animation for the bone
                currentMatrixBuffer = currentAnimation.GetCurrentBoneTransform(this);
                // If the bone is affected by a blend animation, blend the
                // current animation transform with the current blend animation
                // transform
                if (currentBlendAnimation != null && doesBlendContainChannel)
                {
                    blendMatrix = currentBlendAnimation.GetCurrentBoneTransform(this);
                    Util.SlerpMatrix(
                        ref currentMatrixBuffer,
                        ref blendMatrix,
                        BlendFactor,
                        out returnMatrix);
                }
                // Else just return the current animation transform
                else
                {
                    return(currentMatrixBuffer);
                }
            }

            return(returnMatrix);
        }
Пример #2
0
        }   // end of c'tor

        /// <summary>
        /// Gets the current bone transform.
        /// </summary>
        /// <param name="pose">The pose.</param>
        /// <returns>The current transform of the bone.</returns>
        public Matrix GetCurrentBoneTransform(BonePose pose)
        {
            if (animationControllers.Count == 0)
            {
                return(pose.DefaultTransform);
            }

            Matrix transform = new Matrix();
            Matrix m;

            for (int i = 0; i < animationControllers.Count; i++)
            {
                IAnimationController ac = animationControllers[i];

                if (ac.Weight > 0.0f)
                {
                    if (ac.ContainsAnimationTrack(pose))
                    {
                        m          = ac.GetCurrentBoneTransform(pose);
                        transform += ac.Weight == 1.0f ? m : ac.Weight * m;
                    }
                    else
                    {
                        transform += ac.Weight == 1.0f ? pose.DefaultTransform : ac.Weight * pose.DefaultTransform;
                    }
                }
            }

            return(transform);
        }   // end of GetCurrentBoneTransform()