positioning the mouse cursor in OpenGl?

Started by
2 comments, last by Ut 24 years ago
Trying to code up a little demo in OpenGL using Linux and Mesa( so I guess it''s really Mesa). Does anyone know how to set the mouse position? Our problem is that when we exit the boundaries of the window, we stop moving, since we''re using glutPassiveMotionFunc. What we want is to not be able to leave the window until the program is exited. This way we can continue to rotate and view the screen like you would in any FPS game. Any help,tips, tricks would be appreciated. Ut
Advertisement
Hi Ut,

I too was wondering how to make a good mouse look function for my game. Awhile back I remember Quake2 junking out on my and I got to see how the master (carmack) did it.

Everytime you call the function to check the keys put this in there :

POINT p; // Point in the window
GetCursorPos(&p); // Get current mouse position
SetCursorPos(320, 240); // set the cursor in the center of
// the window
yrot -= (float)(320 - p.x)/100 * 12;
xrot -= (float)(240 - p.y)/100 * 12; // change -= to += for
// inverted
And voila! You got a mouse look simular or exactly like quake. To change the mouse speed, change the value 12.

I hope this helps!

Justin Eslinger
My game : Quell - to kill, to torment, to reduce to submission

Homepage : http://members.xoom.com/Blackscar/
Do you have to include a specific header to get this working? And was this for a windows or linux implementation? I couldn''t find a glut call that would do it, and I have a suspicion that SetCursorPos is a Microsoft call. Let me know if it can be done in linux though and if so what header needs to be included. Thanks for your help!

Ut
Actually...windows only...

This topic is closed to new replies.

Advertisement