Mouse interacting

Let’s say there are a bunch of points visible on the screen.
How do make OpenGL let you choose one of them by mouse-click, and move it around the screen as you hold down a mouse-button, then realease and let it stay so I can choose another point? I don’t think I have fully understood the interaction between ‘mouseFunc’ and ‘motionFunc’. It seems like the mouse- and screen-coordinates are a bit out of tune, by the way. If I enlarge the OpenGL-screen the tuning-problem gets worse.

Anybody?

You will need to do “picking and selection” to be able to determine when the mouse has selected an object.
This is a little complicated (and probably can’t be answered fully via this board).
I suggest you get (if you don’t have) or read (if you do have) the Red Book. I believe that there is a whole section on picking and selection.

here’s the low down on glut’s mouse callback functions:

void mouse(int button, int state, int x, int y)
button: either GLUT_LEFT_BUTTON, GLUT_RIGHT_BUTTON, GLUT_MIDDLE_BUTTON
state: GLUT_UP or GLUT_DOWN
x and y: window coords of mouse at time of callback

this function is good for getting initial mouse coordinates. it will only be called when the state of a mouse button changes from up to down, or down to up.

void passivemotion(int x, int y)
x and y: window coords of mouse at time of callback

this function gets called whenever the mouse moves WITHIN the window and a button is NOT pressed. this guy is the one you’d use to simulate a Quake-style mouse look feature.

void motion(int x, int y)
x and y: window coords of mouse at time of callback

this function is identical to passive motion except it gets called when the mouse moves and a button is pressed. you would need to set a global variable in the mouse() func above to be able to tell which button is pressed so it can be processed correctly in the motion() func. hope that helps

b