示例#1
0
        private void UpdateMouse(GameTime gameTime)
        {
            float elapsed = GetElapsed(gameTime);

            if (ignoreMouse)
            {
                return;
            }

            float mouseSpeed = MouseSpeed * elapsed;

            MouseState mouseState = Mouse.GetState();

            if (mouseState.X != center.X)
            {
                Camera.Yaw((center.X - mouseState.X) * mouseSpeed);
            }

            if (mouseState.Y != center.Y)
            {
                Camera.Pitch((center.Y - mouseState.Y) * mouseSpeed);
            }

            Mouse.SetPosition(center.X, center.Y);
        }
示例#2
0
        private void UpdateKeyboard(GameTime gameTime)
        {
            float elapsed = GetElapsed(gameTime);

            float movementSpeed = MovementSpeed * elapsed;
            float rotationSpeed = RotationSpeed * elapsed;

            Vector3 direction = Vector3.Zero;

            keyboardState = Keyboard.GetState();
            Keys[] keys = keyboardState.GetPressedKeys();

            foreach (Keys key in keys)
            {
                switch (key)
                {
                case Keys.W: direction += Camera.MoveForward; break;

                case Keys.S: direction -= Camera.MoveForward; break;

                case Keys.D: direction += Camera.MoveRight; break;

                case Keys.A: direction -= Camera.MoveRight; break;

                case Keys.Y: direction += Camera.MoveUp; break;

                case Keys.X: direction -= Camera.MoveUp; break;

                case Keys.E: Camera.Roll(rotationSpeed); break;

                case Keys.Q: Camera.Roll(-rotationSpeed); break;

                case Keys.Up: Camera.Pitch(rotationSpeed); break;

                case Keys.Down: Camera.Pitch(-rotationSpeed); break;

                case Keys.Left: Camera.Yaw(rotationSpeed); break;

                case Keys.Right: Camera.Yaw(-rotationSpeed); break;
                }
            }

            if (direction != Vector3.Zero)
            {
                Vector3 velocity = Vector3.Normalize(direction) * movementSpeed;

                if (keyboardState.IsKeyDown(Keys.LeftControl))
                {
                    velocity *= MovementBoost;
                }

                Camera.Position += velocity;
            }

            if (IsKeyTyped(Keys.LeftShift))
            {
                ignoreMouse         = !ignoreMouse;
                Game.IsMouseVisible = ignoreMouse;

                if (!ignoreMouse)
                {
                    InitializeMouse();
                }
            }

            prevKeyboardState = keyboardState;
        }