La fenêtre texte donne les différentes valeurs numériques caractéristiques.
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Decembre 2001 */
/* Schema pour un calcul d'illumination */
/* de Gouraud */
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleCouleurs.h"
#include "ModuleFont.h"
#include "ModuleManipulateur.h"
#include "ModuleMatriceVecteur.h"
#include "ModuleMenus.h"
#include "ModuleFleche.h"
#include "ModuleReshape.h"
typedef float couleur[4];
struct facette3 {
vecteur pa;
couleur ca;
vecteur pb;
couleur cb;
vecteur pc;
couleur cc; } ;
static float px1;
static float pz1;
static float px2;
static float pz2;
static float px;
static float pz;
static float h1;
static float h2;
static int cr1;
static int cv1;
static int cb1;
static int cr2;
static int cv2;
static int cb2;
static int cr;
static int cv;
static int cb;
static int f1;
static int f2;
static float posx = 0.5F;
static float posy = 0.0F;
static facette3 f = { { 0.05F,0.8F,0.4F },
{ 0.9F,0.05F,0.8F },
{ -0.55F,-0.2F,-0.5F },
{ 0.1F,0.9F,0.7F },
{ 0.85F,-0.75F,-0.1F } ,
{ 0.7F,0.6F,0.1F } };
void myinit(void) {
GLfloat l_pos[] = { -1.0,1.0,1.0,0.0 };
glLightfv(GL_LIGHT0,GL_POSITION,l_pos);
glEnable(GL_LIGHT0);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glClearColor(0.7F,0.7F,0.8F,1.0F) ;
glDepthFunc(GL_LESS);
}
int intersection(vecteur pi,vecteur pf,couleur ci,couleur cf,float y,float *x,float *z,int *r,int *v,int *b,float *h) {
if ( ( y > pi[1] ) || ( y < pf[1] ) )
return(0);
float fact = (y-pf[1])/(pi[1]-pf[1]);
*h = 1.0F-fact;
*x = pf[0] + fact*(pi[0]-pf[0]);
*z = pf[2] + fact*(pi[2]-pf[2]);
*r =(int) ((cf[0] + fact*(ci[0]-cf[0]))*255);
*v =(int) ((cf[1] + fact*(ci[1]-cf[1]))*255);
*b =(int) ((cf[2] + fact*(ci[2]-cf[2]))*255);
return(1);
}
void evaluationIntersections(void) {
if ( intersection(f.pa,f.pb,f.ca,f.cb,posy,&px1,&pz1,&cr1,&cv1,&cb1,&h1) ) {
if ( !intersection(f.pa,f.pc,f.ca,f.cc,posy,&px2,&pz2,&cr2,&cv2,&cb2,&h2) )
intersection(f.pb,f.pc,f.cb,f.cc,posy,&px2,&pz2,&cr2,&cv2,&cb2,&h2); }
else {
intersection(f.pa,f.pc,f.ca,f.cc,posy,&px2,&pz2,&cr2,&cv2,&cb2,&h2);
intersection(f.pb,f.pc,f.cb,f.cc,posy,&px1,&pz1,&cr1,&cv1,&cb1,&h1); }
px = px1 + posx*(px2-px1);
pz = pz1 + posx*(pz2-pz1);
cr =(int) (cr1 + posx*(cr2-cr1));
cv =(int) (cv1 + posx*(cv2-cv1));
cb =(int) (cb1 + posx*(cb2-cb1));
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
glColor4fv(couleurGrisClair());
glEnable(GL_DEPTH_TEST);
glBegin(GL_POLYGON);
glColor4fv(f.ca);
glVertex3fv(f.pa);
glColor4fv(f.cb);
glVertex3fv(f.pb);
glColor4fv(f.cc);
glVertex3fv(f.pc);
glEnd();
glDisable(GL_DEPTH_TEST);
glColor4fv(couleurNoir());
glBegin(GL_LINES);
glVertex3f(px1,posy,pz1);
glVertex3f(px2,posy,pz2);
glEnd();
glBegin(GL_LINE_LOOP);
glVertex3fv(f.pa);
glVertex3fv(f.pb);
glVertex3fv(f.pc);
glEnd();
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
if ( posy > f.pb[1] ) {
glPushMatrix();
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurVert());
glTranslatef(f.pa[0],f.pa[1],f.pa[2]);
flecheEnVolume(px1-f.pa[0],posy-f.pa[1],pz1-f.pa[2],0.03F,0.1F,0.012F);
glPopMatrix(); }
else {
glPushMatrix();
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge());
glTranslatef(f.pb[0],f.pb[1],f.pb[2]);
flecheEnVolume(px1-f.pb[0],posy-f.pb[1],pz1-f.pb[2],0.03F,0.1F,0.012F);
glPopMatrix(); }
glPushMatrix();
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBleu());
glTranslatef(f.pa[0],f.pa[1],f.pa[2]);
flecheEnVolume(px2-f.pa[0],posy-f.pa[1],pz2-f.pa[2],0.03F,0.1F,0.012F);
glPopMatrix();
glPushMatrix();
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurJaune());
glTranslatef(px1,posy,pz1);
flecheEnVolume(px-px1,0.0F,pz-pz1,0.03F,0.1F,0.012F);
glPopMatrix();
glDisable(GL_LIGHTING);
glColor4fv(couleurGrisFonce());
glEnable(GL_LIGHTING);
float coul1[4] = { cr1/255.0F,cv1/255.0F,cb1/255.0F };
glMaterialfv(GL_FRONT,GL_DIFFUSE,coul1);
glPushMatrix();
glTranslatef(px1,posy,pz1);
glutSolidSphere(0.035F,10,10);
glPopMatrix();
float coul2[4] = { cr2/255.0F,cv2/255.0F,cb2/255.0F };
glMaterialfv(GL_FRONT,GL_DIFFUSE,coul2);
glPushMatrix();
glTranslatef(px2,posy,pz2);
glutSolidSphere(0.035F,10,10);
glPopMatrix();
float coul[4] = { cr/255.0F,cv/255.0F,cb/255.0F };
glMaterialfv(GL_FRONT,GL_DIFFUSE,coul);
glPushMatrix();
glTranslatef(px,posy,pz);
glutSolidSphere(0.035F,10,10);
glPopMatrix();
glDisable(GL_LIGHTING);
glDisable(GL_DEPTH_TEST);
glColor4fv(couleurBleu());
setAlignement(RIGHT);
if ( posy > f.pb[1] ) {
placeFontCursor((f.pa[0]+px1)/2.0F-0.05F,(f.pa[1]+posy)/2.0F,(f.pa[2]+pz1)/2.0F) ;
simpleBitmapOutput(REGULAR8x13,"PaP1 = h1PaPb") ;
deplacementCursor(-2,-5,0) ;
simpleBitmapOutput(DESSIN,"TTTTF TTTTF") ; }
else {
placeFontCursor((f.pb[0]+px1)/2.0F-0.05F,(f.pb[1]+posy)/2.0F,(f.pb[2]+pz1)/2.0F) ;
simpleBitmapOutput(REGULAR8x13,"PbP1 = h1PbPc") ;
deplacementCursor(-2,-5,0) ;
simpleBitmapOutput(DESSIN,"TTTTF TTTTF") ; }
setAlignement(LEFT);
placeFontCursor((f.pa[0]+px2)/2.0F+0.05F,(f.pa[1]+posy)/2.0F,(f.pa[2]+pz2)/2.0F) ;
simpleBitmapOutput(REGULAR8x13,"PaP2 = h2PaPb") ;
deplacementCursor(0,-5,0) ;
simpleBitmapOutput(DESSIN,"TTTTF TTTTF") ;
setAlignement(CENTER);
placeFontCursor(px,posy-0.1F,pz) ;
simpleBitmapOutput(REGULAR8x13,"P1P = hP1P2") ;
deplacementCursor(0,-5,0) ;
simpleBitmapOutput(DESSIN,"TTTF TTTTF") ;
setAlignement(CENTER);
placeFontCursor(f.pa[0]+0.05F,f.pa[1]+0.05F,f.pa[2]+0.05F) ;
simpleBitmapOutput(REGULAR8x13,"Pa (Ca)") ;
setAlignement(RIGHT);
placeFontCursor(f.pb[0]-0.05F,f.pb[1],f.pb[2]+0.05F) ;
simpleBitmapOutput(REGULAR8x13,"Pb (Cb)") ;
setAlignement(LEFT);
placeFontCursor(f.pc[0]+0.05F,f.pc[1],f.pc[2]+0.05F) ;
simpleBitmapOutput(REGULAR8x13,"Pc (Cc)") ;
setAlignement(CENTER);
placeFontCursor(px1-0.1F,posy+0.1F,pz1+0.1F) ;
simpleBitmapOutput(REGULAR8x13,"P1") ;
placeFontCursor(px2+0.1F,posy+0.1F,pz2+0.1F) ;
simpleBitmapOutput(REGULAR8x13,"P2") ;
placeFontCursor(px+0.1F,posy+0.1F,pz+0.1F) ;
simpleBitmapOutput(REGULAR8x13,"P") ;
setAlignement(LEFT);
glPopMatrix();
glPushMatrix();
if ( posy > f.pb[1] ) {
placeFontCursor(-1.4F,-0.82F,0.1F) ;
simpleBitmapOutput(REGULAR8x13,"C1 = Ca+h1(Cb-Ca)") ; }
else {
placeFontCursor(-1.4F,-0.82F,0.1F) ;
simpleBitmapOutput(REGULAR8x13,"C1 = Cb+h1(Cc-Cb)") ; }
placeFontCursor(-1.4F,-0.95F,0.1F) ;
simpleBitmapOutput(REGULAR8x13,"C2 = Ca+h2(Cc-Ca)") ;
placeFontCursor(0.4F,-0.95F,0.1F) ;
simpleBitmapOutput(REGULAR8x13,"C = C1+h(C2-C1)") ;
glPopMatrix();
glFlush();
glutSwapBuffers();
glutPostWindowRedisplay(f2) ;
}
void special(int k,int x,int y) {
if ( specialManipulateur(k,x,y) ) {
glutPostWindowRedisplay(f1); }
}
void key2(unsigned char key,int x,int y) {
switch ( key ) {
case '4' : posx -= 0.01F;
if ( posx < 0.0F )
posx = 0.0F;
evaluationIntersections();
glutPostWindowRedisplay(f1) ;
break ;
case '6' : posx += 0.01F;
if ( posx > 1.0F )
posx = 1.0F;
evaluationIntersections();
glutPostWindowRedisplay(f1) ;
break ;
case 43 : posy += 0.01F;
if ( posy > f.pa[1] )
posy = f.pa[1];
evaluationIntersections();
glutPostWindowRedisplay(f1) ;
break ;
case 45 : posy -= 0.01F;
if ( posy < f.pc[1] )
posy = f.pc[1];
evaluationIntersections();
glutPostWindowRedisplay(f1) ;
break ;
case 0x1B : exit(0);
break ; }
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostWindowRedisplay(f1);
else
key2(key,x,y);
}
void reshape2(int w,int h) {
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,-h,0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display2() {
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glClearColor(0.0F,0.0F,0.0F,1.0F) ;
glPushAttrib(GL_LIGHTING);
glDisable(GL_LIGHTING);
glPushMatrix();
glColor4fv(couleurBlanc());
float pos = 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"PA : %6.3f %6.3f %6.3f",f.pa[0],f.pa[1],f.pa[2]) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"PB : %6.3f %6.3f %6.3f",f.pb[0],f.pb[1],f.pb[2]) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"PC : %6.3f %6.3f %6.3f",f.pc[0],f.pc[1],f.pc[2]) ;
pos += 1.0F;
glColor4fv(f.ca);
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"CA : %6d %6d %6d",(int) (f.ca[0]*255),(int) (f.ca[1]*255),(int) (f.ca[2]*255)) ;
pos += 1.0F;
glColor4fv(f.cb);
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"CB : %6d %6d %6d",(int) (f.cb[0]*255),(int) (f.cb[1]*255),(int) (f.cb[2]*255)) ;
pos += 1.0F;
glColor4fv(f.cc);
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"CC : %6d %6d %6d",(int) (f.cc[0]*255),(int) (f.cc[1]*255),(int) (f.cc[2]*255)) ;
glColor4fv(couleurBlanc());
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"h1 : %6.3f",h1) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"P1 : %6.3f %6.3f %6.3f",px1,posy,pz1) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"h2 : %6.3f",h2) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"P2 : %6.3f %6.3f %6.3f",px2,posy,pz2) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"h : %6.3f",posx) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"P : %6.3f %6.3f %6.3f",px,posy,pz) ;
pos += 1.0F;
glColor3f(cr1/255.0F,cv1/255.0F,cb1/255.0F);
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"C1 : %6d %6d %6d",cr1,cv1,cb1) ;
pos += 1.0F;
glColor3f(cr2/255.0F,cv2/255.0F,cb2/255.0F);
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"C2 : %6d %6d %6d",cr2,cv2,cb2) ;
pos += 1.0F;
glColor3f(cr/255.0F,cv/255.0F,cb/255.0F);
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(REGULAR8x13,"C : %6d %6d %6d",cr,cv,cb) ;
glPopMatrix();
glPopAttrib();
glutSwapBuffers();
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
evaluationIntersections();
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(450,300);
glutInitWindowPosition(10,50);
f1 = glutCreateWindow("Schema Gouraud");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-1.0,1.0,-1.0,1.0,-5.0,5.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(special);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutInitWindowSize(260,310);
glutInitWindowPosition(480,45);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
f2 = glutCreateWindow("Valeurs");
creationMenuBasique();
glutDisplayFunc(display2);
glutReshapeFunc(reshape2);
glutKeyboardFunc(key2);
glutSpecialFunc(special);
glutMainLoop();
return(0);
}