View Full Version : glutMouseFunc() how do you know where your objects are located

09-13-2004, 07:40 AM

I am just starting to use OpenGL and I am trying to click on a triangle and move it around the screen.

I think I have to use glutMouseFunc()

but how do you know where the triangles are, you can't pass the coordinates into the function.

I could use global, but from all my C++ classes we learned that global=bad... so what is the best way to go about doing this.

09-13-2004, 10:37 AM
hey thor, welcome to the wonderful world of design decisions :)

a common approach is to keep geometry in some kind of world/level object. that way, to query the location of a particular object, you can ask the world where it is. the world can then do a line trace, or employ some other technique to determine the object's location at the mouse xy.

you might also look into the gluUnProject function. it takes points from screen-space back into world-space (handy info for line traces).

also, some clever use of gl picking can produce very good results. it all depends on what you're after.