Пример #1
0
        public void Update(float elapsed, Transformation[] setTrans, bool b)
        {
            //for (int i = 0; i < 3; i++)
            //{
            //    if(b)
            //    UpdateFrame2(i, setTrans);
            //    else
            //        UpdateFrame(i, setTrans);
            //}

            //currentFrame++;

            //int te = (frameIndex + 1) % 3;
            //if (currentFrame > Animation.BoneAnimations[0].Keyframes[te].FrameNumber)
            //    frameIndex = (frameIndex + 1) % 3;

            //if (currentFrame > Animation.BoneAnimations[0].FrameLength)
            //{
            //    currentFrame = 0;
            //}
            int length = Animation.BoneAnimations.Count;
            for (int i = 0; i < length; i++)
            {
                AnimationUpdates[i].Update(elapsed, ref setTrans[i]);

                //if (AnimationUpdates[i].BoneAnimationGetter.Keyframes.Count>=frameIndex)
                //{
                //    frameIndex = AnimationUpdates[i].FrameIndex;
                //}
                frameIndex = AnimationUpdates[i].FrameIndex;
            }
        }
Пример #2
0
        public static Transformation Compose(Transformation trans1, Transformation trans2)
        {
            Transformation result;
            Vector2 tempPos = trans1.RotatePosition(trans2.Position);

            result.Position = tempPos;
            result.Rotation = trans1.Rotation + trans2.Rotation;
            result.Scale = trans1.Scale * trans2.Scale;
            return result;
        }
Пример #3
0
        public static Transformation Lerp(Transformation trans1, Transformation trans2, float amount)
        {
            Transformation result;

            //result.Position = Vector2.Lerp(trans1.Position, trans2.Position, 0.5f);
            //result.Scale = Vector2.Lerp(trans1.Scale, trans2.Scale, 0.5f);
            //result.Rotation = MathHelper.Lerp(trans1.Rotation, trans2.Rotation, 0.5f);

            result.Position = Vector2.Lerp(trans1.Position, trans2.Position, amount);
            result.Scale = Vector2.Lerp(trans1.Scale, trans2.Scale, amount);
            result.Rotation = MathHelper.Lerp(trans1.Rotation, trans2.Rotation, amount);

            return result;
        }
Пример #4
0
        public void Update(float elapsed, ref Transformation setTrans)
        {
            setTrans=UpdateFrame(0, setTrans);

            currentFrame++;

            int temp = (frameIndex + 1) % BoneAnimation.Keyframes.Count;

            if (currentFrame > BoneAnimation.Keyframes[temp].FrameNumber)
                frameIndex = (frameIndex + 1) % BoneAnimation.Keyframes.Count;

            if (currentFrame > BoneAnimation.FrameLength)
            {
                currentFrame = 0;
            }
        }
Пример #5
0
        public void SetLocalTransform(Transformation[] t)
        {
            if (RelativeTransforms == null)
            {
                RelativeTransforms = new List<Transformation>();
            }
            //Array.Copy(t, RelativeTransforms, t.Length);

            for (int i = 0; i < t.Length; i++)
            {
                if (RelativeTransforms.Count<t.Length)
                    RelativeTransforms.Add(t[i]);
                else
                    RelativeTransforms[i] = t[i];
            }
        }
Пример #6
0
 public static Transformation Copy(Transformation trans)
 {
     Transformation result = trans;
     return result;
 }
Пример #7
0
 static Transformation()
 {
     Default = new Transformation();
     Default.Scale = Vector2.One;
 }
Пример #8
0
        public Transformation UpdateFrame(int index, Transformation setTrans)
        {
            Transformation temp;

            int te = (frameIndex + 1) % BoneAnimation.Keyframes.Count;
            float am;

            if (currentFrame == 0)
            {

                if (BoneAnimation.Keyframes.Count > 1)
                {
                    float t = (BoneAnimation.Keyframes[te].FrameNumber *
                    BoneAnimation.FPS) -
                        (BoneAnimation.Keyframes[frameIndex].FrameNumber *
                        BoneAnimation.FPS);

                    am = t / 1000;

                    temp = Transformation.Lerp(setTrans,
                        BoneAnimation.Keyframes[te].trans, am);
                    setTrans = temp;

                    return setTrans;
                }
                else
                {
                    setTrans =
                    BoneAnimation.Keyframes[frameIndex].trans;

                    return setTrans;
                }
            }
            else
            {

                if (te > frameIndex)
                {
                    float t = (BoneAnimation.Keyframes[te].FrameNumber *
                    BoneAnimation.FPS) -
                        (BoneAnimation.Keyframes[frameIndex].FrameNumber *
                        BoneAnimation.FPS);

                    am = t / 1000;

                    temp = Transformation.Lerp(setTrans,
                    BoneAnimation.Keyframes[te].trans, am);
                    setTrans = temp;

                    return setTrans;
                }
                else
                {
                    float t = (BoneAnimation.Keyframes[frameIndex].FrameNumber *
                        BoneAnimation.FPS) - (BoneAnimation.Keyframes[te].FrameNumber *
                    BoneAnimation.FPS);

                    am = t / 1000;

                    temp = Transformation.Lerp(BoneAnimation.Keyframes[te].trans,
                        setTrans,
                        am);
                    setTrans = temp;

                    return setTrans;
                }
            }
        }
Пример #9
0
        public void UpdateFrame(int index, Transformation[] setTrans)
        {
            //Animation.BoneAnimations[index].Keyframes[index];

            //if (Animation.BoneAnimations[index].Keyframes.Count < 1)
            //{
            //    setTrans[index] = Animation.
            //        BoneAnimations[index].Keyframes[Animation.BoneAnimations[index].Keyframes.Count - 1].trans;
            //}
            //else if (Animation.BoneAnimations[index].Keyframes.Count <= frameIndex)
            //{
            //    setTrans[index] = Animation.
            //        BoneAnimations[index].Keyframes[frameIndex].trans;
            //}

            //if (setTrans[index].Rotation == null)
            if (currentFrame == 0)
                setTrans[index] = Animation.
                    BoneAnimations[index].Keyframes[frameIndex].trans;
            else
            {
                Transformation temp;
                int te = (frameIndex + 1) % 3;

                float am;

                if (te > frameIndex)
                {
                    //am=(Animation.BoneAnimations[index].Keyframes[te]-
                    //    Animation.BoneAnimations[index].Keyframes[frameIndex])
                    float t = (Animation.BoneAnimations[index].Keyframes[te].FrameNumber *
                    Animation.BoneAnimations[index].FPS) -
                        (Animation.BoneAnimations[index].Keyframes[frameIndex].FrameNumber *
                        Animation.BoneAnimations[index].FPS);

                    am = t / 1000;
                }
                else
                {
                    float t = (Animation.BoneAnimations[index].Keyframes[frameIndex].FrameNumber *
                        Animation.BoneAnimations[index].FPS) - (Animation.BoneAnimations[index].Keyframes[te].FrameNumber *
                    Animation.BoneAnimations[index].FPS);

                    am = t / 1000;
                }
                temp = Transformation.Lerp(setTrans[index],
                    Animation.BoneAnimations[index].Keyframes[te].trans, am);
                setTrans[index] = temp;
            }
        }