Monogame - First-person Camera mouse-look

So the other post on fps cameras covered how to do the rotations of the view. This post covers handling the mouse input to move the fps camera.

The methodolgy for the mouse-look is much like the keyboard input post. The difference being that instead of storing the last state, you store an original state of the mouse. I.e. a position which is used to compare to the current mouse position.

The first person camera rotation has to be reactive to the amount moved by the player. Ie, they move the mouse a little bit, the camera moves a little etc. Its no good having it rotate at a constant rate.

  1. Set the mouse pointer to the center of the screen and store this as the originalState of the mouse. I did this in my Initialize function.
.
  1. Then where player input is checked, like with the keyboard, we store the new, current state of the mouse. Once stored, check if the state has changed, if it has calculate the difference between the mouse positions and rotate the camera by that amount on the relevent axis
.
  1. Finally, reset the mouse back to its original position at the end of the function where input is checked.
.