View Full Version : Detect what the user clicks on
03-14-2008, 02:18 PM
I am drawing a bunch of spheres with:
void DrawPoint(Point P, double rad, int Color)
glTranslatef(P.getX(), P.getY(), P.getZ());
glutSolidSphere(rad, 20, 20);
I am storing these in a display list.
Once the spheres are displayed and i am rotating and zooming and all that good stuff (in the glut main loop), I would like the user to click on one of them and report which one he clicked on. Is this possible?
03-14-2008, 07:30 PM
Yes, but you need to use the selection mechanism, and you will have to change the hit target name between spheres.
You will get a list of hits in the buffer which you will have to determine which is closest.
Colors and readback may be simpler.
03-15-2008, 07:06 AM
A better solution would be to to render each sphere with another color. And read the pixel with glReadPixel from the backbuffer.
03-15-2008, 07:14 AM
Thanks for the replies guys. I found a super easy way to do it though. There is a function set called ZPR (Zoom Pan Rotate - http://www.nigels.com/glt/gltzpr/).
1) it is great for what I am doing (plotting stuff that i want to look at, nothing like gaming haha)
2) all you have to do to select an object in a display list is:
//...other setup stuff...
void pick(GLint name)
printf("Pick: %d\n", name);
This should be global
TestList = glGenLists(1);
void DrawSphere(double x, double y, double z, double r, double g, double b, GLuint nam)
glutSolidSphere(1, 20, 20);
Hope this helps others! By the way, why is something to the effect of ZPR not built right into glut?? It seems to be SUPER useful!
03-16-2008, 04:13 AM
Well, that ZPR is just a wrapper for the selection mode. See dorbies reply.
Please note that this feature is very useful for small scenes but can get very slow for bigger ones.
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.