Bonjour,
J'ai recupere le code de Nate Robbins (tutorial de GLUT) sur les lumieres et je ne comprends pas certaines choses.
Il y a une function qui dessine le "world"
world_display(void)
{
GLfloat pos[4];
double length;
float l[3];
cell_vector(pos, light, 4);
l[0] = lookat[3].value - lookat[0].value;
l[1] = lookat[4].value - lookat[1].value;
l[2] = lookat[5].value - lookat[2].value;
invert(modelview, inverse);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (swapped) {
glPushMatrix();
glTranslatef(l[0], l[1], l[2]);
glMultMatrixd(inverse);
glColor3ub(255, 255, 255);
glBegin(GL_LINE_STRIP);
glVertex3f(0.0, 0.0, 0.0);
if (pos[3] == 0) /* 10.0 = 'infinite' light */
glVertex3f(pos[0]*10.0,pos[1]*10.0,pos[2]*10.0);
else
glVertex3f(pos[0], pos[1], pos[2]);
glEnd();
glLightfv(GL_LIGHT0, GL_POSITION, pos);
glPopMatrix();
} else {
glColor3ub(255, 255, 255);
glBegin(GL_LINE_STRIP);
glVertex3f(0.0, 0.0, 0.0);
if (pos[3] == 0) /* 10.0 = 'infinite' light */
glVertex3f(pos[0]*10.0,pos[1]*10.0,pos[2]*10.0);
else
glVertex3f(pos[0], pos[1], pos[2]);
glEnd();
glLightfv(GL_LIGHT0, GL_POSITION, pos);
}
length = normalize(l);
if (world_draw) {
glEnable(GL_LIGHTING);
drawmodel();
glDisable(GL_LIGHTING);
}
glPushMatrix();
glMultMatrixd(inverse);
/* draw the axes and eye vector */
glPushMatrix();
glColor3ub(0, 0, 255);
glBegin(GL_LINE_STRIP);
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, -1.0*length);
glVertex3f(0.1, 0.0, -0.9*length);
glVertex3f(-0.1, 0.0, -0.9*length);
glVertex3f(0.0, 0.0, -1.0*length);
glVertex3f(0.0, 0.1, -0.9*length);
glVertex3f(0.0, -0.1, -0.9*length);
glVertex3f(0.0, 0.0, -1.0*length);
glEnd();
glColor3ub(255, 255, 0);
glRasterPos3f(0.0, 0.0, -1.1*length);
glutBitmapCharacter(GLUT_BITMAP_HELVETICA_12, 'e');
glColor3ub(255, 0, 0);
glScalef(0.4, 0.4, 0.4);
drawaxes();
glPopMatrix();
invert(projection, inverse);
glMultMatrixd(inverse);
/* draw the viewing frustum */
glColor3f(0.2, 0.2, 0.2);
glBegin(GL_QUADS);
glVertex3i(1, 1, 1);
glVertex3i(-1, 1, 1);
glVertex3i(-1, -1, 1);
glVertex3i(1, -1, 1);
glEnd();
glColor3ub(128, 196, 128);
glBegin(GL_LINES);
glVertex3i(1, 1, -1);
glVertex3i(1, 1, 1);
glVertex3i(-1, 1, -1);
glVertex3i(-1, 1, 1);
glVertex3i(-1, -1, -1);
glVertex3i(-1, -1, 1);
glVertex3i(1, -1, -1);
glVertex3i(1, -1, 1);
glEnd();
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4f(0.2, 0.2, 0.4, 0.5);
glBegin(GL_QUADS);
glVertex3i(1, 1, -1);
glVertex3i(-1, 1, -1);
glVertex3i(-1, -1, -1);
glVertex3i(1, -1, -1);
glEnd();
glDisable(GL_BLEND);
glPopMatrix();
glutSwapBuffers();
}
je ne comprends pas les histoires
invert(modelview, inverse);
..
puis
glPushMatrix();
glTranslatef(l[0], l[1], l[2]);
glMultMatrixd(inverse);
..
qu'est ce que cela fait et pourquoi as t'on besoin de faire ca pour placer les lumieres?
Merci!