Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

snisarenko

How do u handle WM_MOUSEMOVE

This topic is 5753 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

I am trying to write a program where my camera rotates with the mouse movement. When I handle WM_MOUSEMOVE, wParam is how much the mouse moved horizontaly, and lParam is how much it moved verticaly, Right ? Or do i not understand something? Those of you who have done camera-mouse movement give me a suggestion on how to do it.

Share this post


Link to post
Share on other sites
Advertisement
snisarenko--

with WM_MOUSEMOVE, wParam is not used (or it might be i just dont know what for). what you have to do is use LOWORD(lParam), and HIWORD(lParam). this separates the extremely large DWORD into two seperate values. LOWORD is the horizontal POSITION in pixels of the cursor and HIWORD is the Vertical POSITION of the cursor in relation to (0,0), which is in the top-left hand corner of the window.
Therefore, if the mouse starts at the very top-left, and then moves down some and right some, the new position might be something like (56,123). the number will NEVER be negative, because if the mouse moves all the way to the top or left, then it has left the boundries of the window.
Heres what i did to solve that problem. I made 4 global floats, MX,MY (mouse x and y), W,H (width , height of the window). in CreateGlWindow(), right after "WindowRect.bottom=(long)height;" i put in "W = width" and "H = height". this makes w and h the width and height of the new window. than, in WndProc(), I put "case WM_MOUSEMOVE: MX = LOWORD(lParam)-(W/2);". This statement says to take the new mouse position (LOWORD(lParam)), and subtract half of the screen, making the new origin at 0. I did the same thing with MY, except, because I want the y to increase going up, instead of going down, i made the whole thing negative. "MY = -(HIWORD(lParam)-(H/2))" this reduces, and we are left with "MY = -HIWORD(lParam)+(H/2)", (or even "MY = (H/2)-HIWORD(lParam);" if you really want to get picky). now you have the origin in the middle, and two variables for movement.
What i would do to rotate the camera is to do this in DrawGlScene(): "glRotate(.05f/**/*MY,.05f*MX,0.0f);
this should rotate left and right with the mouse.
Whew! that was a lot of typing! hope this helps!
--Steve

Share this post


Link to post
Share on other sites
I think I understand. I will try that. Thank u.

One little question. Does Windows send a WM_MOUSEMOVE when I use SetCursor(); function ?

[edited by - snisarenko on December 26, 2002 9:21:22 PM]

Share this post


Link to post
Share on other sites

  • 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!