Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.Xna.Framework;
- using Microsoft.Xna.Framework.Input;
- using System;
- namespace Game1
- {
- internal static class ExampleInput
- {
- static MouseState previousMouseState;
- #region Extension Methods
- internal static int DeltaX(this MouseState mouseState)
- {
- return Mouse.GetState().X - previousMouseState.X;
- }
- internal static int DeltaY(this MouseState mouseState)
- {
- return Mouse.GetState().Y - previousMouseState.Y;
- }
- internal static int DeltaScrollWheelValue(this MouseState mouseState)
- {
- return Mouse.GetState().ScrollWheelValue - previousMouseState.ScrollWheelValue;
- }
- internal static bool Moving(this MouseState mouseState)
- {
- return (Mouse.GetState().X != previousMouseState.X || Mouse.GetState().Y != previousMouseState.Y) ? true : !true;
- }
- #endregion
- internal static void Update()
- {
- CameraMovement();
- // Call last so all other methods have previous states when called.
- previousMouseState = Mouse.GetState();
- }
- static void CameraMovement()
- {
- if (Mouse.GetState().DeltaScrollWheelValue() != 0)
- {
- Game1.mainCamera.destination += (Mouse.GetState().DeltaScrollWheelValue() * (float)Game1.gameTime.ElapsedGameTime.TotalSeconds * Game1.mainCamera.transform.Matrix.Forward * 100);
- Console.Clear();
- Console.WriteLine("Input manager thinks forward is: " + Game1.mainCamera.View.Forward);
- }
- if (Mouse.GetState().DeltaX() != 0 && Mouse.GetState().MiddleButton == ButtonState.Pressed)
- {
- Game1.mainCamera.destination += Mouse.GetState().DeltaX() * (float)Game1.gameTime.ElapsedGameTime.TotalSeconds * Game1.mainCamera.View.Right * 100;
- }
- if (Mouse.GetState().DeltaY() != 0 && Mouse.GetState().MiddleButton == ButtonState.Pressed)
- {
- Game1.mainCamera.destination += -Mouse.GetState().DeltaY() * (float)Game1.gameTime.ElapsedGameTime.TotalSeconds * Vector3.Up * 100;
- }
- if (Mouse.GetState().Moving() && Keyboard.GetState().IsKeyDown(Keys.LeftAlt))
- {
- // Rotate the camera.
- // **This is the part I have no clue how to rotate properly**
- Game1.mainCamera.transform.Rotation = Quaternion.Concatenate(Game1.mainCamera.transform.Rotation, Quaternion.CreateFromAxisAngle(Game1.mainCamera.View.Up, Mouse.GetState().DeltaX() * (float)Game1.gameTime.ElapsedGameTime.TotalSeconds * 15));
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement