Hi.
I have worked in a scene where users can interacte thought the mouse.
By clicking, a “3D object” should me selected (just painted in other color) on the screen.
The problem is that sometimes OpenGL returns more than one object, so my question is how could select the “nearest” object on the screen ?!
Below some code I have done:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
// selection buffer
GLuint buffer[128];
glSelectBuffer( 128, buffer );
// chance render mode
glRenderMode(GL_SELECT);
// switch to projection and save the matrix
glMatrixMode(GL_PROJECTION);
glPushMatrix();
// get the viewport
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
// new clipping volume, a small
//square around mouse´s cursor
glLoadIdentity();
gluPickMatrix( pos.X(), viewport[3]-pos.Y(), 2, 2, viewport); // pos is a Point from mouse click
…
…
…
Render();
// collect the hits
GLint hits = glRenderMode(GL_RENDER);
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
So, when “hits > 1” how can I get the nearest object selected ??!!
Thanks a lot in advance.
[ ]'s
Rogerio