I have a scene consisting of a lot of points which I drew using
glBegin(GL_POINTS);
glVertex3f(x[i],y[i],z[i]); // the points are displayed properly ..
glEnd();
What I wish to do is to be able to click on one of the points on the scene using the mouse and get its 3-D coordinate.
I have seen other threads to use :
glReadPixels((GLdouble)mouse_x,
(GLdouble) (rect.Height()-mouse_y-1),1, 1,GL_DEPTH_COMPONENT, GL_FLOAT, &Z);
and use the value of z in
gluUnProject(mouse_x, mouse_y, 0, modelview, projection, viewport, out posX, out posY, out posZ);
but i always get z=0
as the output .Is this because these are points and not a polygon?Is there any way to get the coordinates of the z?
Unfortunately, it can't be done. Any point x,y point on the screen can refer to any point along a given ray in the scene.
Given that you're drawing points, you probably want to use select mode to select a specific point, and then determine the coordinates of that point.