netwalker at August 24th, 2008 15:21 — #1
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.
reedbeta at August 24th, 2008 15:56 — #2
Hmm, I'm not sure what could be causing the problem but I've always gotten quite satisfactory mouse movement using Get/SetCursorPos.
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)
int deltax, deltay;
bool wrap = false;
// Get current mouse position
// 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;
// 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);
netwalker at August 25th, 2008 07:16 — #3
Yes Reedbeta. My implementation is pretty much the same, and as result, the outcome is the same. Just out of interest, if you run your application and then strafe left or right and whilst doing this move the mouse left or right, what does the screen look like. Since on mine in looks as if there are two images (one getting erased really quickly). It just doesn't LOOK the same as those that you get in real games. How often is data actually read from the mouse device? is it 60 times p/s?, what if my game runs at 120fps? or 30fps?. I'm at a loss here.
BTW. Is that implementation of yours running in a separate thread?.
vrnunes at August 25th, 2008 11:07 — #4
reedbeta at August 25th, 2008 12:38 — #5
Just out of interest, if you run your application and then strafe left or right and whilst doing this move the mouse left or right, what does the screen look like. Since on mine in looks as if there are two images (one getting erased really quickly).
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?
BTW. Is that implementation of yours running in a separate thread?
No, I run it in the main thread each frame.
mmakrzem at August 26th, 2008 15:00 — #6
It sounds like you are getting tearing as Reedbeta suggested.
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?
kenneth_gorking at August 26th, 2008 17:55 — #7
Or maybe you are not scaling the movement with the frametime. That would certainly give uneven motion like you described.