Archived

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

Win 32: Mouse input

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

Greetings! I''ve been adding mouse support for my OpenGL project and I''ve hit somewhat of a snag. After browsing MSDN and looking at a few online resources, I haven''t been able to find an answer to my problem, so I figured I''d turn to the boards. Essentially, I''m trying to allow the user to move the camera via the mouse. Nothing fancy: moving left/right spins the view around the Y axis and moving up/down around the X axis. The view remains centered around the center of the map, so it''s just a matter of rotating. I''m using this code...
case WM_MOUSEMOVE:
	yRot += (MouseX - (lParam & 0xFFFF)) / 1.75f;
	MouseX=           (lParam & 0xFFFF);
	return 0; 
I also had an ''xRot'' and ''MouseY'' in there but I removed them because for some reason they wouldn''t work. Moving the mouse rotated the landscape clockwise only and it did so by a tremendous amount, too. The code was essentially the same as this, except that I was getting 0xFFFF0000 and dividing by 0x10000 to get the mouse''s Y position. This works fine. Although I can''t say the movement was all that smooth. And when I hit the edge of the screen? Blonk! Mouse stops and moving it more does not result in more rotating. 1.75f is pretty much the exact amount by which I need to divide to do a full 360 degree spin. I originally thought I''d just move the cursor back to the center of the window if it hits the side (and adjust MouseX according to avoid jumping around) but the section on mouse input in MSDN made it seem as though moving the mouse was something you couldn''t do via the API (although I know I can; there just wasn''t any function to do it there...) So my question, basically, is how to avoid getting stuck on the edge of the screen. Any additional information will be very welcomed, though.

Share this post


Link to post
Share on other sites
i cant help u but.. why not use SDL for input? i mean, your using open gl so why not keep everything cross platform? also, its probably easier to use also i mean even i have used mouse input with SDL (for my map editors). also there is relative mouse positions which is what you want i think...

Share this post


Link to post
Share on other sites
Ahh, so it stopped receiving input because the mouse was considered outside of the window? That makes sense, I think. I''ll have a look at SetCapture and see if it continues receiving input then.

As for SendMessage? Never crossed my mind, lol. ^^; Anyhow, I suppose that should be the right way to do it. I just didn''t quite think of it. I''ll see what turns up. Thanks!

Share this post


Link to post
Share on other sites
I''m trying to do it with the Win32 API; mainly for the sake of learning.

Set/ReleaseCapture didn''t seem to do the trick like I had hoped it would. I set SetCapture in my window''s WM_LBUTTONDOWN and ReleaseCapture in the WM_LBUTTONUP, and had absolutely no difference in terms of results. It seems that no matter what I do, my fullscreen version just stops at the edge of the screen. Makes sense since the mouse DOES stop there, but even if I move my mouse it doesn''t seem to receive any form of input telling it there''s (at least) attempted movement.

And windowed, I tried to lock the cursor in my window (I forgot the function that does it offhand, something like SetCursorRect or something to that end) but the same thing happens: the cursor gets jammed against the edges and no matter how much I try, I can''t seem to detect that I''m still moving the mouse. That is, I can only rotate my camera until I hit the edge of the window then it stops there.

Unless this is impossible with the windows API, I''m still stumped. Gah...

Share this post


Link to post
Share on other sites
You can do with the Windows API, but it won''t be nice with other apps.

Use ClipCursor to confine the cursor inside your window. Do NOT forget to Unclip when losing focus or closing down. Once you receive a WM_MOUSEMOVE set the mouse in the center of your screen again. Your delta movement is the difference from the mouse pos in WM_MOUSEMOVE and the center of your window. You''ll also want to hide the mouse cursor (ShowCursor) or you''ll have the pointer in the center of your window all the time.

To set the mouse pos use mouse_event or SetCursorPos or SendInput.

Share this post


Link to post
Share on other sites
quote:
Original post by merlin9x9
You could also just use GetCursorPos and SetCursorPos .


That has already been suggested, tried, and resulted in the problem being solved. Thank you for trying.

Share this post


Link to post
Share on other sites
quote:
That has already been suggested, tried, and resulted in the problem being solved. Thank you for trying.

Funny... The only instances of GetCursorPos that my browser could find on the page were from me directly or indirectly.

Share this post


Link to post
Share on other sites
quote:
Original post by merlin9x9
quote:
That has already been suggested, tried, and resulted in the problem being solved. Thank you for trying.

Funny... The only instances of GetCursorPos that my browser could find on the page were from me directly or indirectly.



I think that anyone with half a brain would attain the logical conclusion that if there''s a ''Set...'' function, there''d be a reciprocal ''Get...'' function to go with it most of the time. No offense or disrespect intended.

Share this post


Link to post
Share on other sites