Picking : gestion d'une hiérarchie d'objets |
![]() ![]() ![]() |
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
![]() |