#### Archived

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

# GLUT and mouse + another question :)

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

## Recommended Posts

I know how to use the mouse with GLUT using the glutMotionFunc() and glutMouseFunc() function strappers, but MouseFunc only handles the buttons, and MotionFunc only seem to be called if a mousebutton is pressed. What I would like to know is how to get the x,y of the mouse when a button is not pressed. Moving on to my next question.. I''m writing a little terrain engine, and are having some troubles with my navigation system.. My vision is that it will become something similar to the system in Black and White, but for now I start out simple. When I press Mouse1 and move the mouse towards me I travel forward over my landscape (skycam view), moving mouse away takes me backward, and sideways causes the camera to pan. Middlebutton rotates the view, and rightbutton zooms. What I wrote for this translation is this:
  void Motion(int x, int y) { float mult = zoom / -161; // moving slower if near the ground if(mButton == 2) { // rotate view rotx += (y - mOldY); roty += (x - mOldX); } else if(mButton == 0) { // translate view if(y > mOldY) { // Move forward transx -= mult * sin(degtorad * roty); transz += mult * cos(degtorad * roty); } if(y < mOldY) { // Move backward transx += mult * sin(degtorad * roty); transz -= mult * cos(degtorad * roty); } if(x > mOldX) { // Pan right transx += mult * sin(degtorad * (roty + 90)); transz -= mult * cos(degtorad * (roty + 90)); } if(x < mOldX) { // Pan left transx += mult * sin(degtorad * (roty - 90)); transz -= mult * cos(degtorad * (roty - 90)); } } else if(mButton == 1) { // zoom zoom += (mOldY - y) * 20; } if(rotx < 5) rotx =5; if(rotx > 90) rotx = 90; if(zoom < -3200) zoom = -3200; if(zoom > -100) zoom = -100; mOldX = x; mOldY = y; glutPostRedisplay(); } 
Although this work, it''s not as smooth as I would like, for example if you move the mouse diagonaly the translation in that direction (forward + pan left for example) will be twise as fast as just moving forward or just panning. So if I move the mouse in a circular motion the camera motion becomes more of a 45deg rotated square if you know what I mean So if anyone have any idea how to solve this, (probably rewrite the whole thing) I would be thankfull for some help. Thanks for reading. return 1;

##### Share on other sites
Check out glutPassiveMotionFunc().
Not sure what you mean by your 2nd question.

##### Share on other sites
Hmmm.. I couldn''t find anything on glutPassiveMotionFunc()..
It wasn''t described in the red book, and a search on openGL.org came back empty..

I tried it anyway just like the MotionFunc and it seemed to work
Strange that it isn''t mentioned anywhere though..

return 1;

##### Share on other sites
Some of the GLUT documentation is incomplete but the man pages is OK. Here if you do not have the man command http://sites.netscape.net/ptrpck/glutman/index.htm

The glutPassiveMotionFunc is on the same man page as the motion function http://sites.netscape.net/ptrpck/glutman/glutMotionFunc.html

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 10
• 14
• 30
• 13
• 11
• ### Forum Statistics

• Total Topics
631782
• Total Posts
3002332
×