Sign in to follow this  
andrew111

Raw mouse input, how to zero values when not moving?

Recommended Posts

Hi, I'm using the win32 raw mouse input within the window messageProc, so when it receives the WM_INPUT message I then set my mouseX and mouseY values. My problem is that those values are only set when the mouse is moved, so that they aren't set to 0 when the mouse isn't moving. This is causing problems with my mouse look, making it drift around the place. I tried setting a mouseMoved flag to true when the mouseX and mouseY variables are set, and then in my main loop I am doing this:
while(1) {
   runWindowMessages();

   runGameCodeIncludingMouseLook();

   if(!mouseMoved) {
       mouseX=mouseY=0;
   }
   mouseMoved = false;
}
But this just makes things jerky, since when the mouseX and mouseY are sampled, most of the time they are getting (0,0). (This is with vsync off btw.) Thanks.

Share this post


Link to post
Share on other sites
I do it like this:

//in the main/game loop
if (mouse.lmb) xRot += mouse.x - mouse.xOld;
if (mouse.lmb) yRot += mouse.y - mouse.yOld;
mouse.xOld = mouse.x;
mouse.yOld = mouse.y;
//in the message loop
case WM_MOUSEMOVE:
mouse.x = GET_X_LPARAM (lParam);
mouse.y = GET_Y_LPARAM (lParam);
break;



Works like a charm.

Edit:
Oh wait, mouse look
Then you should do it like this:
Get the mouse coords from a variable that is updated in message cycle
Snap mouse to the middle of the screen
Subtract screen center coordinates from previously retrieved ones

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this