I would like to make a First Person Shooter and move the camera with the mouse. The problem is that when the cursor reaches the limits of the screen, the camera won't turn anymore. How can I keep the mouse centered and detect its movements anyway?
The general approach to handling this in classic Win32 programming is to capture the mouse delta each frame, and then reset the mouse position to the center of the screen. You also want to make the mouse cursor invisible, obviously, as otherwise things look ugly.
You can do the same thing in XNA, you just work with a slightly different interface. So you might do something like:
- At startup, set the mouse's position to the center of your screen with Mouse.SetPosition.
- Also at startup, make the mouse invisible.
- Every input frame, grab the current mouse state.
- Since you know the mouse was at the center, you can use the current X and Y values from the MouseState object you recovered in step #3 to compute the delta movement in both dimensions. You can feed these deltas to the rest of your game logic, such as (in your case) the camera code.
- Reset the mouse to the center of the screen before moving on to the next frame.
EDIT: Also, here is a tutorial I dug up via a Google search for "XNA relative mouse input" (which is what you're asking about). It's a bit old, I think, so some of the methods may have had their names changed, but the concepts should still apply.
EDIT 2: Meant to say "handling this in Win32" and not "handling this is Win32," updated accordingly.