Exemplo n.º 1
0
 public void RestartAnim()
 {
     PreviousFrame         = CurrentAnimation.RigFrames[0];
     NextFrame             = 0;
     m_frameTime           = 0;
     CurrentAnimation.Over = false;
 }
Exemplo n.º 2
0
 public RigFrame(RigFrame original)
 {
     BoneFrames = new Dictionary <string, float>();
     foreach (KeyValuePair <string, float> bone in original.BoneFrames)
     {
         BoneFrames.Add(bone.Key, bone.Value);
     }
     Position  = original.Position;
     FrameTime = original.FrameTime;
 }
Exemplo n.º 3
0
 public CharacterRig(Entity owner, string id, List <string> tags, Bone root, Dictionary <string, RigAnimation> animations) : base(owner, id, tags, true, false)
 {
     CurrentAnimation = new RigAnimation();
     Animations       = new Dictionary <string, RigAnimation>();
     Bones            = new List <Bone>();
     Scale            = new Vector2(1.0f);
     Root             = root;
     Animations       = animations;
     CurrentAnimation = Animations.First().Value;
     PreviousFrame    = CurrentAnimation.RigFrames[0];
 }
Exemplo n.º 4
0
 public CharacterRig(Entity owner, CharacterRig original) : base(owner, original.Id, original.Tags, original.Active)
 {
     Animations = new Dictionary <string, RigAnimation>();
     foreach (KeyValuePair <string, RigAnimation> anim in original.Animations)
     {
         Animations.Add(anim.Key, anim.Value.Copy());
     }
     CurrentAnimation = original.CurrentAnimation.Copy();
     Bones            = new List <Bone>();
     Tags             = original.Tags;
     Scale            = original.Scale;
     Rotation         = original.Rotation;
     Root             = original.Root.Copy();
     PreviousFrame    = CurrentAnimation.RigFrames[0].Copy();
     OverridePosition = new Vector2(0);
     MountId          = original.MountId;
 }
Exemplo n.º 5
0
 public void SwitchToAnim(string id, bool smooth = true)
 {
     if (smooth)
     {
         PreviousFrame    = new RigFrame(Bones, Position, 0);
         CurrentAnimation = Animations[id];
         NextFrame        = 0;
         m_frameTime      = 0;
     }
     else
     {
         CurrentAnimation = Animations[id];
         PreviousFrame    = CurrentAnimation.RigFrames[0];
         NextFrame        = 1;
         m_frameTime      = 0;
     }
     CurrentAnimation.Over = false;
 }
Exemplo n.º 6
0
        public override void Update(double deltaTime)
        {
            float lerpValue;

            if (MountId != null)
            {
                var component = Owner.GetComponentWithId(MountId);
                OverridePosition = component.Position;
            }

            if (CurrentAnimation.RigFrames.Count > 1 && !CurrentAnimation.Over)
            {
                m_frameTime += deltaTime;
            }

            if (m_frameTime > CurrentAnimation.RigFrames[NextFrame].FrameTime)
            {
                m_frameTime   = m_frameTime % CurrentAnimation.RigFrames[NextFrame].FrameTime;
                PreviousFrame = new RigFrame(Bones, Position - OverridePosition, m_frameTime);
                NextFrame    += 1;
                if (NextFrame > CurrentAnimation.RigFrames.Count - 1)
                {
                    if (CurrentAnimation.Loop)
                    {
                        NextFrame = NextFrame % (CurrentAnimation.RigFrames.Count);
                    }
                    else
                    {
                        NextFrame             = NextFrame % (CurrentAnimation.RigFrames.Count);
                        PreviousFrame         = new RigFrame(Bones, Position - OverridePosition, m_frameTime);
                        CurrentAnimation.Over = true;
                    }

                    if (!m_loopOverride)
                    {
                        NextOverrideRotation = 0;
                    }
                }

                m_previousOverrideRotation = OverrideRotation;
                OverrideRotation           = NextOverrideRotation;
            }

            lerpValue = (float)(m_frameTime / CurrentAnimation.RigFrames[NextFrame].FrameTime);

            Position = (PreviousFrame.Position * (1 - lerpValue) + CurrentAnimation.RigFrames[NextFrame].Position * (lerpValue)) + OverridePosition;

            foreach (Bone b in Bones)
            {
                if (b.Parent == null)
                {
                    float prevFrameRot = PreviousFrame.BoneFrames[b.Id] + m_previousOverrideRotation;
                    float nextFrameRot = CurrentAnimation.RigFrames[NextFrame].BoneFrames[b.Id] + OverrideRotation;
                    if (MotionFlip)
                    {
                        b.Rotation = (prevFrameRot * (1 - lerpValue) - nextFrameRot * (lerpValue));
                    }
                    else
                    {
                        b.Rotation = (prevFrameRot * (1 - lerpValue) + nextFrameRot * (lerpValue));
                    }
                }
                else
                {
                    b.Rotation = (PreviousFrame.BoneFrames[b.Id] * (1 - lerpValue) + CurrentAnimation.RigFrames[NextFrame].BoneFrames[b.Id] * (lerpValue));
                }
            }

            Root.Update();
        }