www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit dca352236cca4905cdcd2554bac2bf674a509afd
parent d5ff67dc04b86705b64cf66e81eb1d871dc5b2e4
Author: Yoann <yoann.b87@voila.fr>
Date:   Tue, 11 Oct 2011 21:22:54 +0200

Modification des normales pour améliorer l'éclairage.

Diffstat:
Mdisplay.c | 8++++----
Msquare.c | 21++++++++++++++++-----
2 files changed, 20 insertions(+), 9 deletions(-)

diff --git a/display.c b/display.c @@ -11,8 +11,8 @@ int initWindow() { glewInit(); float MatSpec[4] = {0.0f, 0.0f, 0.0f, 1.0f}; - float MatDif[4] = {0.0f, 0.8f, 0.0f, 1.0f}; - float MatAmb[4] = {0.1f, 0.1f, 0.1f, 1.0f}; + float MatDif[4] = {0.0f, 0.5f, 0.0f, 1.0f}; + float MatAmb[4] = {0.0f, 0.0f, 0.0f, 1.0f}; float Light1Pos[4] = {0.0f, 1.0f, 0.0f, 0.0f}; float Light1Dif[4] = {1.0f, 1.0f, 1.0f, 1.0f}; @@ -69,8 +69,8 @@ int mainLoop() { case SDL_MOUSEMOTION: printf("mouse motion\n"); - xAngle = ((event.motion.x-windowWidth/2)*260/(windowWidth)); - yAngle = (event.motion.y-windowHeight/2)*260/(windowHeight); + xAngle = ((event.motion.x-windowWidth/2)*340/(windowWidth)); + yAngle = (event.motion.y-windowHeight/2)*340/(windowHeight); break; default: diff --git a/square.c b/square.c @@ -222,8 +222,17 @@ void setNormal(Vertex *center, Vertex *va, Vertex *v) { length = length; x = x/length; y = y/length; - z = -z/length; + z = z/length; + /*va = center; + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glColor3ub(255,255,255); + glBegin(GL_LINES); + glVertex3f(va->x,va->y,va->z); + glVertex3f(va->x+500*x,va->y+500*y,va->z+500*z); + glEnd(); + glEnable(GL_LIGHTING);*/ glNormal3f(x,y,z); } @@ -244,19 +253,21 @@ void QT_enumerate(QTNode* first) { for (n = first; n != NULL; n = n->nextNode) { qtnode_print(n); + glEnable(GL_NORMALIZE); glBegin(GL_TRIANGLE_FAN); setNormal(n->vertices[QT_NE],n->vertices[QT_SO],n->vertices[QT_SE]); // envoyer le vertex central center = n->center; + setNormal(center,n->vertices[ROT_NO],n->vertices[ROT_NO]->next[ROT_E]); glVertex3f(center->x,center->y,center->y); // Pour chaque côté - for (r = 0; r < 4; r++) { + for (r = 0, i = 0; r < 4; r++) { // On parcourt tous les vertices le long du côté. for (v = n->vertices[ROT_NO]; v != n->vertices[ROT_NE]; i++, v = v->next[ROT_E]) { - if(i==0){ + if(i <= 2){ va = v; - setNormal(center,n->vertices[QT_SO],v); + //setNormal(center,n->vertices[QT_SO],v); } else { setNormal(center,va,v); @@ -272,7 +283,7 @@ void QT_enumerate(QTNode* first) { // Nécessaire ssi on fait un TRIANGLE_FAN et qu'on ne peut pas lui dire de fermer la boucle. // On renvoie le 1er vertex du bord : (void)(n->vertices[QT_NO]); - setNormal(center,va,n->vertices[QT_NO]); + //setNormal(center,va,n->vertices[QT_NO]); glVertex3f(n->vertices[QT_NO]->x,n->vertices[QT_NO]->y,n->vertices[QT_NO]->z); glEnd(); }