View Full Version : Mouse Coordinates with WM_MOUSEMOVE

02-11-2010, 04:40 AM
Hi all,

I am doing a small project in Opengl in windows and am simply moving a robot in 3d and at present works very well using keyboard input, but am now looking at rotating the robot by using the mouse hence to change direction of movement using the mouse.

I dont have access to my code at the moment as is at university but i Have found on the forums how people have got the X and y Using HIWORD and LOWORD of LPARAM?! however the number it gives cant simply be put into a float number of glrotatef as the number is simply to high...

I am asking for help please on how i can convert the number that i gain from loword and HIWORD to a float number i can use for X and Y. is this very simple to do and something i have overlooked or is it a little more comple..

any help will be greatly appreciated.

thanks, burrows111

02-11-2010, 06:56 AM
It sounds like you are hooking WM_MOUSE which is fine but maybe more than you need especially if it is confusing you.

Why not try GetCursorPos() instead? I'd compare the returned mouse coords with the mouse coords from the last frame and then scale by the number of milliseconds since the last frame. This gives mouse movement in pixels/sec which you'll easily convert to robot rotation in degrees/sec.

02-11-2010, 07:07 AM
Ok GetCursorPos() will return me the coords in pixel value...
Is it not possible to have this function running constantly to keep updating the X and Y with the mouse position? assuming so how do i convert from pixels / sec to rotation in degrees/sec?

Thanks for you answer Pziko!

02-11-2010, 12:49 PM
Personally I don't recommend GetCursorPos, and suggest sticking with the WM_MouseMove. GetCursorPos returns the mouse position in screen coordinates, and you only want mouse coordinates for the Client Area of your application. The client area is the exact size as your openGL rendering area in pixels, and are therefore the most relevant to what you're doing.

Furthermore, note that the Y coordinates Windows gives you start from the TOP-Left of the client area, while OpenGL starts from the bottom-left. This means that Y := WindowHeight - Y;

I don't know much about your program, but you will probably have to measure how far the mouse has moved by saving it's original position, and comparing it to the latest position given from WM_MouseMove. After that, it's just math, and that's up to you! Obviously, you can convert the numbers given from the MouseMove by dividing them until they are scaled to what you want, and stored as a float. Yes, that part is easy to do.

02-11-2010, 04:00 PM
It's probable that WM_MOUSE is a better technique, (although it's obviously less portable) but if you are looking at the difference in mouse coordinates between frames it doesn't matter what the coordinate system is (client or screen), nor where the origin is.

02-11-2010, 04:41 PM
ok thanks guys, shall stick with WM_MOUSE. thanks