Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
I was wondering if there is a way to select an object that I draw in a graphics window? say for example, I have 3 spheres drawn to the window, is there a way to select one of them using the mouse and differentiate it from he other 2? the only way I know of is by comparing the objects position and the position of the mouse. Is there an easier way? All ideas are welcome.
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
OpenGl does have a mechanism called Picking to do this. But it's easy to implement your own method. For example when a mouse is clicked. Draw the scene again to the back buffer (no need to display it), but use a different colour for each sphere. You can then identify the sphere clicked on by reading the colour of the pixel that was clicked on.

b e n
 

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
thanks, ill look up picking on google. and that color trick doesnt seem too hard either. except it may get tedious to keep track of all the colors as the window will have many spheres in it.
 

kpua

macrumors 6502
Jul 25, 2006
294
0
The OpenGL picking is really easy to do. A quick reference to the man pages for glRenderMode and gluPickMatrix should get you going pretty quick.
 

kashmoney2006

macrumors regular
Original poster
Dec 12, 2007
232
0
I got it to work, but not after translating the objects. anyway to translate the pick matrix the same amount as you translate the drawn objects when using glTranslate? ive tried different things but none havent worked for myself.

Edit: nevermind. I got it to work. :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.