Jump to content
  • Advertisement
Sign in to follow this  
andrew111

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

This topic is 3031 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!