Les mécanismes de sélection et de picking permettent l'interaction de l'utilisateur avec la scène 3-D :
Le mécanisme de feedback permet de récupérer des informations sur ce qui doit être dessiné sur l'écran
glInitNames();
glPushName(-1);
glPushMatrix(); /* save the current transformation state */
/* create your desired viewing volume here */
glLoadName(1);
drawSomeObject();
glLoadName(2);
drawAnotherObject();
glLoadName(3);
drawYetAnotherObject();
drawJustOneMoreObject();
glPopMatrix (); /* restore the previous transformation state*/
> ./select hits = 2 number of names for hit = 1 z1 is 3.05176e-05; z2 is 3.05176e-05 the name is 1 number of names for hit = 1 z1 is 3.05176e-05; z2 is 3.05176e-05 the name is 3
On utilise gluPickMatrix() pour effectuer la sélection sur une petite zone de l'affichage

On multiplie la matrice de projection par la matrice suivante :

glMatrixMode (GL_PROJECTION);
glPushMatrix ();
glLoadIdentity ();
gluPickMatrix (...);
gluPerspective, glOrtho, gluOrtho2D, or glFrustum
/* ... draw scene for picking ; perform picking ... */
glPopMatrix();
> ./picksquare hits = 1 number of names for this hit = 2 z1 is 3.05176e-05; z2 is 3.05176e-05 names are 1 1 hits = 1 number of names for this hit = 2 z1 is 3.05176e-05; z2 is 3.05176e-05 names are 2 1 hits = 4 number of names for this hit = 2 z1 is 3.05176e-05; z2 is 3.05176e-05 names are 1 0 number of names for this hit = 2 z1 is 3.05176e-05; z2 is 3.05176e-05 names are 1 1 number of names for this hit = 2 z1 is 3.05176e-05; z2 is 3.05176e-05 names are 2 0 number of names for this hit = 2 z1 is 3.05176e-05; z2 is 3.05176e-05 names are 2 1
On utilise des noms multiples, qui reflètent la hiérarchie d'objets :
draw_wheel_and_bolts()
{
long i;
draw_wheel_body();
for (i = 0; i < 5; i++) {
glPushMatrix();
glRotate(72.0*i, 0.0, 0.0, 1.0);
glTranslatef(3.0, 0.0, 0.0);
glPushName(i);
draw_bolt_body();
glPopName();
glPopMatrix();
}
}
draw_body_and_wheel_and_bolts()
{
draw_car_body();
glPushMatrix();
glTranslate(40, 0, 20); /* first wheel position*/
glPushName(1); /* name of wheel number 1 */
draw_wheel_and_bolts();
glPopName();
glPopMatrix();
glPushMatrix();
glTranslate(40, 0, -20); /* second wheel position */
glPushName(2); /* name of wheel number 2 */
draw_wheel_and_bolts();
glPopName();
glPopMatrix();
/* draw last two wheels similarly */
}
draw_three_cars()
{
glInitNames();
glPushMatrix();
translate_to_first_car_position();
glPushName(1);
draw_body_and_wheel_and_bolts();
glPopName();
glPopMatrix();
glPushMatrix();
translate_to_second_car_position();
glPushName(2);
draw_body_and_wheel_and_bolts();
glPopName();
glPopMatrix();
glPushMatrix();
translate_to_third_car_position();
glPushName(3);
draw_body_and_wheel_and_bolts();
glPopName();
glPopMatrix();
}
d1 et d2 sont les valeurs de profondeur min et max du pick
Les valeurs de profondeur retournées permettent éventuellement de distinguer les objets par leur profondeur, si deux objets ont le même nom.
> ./pickdepth hits = 1 number of names for hit = 1 z1 is 0.833333; z2 is 0.833333 the name is 3 hits = 2 number of names for hit = 1 z1 is 0.166667; z2 is 0.166667 the name is 1 number of names for hit = 1 z1 is 0.5; z2 is 0.5 the name is 2 hits = 3 number of names for hit = 1 z1 is 0.166667; z2 is 0.166667 the name is 1 number of names for hit = 1 z1 is 0.5; z2 is 0.5 the name is 2 number of names for hit = 1 z1 is 0.833333; z2 is 0.833333 the name is 3
Retourne des informations sur ce qui doit être dessiné.
Exemple d'utilisation : Export vers un format de fichier 3D, impression
Les étapes du mode feedback :
> ./feedback GL_LINE_RESET_TOKEN 30.00 30.00 0.00 0.84 0.84 0.84 1.00 50.00 60.00 0.00 0.84 0.84 0.84 1.00 GL_LINE_TOKEN 50.00 60.00 0.00 0.84 0.84 0.84 1.00 70.00 40.00 0.00 0.84 0.84 0.84 1.00 GL_PASS_THROUGH_TOKEN 1.00 GL_PASS_THROUGH_TOKEN 2.00 GL_POINT_TOKEN 50.00 50.00 0.00 0.84 0.84 0.84 1.00