예제 #1
0
        public static void GetBoneTransformationsTransition(BoneTransformation[] transforms, BoneTransitionState[] transitionState, Animation currentAnimation, Animation stopAnimation, float transitionPosition)
        {
            for (int boneIndex = 0; boneIndex < currentAnimation.Keyframes[0].UpdateOrderBones.Count; boneIndex++)
            {
                Bone currentBone = currentAnimation.Keyframes[0].UpdateOrderBones[boneIndex];
                Bone transitionBone = null;

                foreach (Bone b in stopAnimation.Keyframes[0].UpdateOrderBones)
                {
                    if (currentBone.Name == b.Name)
                    {
                        transitionBone = b;
                        break;
                    }
                }

                if (transitionBone == null)
                    continue;

                Vector2 position = Vector2.Lerp(transitionState[boneIndex].Position, transitionBone.Position, transitionPosition);
                Vector2 scale = new Vector2(1, 1);
                float rotation = MathHelper.Lerp(transitionState[boneIndex].Rotation, transitionBone.Rotation, transitionPosition);

                Matrix parentTransform = currentBone.ParentIndex == -1 ? Matrix.Identity : transforms[currentBone.ParentIndex].Transform;

                int drawIndex = currentBone.SelfIndex;

                transforms[drawIndex].Transform = Matrix.CreateScale(scale.X, scale.Y, 1) *
                    Matrix.CreateRotationZ(rotation) *
                    Matrix.CreateTranslation(position.X, position.Y, 0) *
                    parentTransform;

                Vector3 position3, scale3;
                Vector2 direction;
                Quaternion rotationQ;

                transforms[drawIndex].Transform.Decompose(out scale3, out rotationQ, out position3);
                direction = Vector2.Transform(Vector2.UnitX, rotationQ);

                transforms[drawIndex].Position = new Vector2(position3.X, position3.Y);
                transforms[drawIndex].Rotation = (float)Math.Atan2(direction.Y, direction.X);
                transforms[drawIndex].Scale = new Vector2(scale3.X, scale3.Y);
            }
        }
예제 #2
0
 public void AddAnimation(string name, Animation animation)
 {
     animations[name] = animation;
     if (BoneTransformations == null || animation.Keyframes[0].Bones.Count > BoneTransformations.Length)
     {
         BoneTransformations = new BoneTransformation[animation.Keyframes[0].Bones.Count];
         transitionStates = new BoneTransitionState[animation.Keyframes[0].Bones.Count];
     }
 }
예제 #3
0
        public static void UpdateBoneTransitions(BoneTransitionState[] transitionState, Animation currentAnimation, Animation stopAnimation, float transitionPosition)
        {
            for (int boneIndex = 0; boneIndex < currentAnimation.Keyframes[0].UpdateOrderBones.Count; boneIndex++)
            {
                Bone currentBone = currentAnimation.Keyframes[0].UpdateOrderBones[boneIndex];
                Bone transitionBone = null;

                foreach (Bone b in stopAnimation.Keyframes[0].UpdateOrderBones)
                {
                    if (currentBone.Name == b.Name)
                    {
                        transitionBone = b;
                        break;
                    }
                }

                if (transitionBone == null)
                    continue;

                transitionState[boneIndex].Position = Vector2.Lerp(transitionState[boneIndex].Position, transitionBone.Position, transitionPosition);
                transitionState[boneIndex].Rotation = MathHelper.Lerp(transitionState[boneIndex].Rotation, transitionBone.Rotation, transitionPosition);
            }
        }