Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (MouseState.IsButtonDown(MouseButton.Right))
- {
- CursorState = CursorState.Grabbed;
- var input = KeyboardState;
- const float cameraSpeed = 1.5f;
- const float sensitivity = 0.2f;
- if (input.IsKeyDown(Keys.W))
- {
- _camera.Position += _camera.Front * cameraSpeed * (float)e.Time; // Forward
- }
- if (input.IsKeyDown(Keys.S))
- {
- _camera.Position -= _camera.Front * cameraSpeed * (float)e.Time; // Backwards
- }
- if (input.IsKeyDown(Keys.A))
- {
- _camera.Position -= _camera.Right * cameraSpeed * (float)e.Time; // Left
- }
- if (input.IsKeyDown(Keys.D))
- {
- _camera.Position += _camera.Right * cameraSpeed * (float)e.Time; // Right
- }
- if (input.IsKeyDown(Keys.Space))
- {
- _camera.Position += _camera.Up * cameraSpeed * (float)e.Time; // Up
- }
- if (input.IsKeyDown(Keys.LeftShift))
- {
- _camera.Position -= _camera.Up * cameraSpeed * (float)e.Time; // Down
- }
- // Get the mouse state
- var mouse = MouseState;
- if (_firstMove) // This bool variable is initially set to true.
- {
- _lastPos = new Vector2(mouse.X, mouse.Y);
- _firstMove = false;
- }
- else
- {
- // Calculate the offset of the mouse position
- var deltaX = mouse.X - _lastPos.X;
- var deltaY = mouse.Y - _lastPos.Y;
- _lastPos = new Vector2(mouse.X, mouse.Y);
- // Apply the camera pitch and yaw (we clamp the pitch in the camera class)
- _camera.Yaw += deltaX * sensitivity;
- _camera.Pitch -= deltaY * sensitivity; // Reversed since y-coordinates range from bottom to top
- }
- }
- else
- {
- CursorState = CursorState.Normal;
- } if (MouseState.IsButtonDown(MouseButton.Right))
- {
- CursorState = CursorState.Grabbed;
- var input = KeyboardState;
- const float cameraSpeed = 1.5f;
- const float sensitivity = 0.2f;
- if (input.IsKeyDown(Keys.W))
- {
- _camera.Position += _camera.Front * cameraSpeed * (float)e.Time; // Forward
- }
- if (input.IsKeyDown(Keys.S))
- {
- _camera.Position -= _camera.Front * cameraSpeed * (float)e.Time; // Backwards
- }
- if (input.IsKeyDown(Keys.A))
- {
- _camera.Position -= _camera.Right * cameraSpeed * (float)e.Time; // Left
- }
- if (input.IsKeyDown(Keys.D))
- {
- _camera.Position += _camera.Right * cameraSpeed * (float)e.Time; // Right
- }
- if (input.IsKeyDown(Keys.Space))
- {
- _camera.Position += _camera.Up * cameraSpeed * (float)e.Time; // Up
- }
- if (input.IsKeyDown(Keys.LeftShift))
- {
- _camera.Position -= _camera.Up * cameraSpeed * (float)e.Time; // Down
- }
- // Get the mouse state
- var mouse = MouseState;
- if (_firstMove) // This bool variable is initially set to true.
- {
- _lastPos = new Vector2(mouse.X, mouse.Y);
- _firstMove = false;
- }
- else
- {
- // Calculate the offset of the mouse position
- var deltaX = mouse.X - _lastPos.X;
- var deltaY = mouse.Y - _lastPos.Y;
- _lastPos = new Vector2(mouse.X, mouse.Y);
- // Apply the camera pitch and yaw (we clamp the pitch in the camera class)
- _camera.Yaw += deltaX * sensitivity;
- _camera.Pitch -= deltaY * sensitivity; // Reversed since y-coordinates range from bottom to top
- }
- }
- else
- {
- CursorState = CursorState.Normal;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement