First Person Camera Proper Mouse Input

Started by
2 comments, last by compscialien 12 years, 3 months ago
I am wondering the best way to retrieve and handle mouse input for a first person camera. The idea is that the speed at which the camera turns does not depend on frame rate, i.e. 30 FPS plays the same as 1000 FPS.

One way to do this:

Record cursor position each frame
Reset cursor position to middle of window each frame
Scale that by some constant

Theoretically, this would produce constant camera speed, because the mouse would move more each frame at a lower frame rate, and move less at a higher frame rate. However, this doesn't work because at high frame rates, it is very possible that the cursor will move less than a pixel each frame, and you would get no movement.

How do you implement first person cameras?

If you use the mentioned method, how do you get around the flaws?
Advertisement
If the mouse hasn't moved you can't move the camera. I think the method you describe is the one usually used. On Windows you can use raw mouse input instead of reading and resetting the cursor position, which should have better resolution. http://msdn.microsoft.com/en-us/library/windows/desktop/ms645536(v=vs.85).aspx
The method you describe is a common way to create one. I think (not sure) you can use DirectInput to get more accurate mouse movement input.
If the application is windowed, you have to reset the cursor, else, you can just read in the raw mouse coordinates, and use those against the old values to find the delta values to use.

This topic is closed to new replies.

Advertisement