La 3D avec OpenGL

Voir en 3D

Rappel : une matrice 4x4 peut

 

Pipe line OpenGL

Matrice MODELVIEW

Matrice PROJECTION

Division perspective

Viewport transformation

Avec OpenGL comment on manipule tout ça ?


...

Comment changer la valeur de la matrice courante ?

On applique les transformations de droite à gauche.

ATTENTION : si vous avez fait un glScale() toutes les transformations suivantes se feront avec les nouvelles unités !

Comment donner l'illusion que la caméra se déplace ?

En réalité la caméra reste tout le temps immobile ! C'est toute la scène qui bouge !

glMatrixMode(GL_MODELVIEW);
...
glTranslatef(0.0, 0.0, -5.0);

On empile des matrices !

Plans de clipping additionnels

double plan1 = {1.0, 1.0, 0.0, 0.0};
glClipPlane(0, plan1);

glEnable(GL_CLIP_PLANE0);

Exemple de plan de clipping


void display(void) { 
   GLdouble eqn[4] = {0.0, 1.0, 0.0, 0.0}; /* y < 0 */ 
   GLdouble eqn2[4] = {1.0, 0.0, 0.0, 0.0}; /* x < 0 */ 
   
   glClear(GL_COLOR_BUFFER_BIT); 
   glColor3f (1.0, 1.0, 1.0); 
   glPushMatrix(); 
   glTranslatef (0.0, 0.0, -5.0); 
   glClipPlane (GL_CLIP_PLANE0, eqn); 
   glEnable (GL_CLIP_PLANE0); 
   glClipPlane (GL_CLIP_PLANE1, eqn2); 
   glEnable (GL_CLIP_PLANE1); 
   glRotatef (90.0, 1.0, 0.0, 0.0); 
   glutWireSphere(1.0); 
   glPopMatrix(); 
   glFlush(); 
   } 
 

Quelques exemples d'objets hiérarchisés

glPushMatrix();
 glutWireSphere(1.0); /* draw sun */ 
 glRotatef ((GLfloat) year, 0.0, 1.0, 0.0); 
 glTranslatef (2.0, 0.0, 0.0); 
 glRotatef ((GLfloat) day, 0.0, 1.0, 0.0); 
 glutWireSphere(0.2); /* draw smaller planet */ 
 glPopMatrix(); 

Quelques exemples d'objets hiérarchisés (2)


glTranslatef (-1.0, 0.0, 0.0);
glRotatef ((GLfloat) shoulder_angle, 0.0, 0.0, 1.0);
glTranslatef (1.0, 0.0, 0.0);
glutWireBox(2.0, 0.4, 1.0);

glTranslatef (1.0, 0.0, 0.0); 
glRotatef ((GLfloat) elbow_angle, 0.0, 0.0, 1.0);
glTranslatef (1.0, 0.0, 0.0);
glutWireBox(2.0, 0.4, 1.0);


etc...