Ejemplo n.º 1
0
 public Player()
 {
     Keyboard = new KeyboardWrapper();
     Mouse = new MouseWrapper();
 }
Ejemplo n.º 2
0
        public void Update(float gameTime, KeyboardWrapper keyboard, MouseWrapper mouse)
        {
            #if XBOX360
            //Turn based on gamepad input.
            Yaw += Game.GamePadState.ThumbSticks.Right.X * -1.5f * dt;
            Pitch += Game.GamePadState.ThumbSticks.Right.Y * 1.5f * dt;
            #else
            //Turn based on mouse input.
            Yaw += (200 - (mouse.State.X * (keyboard.InvertOptions.InvertX ? -1 : 1))) * gameTime * .12f;
            Pitch += (200 - (mouse.State.Y * (mouse.InvertOptions.InvertY ? -1 : 1))) * gameTime * .12f;
            #endif
            Mouse.SetPosition(200, 200);

            WorldMatrix = Matrix.CreateFromAxisAngle(Vector3.Right, Pitch) * Matrix.CreateFromAxisAngle(Vector3.Up, Yaw);

            float distance = Speed * gameTime;
            #if XBOX360
            //Move based on gamepad input.
                MoveForward(Game.GamePadState.ThumbSticks.Left.Y * distance);
                MoveRight(Game.GamePadState.ThumbSticks.Left.X * distance);
                if (Game.GamePadState.IsButtonDown(Buttons.LeftStick))
                    MoveUp(distance);
                if (Game.GamePadState.IsButtonDown(Buttons.RightStick))
                    MoveUp(-distance);
            #else

            //Scoot the camera around depending on what keys are pressed.
            if (keyboard.State.IsKeyDown(KeyBindings.Up))
                MoveForward(distance);
            if (keyboard.State.IsKeyDown(KeyBindings.Down))
                MoveForward(-distance);
            if (keyboard.State.IsKeyDown(KeyBindings.Left))
                MoveRight(-distance);
            if (keyboard.State.IsKeyDown(KeyBindings.Right))
                MoveRight(distance);
            #endif

            WorldMatrix = WorldMatrix * Matrix.CreateTranslation(Position);
            ViewMatrix = Matrix.Invert(WorldMatrix);
        }