Esempio n. 1
0
        /// <summary>
        /// Gets the current transform for the given BonePose object in the animation.
        /// This is only called when a bone pose is affected by the current animation.
        /// </summary>
        /// <param name="pose">The BonePose object querying for the current transform in
        /// the animation.</param>
        /// <returns>The current transform of the bone.</returns>
        public virtual Matrix GetCurrentBoneTransform(BonePose pose)
        {
            AnimationChannelCollection channels = animation.AnimationChannels;
            BoneKeyframeCollection     channel  = channels[pose.Name];
            int boneIndex = channel.GetIndexByTime(elapsedTime);

            return(channel[boneIndex].Transform);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns the current transform for a bone.
        /// </summary>
        /// <param name="pose">The bone.</param>
        /// <returns>The bone's current transform.</returns>
        public override Matrix GetCurrentBoneTransform(BonePose pose)
        {
            BoneKeyframeCollection channel = base.AnimationSource.AnimationChannels[
                pose.Name];
            int curIndex = channel.GetIndexByTime(base.ElapsedTime);

            if (interpMethod == InterpolationMethod.None)
            {
                return(channel[curIndex].Transform);
            }
            int nextIndex = curIndex + 1;

            if (nextIndex >= channel.Count)
            {
                return(channel[curIndex].Transform);
            }
            // Numerator of the interpolation factor
            double interpNumerator = (double)(ElapsedTime - channel[curIndex].Time);
            // Denominator of the interpolation factor
            double interpDenom = (double)(channel[nextIndex].Time
                                          - channel[curIndex].Time);
            // The interpolation factor, or amount to interpolate between the current
            // and next frame
            double interpAmount = interpNumerator / interpDenom;

            curTransform  = channel[curIndex].Transform;
            nextTransform = channel[nextIndex].Transform;
            if (interpMethod == InterpolationMethod.Linear)
            {
                Matrix.Lerp(ref curTransform, ref nextTransform,
                            (float)interpAmount, out transform);
            }
            else
            {
                Util.SlerpMatrix(ref curTransform, ref nextTransform,
                                 (float)interpAmount, out transform);
            }
            return(transform);
        }