public void Update(GameTime time)
        {
            float ts = TimeScale * 6.0f * 0.0167f;

            if (ts > 0)
            {
                GameTime gameTime = new GameTime(TimeSpan.Zero, TimeSpan.FromSeconds(ts), TimeSpan.Zero, TimeSpan.FromSeconds(ts));

                if (!playingSkinned)
                {
                    skinnedPlayer.StartClip(skinnedClip, 1, TimeSpan.Zero);

                    rigidPlayer.StartClip(rigidClip, 1, TimeSpan.Zero);

                    playingSkinned = true;

                    if (skinnedRootPlayer != null && skinnedRootClip != null)
                    {
                        skinnedRootPlayer.StartClip(skinnedRootClip, 1, TimeSpan.Zero);
                    }
                    if (rigidRootPlayer != null && rigidRootClip != null)
                    {
                        rigidRootPlayer.StartClip(rigidRootClip, 1, TimeSpan.Zero);
                    }
                }

                // If we are playing skinned animations, update the players
                if (playingSkinned)
                {
                    if (skinnedRootPlayer != null)
                    {
                        skinnedRootPlayer.Update(gameTime);
                    }
                    if (rigidRootPlayer != null)
                    {
                        rigidRootPlayer.Update(gameTime);
                    }

                    skinnedPlayer.Update(gameTime);
                    rigidPlayer.Update(gameTime);
                }
            }
        }
Beispiel #2
0
        public Model3DSkinned(SceneContainer scene, Vector3 pos, Matrix rotation, Vector3 scale, String modelName, String clip)
            : base(scene, pos, rotation, scale)
        {
            this.scene     = scene;
            this.modelName = modelName;

            this.clip    = clip;
            this.animate = false;
            this.jumping = false;
            this.rising  = false;
            model        = scene.Game.Content.Load <Model>(modelName);

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

            if (skinningData != null)
            {
                if (skinningData.RootAnimationClips != null)
                {
                    rootAnimationPlayer = new RootAnimationPlayer();
                }
                if (skinningData.ModelAnimationClips != null)
                {
                    skinnedAnimationPlayer = new SkinnedAnimationPlayer(skinningData.BindPose, skinningData.InverseBindPose, skinningData.SkeletonHierarchy);
                    skinnedAnimationPlayer.StartClip(skinningData.ModelAnimationClips[clip]);
                    boneTransforms = skinnedAnimationPlayer.GetSkinTransforms();
                    skinnedAnimationPlayer.Update(new GameTime(new TimeSpan(), new TimeSpan(2)));
                }
            }
            bsLocal = new BoundingSphere();
            foreach (ModelMesh mesh in model.Meshes)
            {
                bsLocal = BoundingSphere.CreateMerged(bsLocal, mesh.BoundingSphere);
            }
            setObject(pos.X, pos.Y, pos.Z);
        }
        protected override void Update(GameTime gameTime)
        {
            // Get the current gamepad state and store the old
            lastGamePadState    = currentGamePadState;
            currentGamePadState = GamePad.GetState(PlayerIndex.One);

            lastKeyboardState    = currentKeyboardState;
            currentKeyboardState = Keyboard.GetState();

            // Allows the game to exit
            if (currentGamePadState.Buttons.Back == ButtonState.Pressed ||
                currentKeyboardState.IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // When the A button is pressed and we aren't playing the rigid animations, play them
            if ((IsNewButtonPress(Buttons.A) || IsNewKeyPress(Keys.A)) && playingRigid == false)
            {
                if (rigidPlayer != null && rigidClip != null)
                {
                    rigidPlayer.StartClip(rigidClip, 1, TimeSpan.Zero);
                    playingRigid = true;
                }

                if (rigidRootPlayer != null && rigidRootClip != null)
                {
                    rigidRootPlayer.StartClip(rigidRootClip, 1, TimeSpan.Zero);
                    playingRigid = true;
                }
            }

            // When the B button is pressed and we aren't playing the skinned animations, play them
            if ((IsNewButtonPress(Buttons.B) || IsNewKeyPress(Keys.B)) && playingSkinned == false)
            {
                if (skinnedPlayer != null && skinnedClip != null)
                {
                    skinnedPlayer.StartClip(skinnedClip, 1, TimeSpan.Zero);
                    playingSkinned = true;
                }

                if (skinnedRootPlayer != null && skinnedRootClip != null)
                {
                    skinnedRootPlayer.StartClip(skinnedRootClip, 1, TimeSpan.Zero);
                    playingSkinned = true;
                }
            }

            // If we are playing rigid animations, update the players
            if (playingRigid)
            {
                if (rigidRootPlayer != null)
                {
                    rigidRootPlayer.Update(gameTime);
                }

                if (rigidPlayer != null)
                {
                    rigidPlayer.Update(gameTime);
                }
            }

            // If we are playing skinned animations, update the players
            if (playingSkinned)
            {
                if (skinnedRootPlayer != null)
                {
                    skinnedRootPlayer.Update(gameTime);
                }

                if (skinnedPlayer != null)
                {
                    skinnedPlayer.Update(gameTime);
                }
            }

            base.Update(gameTime);
        }
Beispiel #4
0
 public void updateClip(String clip)
 {
     this.clip = clip;
     skinnedAnimationPlayer.StartClip(skinningData.ModelAnimationClips[clip]);
 }
        public Cyclist()
        {
            //string test = typeof(AnimationDataReader).AssemblyQualifiedName;
            TimeScale    = 1;
            skinnedModel = BaseGame.Content.Load <XnaModel>("Content\\Models\\bike_boy");
            objectMatrix = Matrix.CreateScale(0.5f);// Matrix.Identity;

            // Create animation players for the skinned model
            animData = skinnedModel.Tag as AnimationData;
            if (animData != null)
            {
                if (animData.RootAnimationClips != null && animData.RootAnimationClips.ContainsKey("Take 001"))
                {
                    skinnedRootClip = animData.RootAnimationClips["Take 001"];

                    skinnedRootPlayer            = new RootAnimationPlayer();
                    skinnedRootPlayer.Completed += new EventHandler(skinnedPlayer_Completed);
                }
                if (animData.ModelAnimationClips != null && animData.ModelAnimationClips.ContainsKey("Take 001"))
                {
                    skinnedClip = animData.ModelAnimationClips["Take 001"];

                    skinnedPlayer = new SkinnedAnimationPlayer(animData.BindPose, animData.InverseBindPose, animData.SkeletonHierarchy);

                    skinnedPlayer.StartClip(skinnedClip, 1, TimeSpan.Zero);
                    skinnedPlayer.CurrentTimeValue = skinnedClip.Duration;
                    skinnedPlayer.CurrentTimeValue = TimeSpan.Zero;

                    skinnedPlayer.Completed += new EventHandler(skinnedPlayer_Completed);
                }
            }

            rigidModel = BaseGame.Content.Load <XnaModel>("Content\\Models\\bike");

            // Create animation players/clips for the rigid model
            animData2 = rigidModel.Tag as AnimationData;
            if (animData2 != null)
            {
                if (animData2.RootAnimationClips != null && animData2.RootAnimationClips.ContainsKey("Take 001"))
                {
                    rigidRootClip = animData2.RootAnimationClips["Take 001"];

                    rigidRootPlayer            = new RootAnimationPlayer();
                    rigidRootPlayer.Completed += new EventHandler(skinnedPlayer_Completed);
                    rigidRootPlayer.StartClip(rigidRootClip, 1, TimeSpan.Zero);
                }
                if (animData2.ModelAnimationClips != null && animData2.ModelAnimationClips.ContainsKey("Take 001"))
                {
                    rigidClip = animData2.ModelAnimationClips["Take 001"];



                    rigidPlayer = new RigidAnimationPlayer(rigidModel.Bones.Count);
                    rigidPlayer.StartClip(rigidClip, 1, TimeSpan.Zero);


                    rigidPlayer.CurrentTimeValue = rigidClip.Duration;
                    rigidPlayer.CurrentTimeValue = TimeSpan.Zero;

                    rigidPlayer.Completed += new EventHandler(skinnedPlayer_Completed);
                }
            }


            skinned = BaseGame.Content.Load <Effect>("Content\\Shaders\\skinned");
            skinned.CurrentTechnique = skinned.Techniques[0];

            Update(null);
        }