Smooth mouse movement.
Posted 24 August 2008 - 07:21 PM
I'm having a problem in trying to get nice smooth mouse movement in my simple game engine. In fact my current implementation is awful. It jerks all over the place and I look at games like Serious Sam and UT and they have REALLY smooth movement. How on earth is this achieved?. Currently I'm using the standard mouse functions of GetCursorPos/SetCursorPos to do the movement and like I say it looks pretty poor (and above all unresponsive). So any advice/suggestions on how to implement such would be really appreciated.
Posted 24 August 2008 - 07:56 PM
Here is the code I use to process mouse movement:
// somewhere in the global state... static POINT mousepos; // run every frame (or on WM_MOUSEMOVE) POINT pt; int deltax, deltay; bool wrap = false; // Get current mouse position GetCursorPos(&pt); // Calculate deltas deltax = pt.x - mousepos.x; deltay = pt.y - mousepos.y; // Wrap mouse position if needed if (pt.x == GetSystemMetrics(SM_CXSCREEN) - 1) pt.x = 0, wrap = true; else if (pt.x == 0) pt.x = GetSystemMetrics(SM_CXSCREEN) - 1, wrap = true; if (pt.y == GetSystemMetrics(SM_CYSCREEN) - 1) pt.y = 0, wrap = true; else if (pt.y == 0) pt.y = GetSystemMetrics(SM_CYSCREEN) - 1, wrap = true; if (wrap) SetCursorPos(pt.x, pt.y); // Save off new mouse position mousepos = pt; // Inform the game that a mouse movement has occurred g_pGame->MouseMoved(deltax, deltay, (wParam & MK_LBUTTON) > 0, (wParam & MK_RBUTTON) > 0);
Posted 25 August 2008 - 11:16 AM
BTW. Is that implementation of yours running in a separate thread?.
Posted 25 August 2008 - 04:38 PM
I haven't got my app running on this computer, so I can't check, but I can't remember having seen something like what you describe.
The "two images" thing sounds like the tearing due to vsync being turned off. Is it possible that's the problem? Or is this something totally different?
No, I run it in the main thread each frame.
Posted 26 August 2008 - 07:00 PM
One other thing that I would like to ask is how many degrees do you rotate your camera when you get motion from the mouse? Could it be that you are moving too much?
Play my free games: Ghost Toast, Zing
Posted 26 August 2008 - 09:55 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users