Voir en 3D : termes importants

Voir en 3D : principes

Voir en 3D : principes (2)

  1. Clipping 3D des objets de la scène sur la pyramide de vue (frustum)
  2. Projeter le contenu de la pyramide de vue sur le plan focal (repère du monde)
  3. Passer du repère du monde au repère de la caméra
  4. Passer du repère caméra au repère de l'écran
  5. Dessiner le résultat dans la fenêtre graphique


Principaux types de projections planaires:


Les projections parallèles (1)

(x, y, z) --> drop z coordinate --> (x, y) : projects onto x-y plane

Les projections parallèles (2)

Les projections parallèles: avec OpenGL

glOrtho(GLdouble Xmin, Xmax, Ymin, Ymax, Zmin, Zmax)


Projection perspective

Projection perspective (2)

On a : y/(E-z) = (y'/E)

ainsi

y' = Y*E / (E-z) = y*(E/(E-z)) = y*(1/(1-(z/E)))
S = 1/(1-(z/E)) <-- facteur de perspective

So... y'= y*S = y/(1-z/E),   x' = x*S = x/(1-z/E)

Projection perspective (3)


Projection perspective : un exemple

 Point
Coords 
Monde
Coords
Orthographiques 
Facteur de perspective S
Coords
perspectives
A
 (2,1,0)
 (2,1)
 1.0
 (2,1)
 B
 (2,1,-10)
 (2,1)
 0.09
 (0.18, 0.09)
 C
 (2,1,-100)
 (2,1)
 0.001
 (0.02, 0.001)
 D
 (2,-5,-100)
 (2,-5)
 0.001
 (0.02, -0.05)
 E
 (-50,-50,-100)
 (-50,-50)
 0.001
 (-0.49, -0.49)

Point de fuite : Lim(z -> -inf) (1/(1-(z/E)) = Lim(z -> -inf) (1/(1-z)) = 0

projection perspective: OpenGL

Projection perspective: OpenGL (2)

gluPerspective(GLdouble fovy, aspect, zNear, zFar)

Changer le point de vue en OpenGL

1. Déplacer la caméra "à la main"

Déplacer  le point de vue en OpenGL (2)

2. gluLookAt(GLdouble eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ)

Example de programme OpenGL

Example de programme OpenGL (2)

#include <GL/gl.h>
#include <GL/glut.h>

long v[8][3] = {
        {-1, -1, -1},
        {-1, -1,  1},
        {-1,  1,  1},
        {-1,  1, -1},
        { 1, -1, -1},
        { 1, -1,  1},
        { 1,  1,  1},
        { 1,  1, -1}
};
int path[16] = {
        0, 1, 2, 3,
        0, 4, 5, 6,
        7, 4, 5, 1,
        2, 6, 7, 3
};

void drawcube() {
        int i;

        glClear(GL_COLOR_BUFFER_BIT);
        glColor3f(0.0, 0.0, 0.0);

        glBegin(GL_LINE_STRIP);
        for (i=0; i < 16; i++)
                glVertex3i(v[path[i]][0], v[path[i]][1], v[path[i]][2]);
        glEnd();
        glFlush();
}

main(int argc, char **argv) {
        glutInit(&argc, argv);
        glutInitWindowSize(600, 400);
        glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
        glutCreateWindow("glLookat example");
 

        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        gluPerspective(30.0, 1.5, 0.1, 10.0);
        gluLookAt(5.0, 4.0, 6.0, 1.0, 1.0, 1.0, 0.0, 1.0, 0.0);

        glMatrixMode(GL_MODELVIEW);

        glClearColor(1.0, 1.0, 1.0, 0.0);  /* white */
        glClear(GL_COLOR_BUFFER_BIT);

        glutDisplayFunc(drawcube);
        glutMainLoop();
        return 0;
}
 
 

Références