1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| glPushAttrib(GL_ALL_ATTRIB_BITS); /* on sauvegarde tous */
glDisable(GL_LIGHTING); /* pas besoin de la lumiere pour le picking, desactiver tous ce qui est inutile */
GLuint selectBuf[BUFSIZE];
GLint hits=0;
GLint viewport[4];
glGetIntegerv (GL_VIEWPORT, viewport);
glSelectBuffer (BUFSIZE, selectBuf);
(void) glRenderMode (GL_SELECT);
glInitNames();
glPushName(0);
glMatrixMode (GL_PROJECTION);
glPushMatrix (); /* push projection */
glLoadIdentity ();
camera->Camera::Focalise();
gluPickMatrix ((GLdouble) x, (GLdouble) (viewport[3] - y), 2.0, 2.0, viewport);
gluPerspective(60,1.5,0.1,100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix(); /* push modelview */
glLoadIdentity();
glTranslatef(0,0,-15);
for(int i=0; i<n_objects; ++i)
{
glLoadName(objects[i].id); /* on change le nom sur la pile */
objects[i].draw(); /* on dessine l'objet */
}
glPopMatrix(); /* pop modelview */
glMatrixMode (GL_PROJECTION);
glPopMatrix (); /* pop projection */
hits = glRenderMode (GL_RENDER);
cout<<"nb hits = "<<hits<<"\n";
processHits (hits, selectBuf, list);
glPopAttrib();
glutPostRedisplay();
} |
Partager