Update() public method

Advances the current animation position.
public Update ( System.TimeSpan time, bool relativeToCurrentTime, Matrix rootTransform ) : void
time System.TimeSpan
relativeToCurrentTime bool
rootTransform Matrix
return void
        SkinningData skinningData; // Skinning Data

        #endregion Fields

        #region Constructors

        /// <summary>
        /// ModelGeo with animation
        /// </summary>
        /// <param name="Go"></param>
        /// <param name="modelResource"></param>
        /// <param name="AniClip"></param>
        public ModelGeoAnim(GameObject Go, string modelResource, string AniClip)
            : base(Go, modelResource)
        {
            // Look up our custom skinning information.
            skinningData = mModel.Tag as SkinningData;

            if (skinningData == null)
                throw new InvalidOperationException
                    ("Model '" + modelResource + "' does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayer = new AnimationPlayer(skinningData);

            AnimationClip clip = skinningData.AnimationClips[AniClip];
            animationPlayer.StartClip(clip);

            //boneTransforms = new Matrix[skinningData.BindPose.Count];
            //animationPlayer.GetBoneTransforms().CopyTo(boneTransforms, 0);
            //mMatBones = animationPlayer.GetBoneTransforms();
            BoneTransformTemp = new Matrix[skinningData.BindPose.Count];

            animationPlayer.Update(new TimeSpan(0, 0, 0), true, mMatWorld);

            InitBoundingSpheres();
            UpdateBoundingBox();
        }
Beispiel #2
0
        public AnimatedModel(Model model)
        {
            this.Model = model;

            // Look up our custom skinning information.
            SkinningData skinningData = model.Tag as SkinningData;

            if (skinningData == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            AnimationPlayer = new AnimationPlayer(skinningData);

            AnimationClip clip = skinningData.AnimationClips["Take 001"];

            AnimationPlayer.StartClip(clip);
            AnimationPlayer.Update(TimeSpan.Zero, true, Matrix.Identity);
        }
        //Execute entity's action
        public void Update(GameTime gameTime)
        {
            lastAttackTime += gameTime.ElapsedGameTime.Milliseconds;
            timeSinceAstar += gameTime.ElapsedGameTime.Milliseconds;

            #region Animations
            if (animState == AnimationState.Idle)
            {
                animationPlayer = animationPlayerwalk;
                animationPlayer.ResetClip();
            }
            else if (animState == AnimationState.Walking)
            {
                animationPlayer = animationPlayerwalk;
            }
            else if(animState == AnimationState.Attacking)//animation for attacking
            {
                animationPlayer = animationPlayerattack;
            }
            else if (animState == AnimationState.Hurt)//animation when hurt
            {
                animationPlayer = animationPlayerhurt;

                ElapsedDamagedTime += gameTime.ElapsedGameTime.Milliseconds;
                if (ElapsedDamagedTime < DAMAGE_ANIM_LENGTH)
                {
                    if (animationPlayer.currentKeyframe < animationPlayer.CurrentClip.Keyframes.Count() - 1)
                    {
                        animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);
                    }
                    else
                        animationPlayer.ResetClip();
                    return;
                }
                ElapsedDamagedTime = 0;
                animState = AnimationState.Idle;
            }
            else if (animState == AnimationState.Dying)//animation for dying
            {
                animationPlayer = animationPlayerdie;
                ElapsedDeathTime += gameTime.ElapsedGameTime.Milliseconds;
                if (ElapsedDeathTime < DEATH_ANIM_LENGTH)
                {
                    if (animationPlayer.currentKeyframe < animationPlayer.CurrentClip.Keyframes.Count() - 1)
                    {
                        animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);
                    }
                    return;
                }
                else
                {
                    Dead = true;
                    return;
                }
            }
            else//if just standing
            {
                animationPlayer = animationPlayerwalk;
                animationPlayer.ResetClip();
            }
            animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);
            #endregion

            PosState = EvaluateBehaviour();

            switch (PosState)
            {
                case EntityPositionState.KineticArrive:
                    {
                        KinematicArrive();
                        animState = AnimationState.Walking;
                        Position += Velocity;
                        break;
                    }
                case EntityPositionState.KineticFlee:
                    {
                        if ((Target.Position - this.Position).Length() < FleeRadius)
                        {
                            KinematicFlee();
                            animState = AnimationState.Walking;
                            Position += Velocity;
                        }
                        break;
                    }
                case EntityPositionState.SteeringArrive:
                    {
                        //if (onPath)
                        //{
                        //    // see if we can get to second node in path
                        //    if (path.Count > 1 && astarGetter(Position, path[1].position).Equals(Vector3.Zero))
                        //    {
                        //        GroundTarget = path[1].position;
                        //        path.RemoveAt(0);
                        //    }
                        //    else if (path.Count > 0)
                        //    {
                        //        if (!astarGetter(Position, GroundTarget).Equals(Vector3.Zero))
                        //            GroundTarget = path[0].position;
                        //        else
                        //            onPath = false;
                        //    }
                        //}
                        //else if (!onPath) // try to get path
                        //{
                        //    if (timeSinceAstar > MIN_PATHFINDING_IDLE)
                        //    {
                        //        path = GetAStarPath(GroundTarget);
                        //        if (path != null)
                        //            onPath = true;
                        //        timeSinceAstar = 0;
                        //    }
                        //}
                        SteeringArrive(creep);
                        animState = AnimationState.Walking;
                        Position += Velocity;
                        break;
                    }
                case EntityPositionState.SteeringFlee:
                    {
                        if ((Target.Position - this.Position).Length() < FleeRadius)
                        {
                            SteeringFlee(creep);
                            animState = AnimationState.Walking;
                            Position += Velocity;
                            onPath = false;
                        }
                        break;
                    }
                case EntityPositionState.SteeringWander:
                    {
                        SteeringWander();
                        animState = AnimationState.Walking;
                        Position += Velocity;
                        onPath = false;
                        break;
                    }
                case EntityPositionState.Attack:
                    {
                        animState = AnimationState.Attacking;
                        if (lastAttackTime > MeleeAttack.Speed)
                        {
                            Attack(MeleeAttack);
                            lastAttackTime = 0;
                        }
                        onPath = false;
                        break;
                    }
                case EntityPositionState.RangedAttack:
                    {
                        animState = AnimationState.Attacking;
                        if (lastAttackTime > RangedAttack.Speed)
                        {
                            Attack(RangedAttack);
                            lastAttackTime = 0;
                        }
                        onPath = false;
                        break;
                    }
                default:
                    {
                        animState = AnimationState.Idle;
                        break;
                    }
            }
        }
        public void Update(GameTime gameTime)
        {
            TimeSinceLastFire += gameTime.ElapsedGameTime.Milliseconds;
            TimeSinceLastUse += gameTime.ElapsedGameTime.Milliseconds;

            if (animState == AnimationState.Idle)
            {
                animationPlayer = animationPlayerwalk;
                animationPlayer.ResetClip();
            }
            else if (animState == AnimationState.Walking)
            {
                animationPlayer = animationPlayerwalk;
            }
            else if (animState == AnimationState.Hurt)//animation when hurt
            {
                animationPlayer = animationPlayerhurt;

                ElapsedDamagedTime += gameTime.ElapsedGameTime.Milliseconds;
                if (ElapsedDamagedTime < DAMAGE_ANIM_LENGTH)
                {
                    if (animationPlayer.currentKeyframe < animationPlayer.CurrentClip.Keyframes.Count() - 1)
                    {
                        animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);
                    }
                    else
                        animationPlayer.ResetClip();
                    return;
                }
                ElapsedDamagedTime = 0;
                animState = AnimationState.Idle;
            }
            else if (animState == AnimationState.Dying)//animation for dying
            {
                animationPlayer = animationPlayerdie;
                ElapsedDeathTime += gameTime.ElapsedGameTime.Milliseconds;
                if (ElapsedDeathTime < DEATH_ANIM_LENGTH)
                {
                    if (animationPlayer.currentKeyframe < animationPlayer.CurrentClip.Keyframes.Count() - 1)
                    {
                        animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);
                    }
                    return;
                }
                else
                {
                    Dead = true;
                    return;
                }
            }
            else//if just standing
            {
                animationPlayer = animationPlayerwalk;
                animationPlayer.ResetClip();
            }
            animationPlayer.Update(gameTime.ElapsedGameTime, true, Matrix.Identity);

            //update ray positions
            ray[0] = new VertexPositionColor(Position + rayHeight, Color.GreenYellow);
            ray[1] = new VertexPositionColor(Position + rayHeight + raydist * new Vector3((float)Math.Sin(Rotation), 0, (float)Math.Cos(Rotation)) * 2f, Color.GreenYellow);
        }
Beispiel #5
0
        public void LoadContent(ContentManager content)
        {
            myModel = content.Load<Model>(@"Models\butterfly");
            SkinningData data = myModel.Tag as SkinningData;

            if (data == null)
                throw new InvalidOperationException
                    ("This model does not contain a SkinningData tag.");

            // Create an animation player, and start decoding an animation clip.
            animationPlayer = new AnimationPlayer(data);

            AnimationClip clip = data.AnimationClips["ArmatureAction_001"];

            animationPlayer.StartClip(clip);
            animationPlayer.Update(new TimeSpan(0, 0, 0, msOffset), true, Matrix.Identity);
        }