Exemplo n.º 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Font.Initialze(GraphicsDevice, Content);

            miku = Content.Load <PmdModel>("Models/miku");
            miku.Initialize(GraphicsDevice, Content);
            anim = Content.Load <VmdAnimation>("Anims/Lamb");
            miku.SetAnim(anim);
            anim.AnimationSpeed = 0.1f;
            //bone helper
#if WINDOWS
            helper = new BoneHelper(GraphicsDevice, Content);
#endif

            // TODO: use this.Content to load your game content here
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
            {
                this.Exit();
            }

            // TODO: Add your update logic here
            //update view
            if (g_bRotateCamera)
            {
                g_time   += gameTime.ElapsedGameTime.Milliseconds * 0.001f;
                CameraPos = new Vector3(g_fDistanceToMiku * (float)Math.Cos(g_time), height, g_fDistanceToMiku * (float)Math.Sin(g_time));
                View      = Matrix.CreateLookAt(CameraPos, new Vector3(0, height - 5, 0), new Vector3(0, 1, 0));
            }

            miku.Update(gameTime);


            #region Control
            //control region
            KeyboardState currentState      = Keyboard.GetState();
            MouseState    currentMouseState = Mouse.GetState();

            if (currentState.IsKeyDown(Keys.C) && lastKeyState.IsKeyUp(Keys.C))
            {
                miku = Content.Load <PmdModel>("Models/model_1");
                miku.Initialize(GraphicsDevice, Content);
                anim = Content.Load <VmdAnimation>("Anims/Lamb");
                miku.SetAnim(anim);
                anim.AnimationSpeed = 0.1f;
            }

            if (currentState.IsKeyDown(Keys.V) && lastKeyState.IsKeyUp(Keys.V))
            {
                miku = Content.Load <PmdModel>("Models/miku");
                miku.Initialize(GraphicsDevice, Content);
                anim = Content.Load <VmdAnimation>("Anims/Lamb");
                miku.SetAnim(anim);
                anim.AnimationSpeed = 0.1f;
            }
            if (currentState.IsKeyDown(Keys.Space) && lastKeyState.IsKeyUp(Keys.Space))
            {
                bShowAllBone = !bShowAllBone;
            }
            if (currentState.IsKeyDown(Keys.Enter) && lastKeyState.IsKeyUp(Keys.Enter))
            {
                g_bRotateCamera = !g_bRotateCamera;
            }
            if (currentState.IsKeyDown(Keys.P) && lastKeyState.IsKeyUp(Keys.P))
            {
                miku.Pause = !miku.Pause;
            }
            if (currentState.IsKeyDown(Keys.I) && lastKeyState.IsKeyUp(Keys.I))
            {
                miku.PauseBoneUpdate = !miku.PauseBoneUpdate;
            }
            //show ik bone
            if (currentState.IsKeyDown(Keys.K) && lastKeyState.IsKeyUp(Keys.K))
            {
                bShowIkBone = !bShowIkBone;
            }
            if (currentState.IsKeyDown(Keys.Up) && lastKeyState.IsKeyUp(Keys.Up))
            {
                showBoneIndex = (showBoneIndex + 1) % miku.BoneCount;
            }
            else if (currentState.IsKeyDown(Keys.Down) && lastKeyState.IsKeyUp(Keys.Down))
            {
                showBoneIndex = (showBoneIndex - 1 + miku.BoneCount) % miku.BoneCount;
            }
            if (currentState.IsKeyDown(Keys.Left))
            {
                showBoneIndex = (showBoneIndex + 1) % miku.BoneCount;
            }
            else if (currentState.IsKeyDown(Keys.Right))
            {
                showBoneIndex = (showBoneIndex - 1 + miku.BoneCount) % miku.BoneCount;
            }

            Vector3 forward = Vector3.Cross(CameraUp, CameraRight);
            forward.Normalize();

            if (currentState.IsKeyDown(Keys.W) || currentState.IsKeyDown(Keys.A) ||
                currentState.IsKeyDown(Keys.D) || currentState.IsKeyDown(Keys.S))
            {
                Vector3 moveMent = Vector3.Zero;
                if (currentState.IsKeyDown(Keys.W))
                {
                    moveMent = forward;
                }
                else if (currentState.IsKeyDown(Keys.S))
                {
                    moveMent = -forward;
                }
                if (currentState.IsKeyDown(Keys.A))
                {
                    moveMent = -CameraRight;
                }
                else if (currentState.IsKeyDown(Keys.D))
                {
                    moveMent = CameraRight;
                }
                moveMent     *= 0.05f;
                CameraPos    += moveMent;
                CameraTarget += moveMent;
                View          = Matrix.CreateLookAt(CameraPos, CameraTarget, CameraUp);
            }

            if ((lastMouseState.LeftButton == ButtonState.Pressed) && (lastMouseState.X != currentMouseState.X ||
                                                                       lastMouseState.Y != currentMouseState.Y))
            {
                float xMove = lastMouseState.X - currentMouseState.X;
                float yMove = lastMouseState.Y - currentMouseState.Y;

                CameraTarget += 0.05f * (-xMove * CameraRight + yMove * CameraUp);
                forward       = CameraTarget - CameraPos;
                forward.Normalize();

                CameraRight = Vector3.Cross(forward, CameraUp);
                CameraRight.Normalize();
                CameraUp = Vector3.Cross(CameraRight, forward);
                CameraUp.Normalize();

                //CameraUp = new Vector3(0, 1, 0);
                View = Matrix.CreateLookAt(CameraPos, CameraTarget, CameraUp);
            }
            if (currentState.IsKeyDown(Keys.Escape) && lastKeyState.IsKeyUp(Keys.Escape))
            {
                bShowMiku = !bShowMiku;
            }
            //show single chain
            if (currentState.IsKeyDown(Keys.F1) && lastKeyState.IsKeyUp(Keys.F1))
            {
                bShowSingleIkChain = !bShowSingleIkChain;
            }
            if (currentState.IsKeyDown(Keys.PageDown) && lastKeyState.IsKeyUp(Keys.PageDown))
            {
                showSingleChainIndex = (showSingleChainIndex - 1 + miku.IK_Chains.IKChainCount) % miku.IK_Chains.IKChainCount;
            }
            if (currentState.IsKeyDown(Keys.PageUp) && lastKeyState.IsKeyUp(Keys.PageUp))
            {
                showSingleChainIndex = (showSingleChainIndex + 1) % miku.IK_Chains.IKChainCount;
            }

            lastKeyState   = currentState;
            lastMouseState = currentMouseState;
            Font.DrawMessage(showBoneIndex.ToString(), 20, 20);
            #endregion
            base.Update(gameTime);
        }