Exemplo n.º 1
0
        internal MD5BoneTransforms GetBoneTransforms(int boneNumber)
        {
            MD5BoneTransforms boneTransforms = new MD5BoneTransforms();

            boneTransforms.Translation = Vector3.Lerp(animation.GetFrameSkeleton(currentFrame).Joints[boneNumber].Position, animation.GetFrameSkeleton(nextFrame).Joints[boneNumber].Position, timeInCurrentFrame / animation.SecondsPerFrame);
            boneTransforms.Rotation    = Quaternion.Slerp(animation.GetFrameSkeleton(currentFrame).Joints[boneNumber].Rotation, animation.GetFrameSkeleton(nextFrame).Joints[boneNumber].Rotation, timeInCurrentFrame / animation.SecondsPerFrame);
            return(boneTransforms);
        }
Exemplo n.º 2
0
        public MD5BoneTransforms GetFinalBoneTransforms(int boneIndex)
        {
            MD5BoneTransforms trackBT;
            int  trackFlags;
            int  totalBias              = 0;
            int  bufferedBias           = 0;
            bool boneExplicitlyAnimated = false;
            MD5BoneTransforms bt        = new MD5BoneTransforms();
            MD5BoneTransforms bufferBT  = new MD5BoneTransforms();
            int numberOfActiveTracks    = NumberOfActiveTracks;

            bt.Translation = bufferBT.Translation = Vector3.Zero;
            bt.Rotation    = bufferBT.Rotation = Quaternion.Identity;

            foreach (MD5AnimationTrack track in animationTracks)
            {
                if (track != null)
                {
                    trackBT    = track.GetBoneTransforms(boneIndex);
                    trackFlags = track.GetBoneFlags(boneIndex);

                    if (numberOfActiveTracks == 1)
                    {
                        return(trackBT);
                    }

                    bufferedBias += track.Bias;

                    bufferBT.Translation = Vector3.Lerp(bufferBT.Translation, trackBT.Translation, (float)track.Bias / (float)bufferedBias);
                    bufferBT.Rotation    = Quaternion.Slerp(bufferBT.Rotation, trackBT.Rotation, (float)track.Bias / (float)bufferedBias);

                    if (trackFlags != 0)
                    {
                        boneExplicitlyAnimated = true;
                        totalBias     += track.Bias;
                        bt.Translation = Vector3.Lerp(bt.Translation, trackBT.Translation, (float)track.Bias / (float)totalBias);
                        bt.Rotation    = Quaternion.Slerp(bt.Rotation, trackBT.Rotation, (float)track.Bias / (float)totalBias);
                    }
                }
            }

            if (!boneExplicitlyAnimated)
            {
                return(bufferBT);
            }

            return(bt);
        }