/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Mars 2004 */ /* Calculs mathematiques */ /* sur les vecteurs et les facettes */ #include #include #include #include #include #include #include #include "TD-MathematiquesElementaires.h" #include "ModuleCouleurs.h" #include "ModuleManipulateur.h" #include "ModuleAxes.h" #include "ModuleFleche.h" #include "ModuleMenus.h" #include "ModuleReshape.h" #include "ModuleFont.h" static int question = 0; static int f1 ; static int f2 ; static direction *v1; static direction *v2; static facetteTriangulaire *ft; static facettePolygonale *fp; static direction v11 = { 1.9F,0.0F,0.0F,0.0F }; static direction v21 = { 0.0F,1.8F,0.0F,0.0F }; static direction v12 = { 1.5F,1.0F,1.0F,0.0F }; static direction v22 = { -1.0F,-1.2F,-1.8F,0.0F }; static position p1 = { -1.3F,1.6F,-1.5F,1.0F }; static position p2 = { 1.7F,-1.2F, 1.8F,1.0F }; static direction v; static direction n; static direction pv; static facetteTriangulaire f = { { -1.5F,-1.3F,-0.6F,1.0F }, { 3.0F,-0.2F,3.1F,0.0F }, { 2.4F,2.8F,0.3F,0.0F } }; static facetteTriangulaire fc1 = { { -1.8F,-0.6F,1.1F,1.0F }, { 3.0F,-0.2F,3.1F,0.0F }, { 2.4F,2.8F,0.3F,0.0F } }; static facetteTriangulaire fc2 = { { -1.8F,-0.6F,1.1F,1.0F }, { 3.0F,-0.2F,3.1F,0.0F }, { 2.1F,2.3F,1.8F,0.0F } }; struct direction dir1[6] = { { -0.2F,2.1F,1.18F }, { 1.8F,3.1F,2.58F }, { 3.5F,2.7F,3.02F }, { 3.8F,1.7F,2.54F }, { 3.4F,0.3F,1.54F }, { 1.8F,-0.4F,0.48F} }; struct direction dir2[6] = { { -0.2F,2.1F,1.2F }, { 1.8F,3.1F,-1.0F }, { 3.5F,2.7F,2.2F }, { 3.8F,1.7F,-1.1F }, { 3.4F,0.3F,1.2F }, { 1.8F,-0.4F,-0.3F} }; struct direction dir3[6] = { { -0.2F,2.1F,1.2F }, { 1.6F,3.4F,2.52F }, { 2.3F,1.9F,1.83F }, { 3.8F,2.1F,2.4F }, { 3.4F,0.3F,1.2F }, { 1.8F,-0.4F,0.3F} }; struct facettePolygonale fp1 = { { -1.6F,-1.4F,-1.0F },dir1,7 }; struct facettePolygonale fp2 = { { -1.6F,-1.4F,-1.0F },dir2,7 }; struct facettePolygonale fp3 = { { -1.6F,-1.4F,-1.0F },dir3,7 }; void calculDirection(position *p1,position *p2,direction *d) { d->dx = p2->x - p1->x; d->dy = p2->y - p1->y; d->dz = p2->z - p1->z; d->dw = 0.0F; } float norme(direction *d) { return(pow(pow((double) d->dx,2)+pow((double) d->dy,2)+pow((double) d->dz,2),0.5)); } void normalise(direction *d) { float n = norme(d); if ( n != 0 ) { d->dx /= n; d->dy /= n; d->dz /= n; } } float produitScalaire(direction *d1,direction *d2) { return(d1->dx*d2->dx+d1->dy*d2->dy+d1->dz*d2->dz); } void produitVectoriel(direction *d1,direction *d2,direction *d) { d->dx = d1->dy*d2->dz-d1->dz*d2->dy; d->dy = d1->dz*d2->dx-d1->dx*d2->dz; d->dz = d1->dx*d2->dy-d1->dy*d2->dx; d->dw = 0.0F; } void normale(facetteTriangulaire *f,direction *d) { produitVectoriel(&f->d1,&f->d2,d); normalise(d); } int testParallelisme(facetteTriangulaire *f1,facetteTriangulaire *f2) { direction n; produitVectoriel(&f1->d1,&f1->d2,&n); float ps1 = produitScalaire(&f2->d1,&n); if ( fabs(ps1) > 0.000001F ) return(0); float ps2 = produitScalaire(&f2->d2,&n); if ( fabs(ps2) > 0.000001F ) return(0); return(1); } int testColinearite(direction *d1,direction *d2) { direction pv; produitVectoriel(d1,d2,&pv); if ( fabs(pv.dx) > 0.000001F ) return(0); if ( fabs(pv.dy) > 0.000001F ) return(0); if ( fabs(pv.dz) > 0.000001F ) return(0); return(1); } int testPlanarite(facettePolygonale *fp) { int i = 1; while ( testColinearite(&fp->d[0],&fp->d[i]) ) i++; direction pv; produitVectoriel(&fp->d[0],&fp->d[i],&pv); int j = 1; while ( j < fp->nbs-1 ) { if ( i != j ) if ( fabs(produitScalaire(&pv,&fp->d[j])) > 0.000001F ) return(0); j++; } return(1); } int testVecteurNul(direction *d) { if ( fabs(d->dx) > 0.000001F ) return(0); if ( fabs(d->dy) > 0.000001F ) return(0); if ( fabs(d->dz) > 0.000001F ) return(0); return(1); } int testConvexite(facettePolygonale *fp) { direction *d =(direction *) calloc(fp->nbs,sizeof(direction)); d[0] = fp->d[0]; int i; for ( i = 1 ; i < fp->nbs-1 ; i++ ) { d[i].dx = fp->d[i].dx-fp->d[i-1].dx; d[i].dy = fp->d[i].dy-fp->d[i-1].dy; d[i].dz = fp->d[i].dz-fp->d[i-1].dz; } d[fp->nbs-1].dx = -fp->d[fp->nbs-2].dx; d[fp->nbs-1].dy = -fp->d[fp->nbs-2].dy; d[fp->nbs-1].dz = -fp->d[fp->nbs-2].dz; i = 0 ; direction pv; produitVectoriel(&d[0],&d[1],&pv); while ( testVecteurNul(&pv) ) { i++; produitVectoriel(&d[i],&d[(i+1)%fp->nbs],&pv); } for ( ; i < fp->nbs ; i++ ) { direction pv2; produitVectoriel(&d[i],&d[(i+1)%fp->nbs],&pv2); if ( produitScalaire(&pv,&pv2) < -0.000001F ) { free(d); return(0); } } free(d); return(1); } void dessinPoint(position *p) { glPushMatrix(); glTranslatef(p->x,p->y,p->z); glutSolidSphere(0.1,36,36); glPopMatrix(); } void display1() { glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glPushMatrix(); glTranslatef(p1.x,p1.y,p1.z); calculDirection(&p1,&p2,&v); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurVert()); flecheEnVolume(v.dx,v.dy,v.dz,0.1F,0.5F,0.025F); calculDirection(&p1,&p2,&n); normalise(&n); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge()); flecheEnVolume(n.dx,n.dy,n.dz,0.1F,0.5F,0.04F); glPopMatrix(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurJaune()); dessinPoint(&p1); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBleu()); dessinPoint(&p2); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); } void scene2() { glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurVert()); flecheEnVolume(v1->dx,v1->dy,v1->dz,0.1F,0.5F,0.025F); glPopMatrix(); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge()); flecheEnVolume(v2->dx,v2->dy,v2->dz,0.1F,0.5F,0.025F); glPopMatrix(); produitVectoriel(v1,v2,&pv); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurJaune()); flecheEnVolume(pv.dx,pv.dy,pv.dz,0.1F,0.5F,0.025F); glPopMatrix(); } void display2() { v1 = &v11; v2 = &v21; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); scene2(); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); } void display3() { v1 = &v12; v2 = &v22; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); scene2(); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); } void display4() { glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBleu()); dessinPoint(&f.p); glPushMatrix(); glTranslatef(f.p.x,f.p.y,f.p.z); flecheEnVolume(f.d1.dx,f.d1.dy,f.d1.dz,0.1F,0.5F,0.025F); flecheEnVolume(f.d2.dx,f.d2.dy,f.d2.dz,0.1F,0.5F,0.025F); glPopMatrix(); normale(&f,&n); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBlanc()); glPushMatrix(); glTranslatef(f.p.x+(f.d1.dx+f.d2.dx)/3.0F,f.p.y+(f.d1.dy+f.d2.dy)/3.0F,f.p.z+(f.d1.dz+f.d2.dz)/3.0F); flecheEnVolume(n.dx,n.dy,n.dz,0.1F,0.5F,0.025F); glPopMatrix(); glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge(0.5F)); glMaterialfv(GL_BACK,GL_DIFFUSE,couleurVert(0.5F)); glBegin(GL_POLYGON); glNormal3f(n.dx,n.dy,n.dz); glVertex3fv((float *) &f.p); glVertex3f(f.p.x+f.d1.dx,f.p.y+f.d1.dy,f.p.z+f.d1.dz); glVertex3f(f.p.x+f.d2.dx,f.p.y+f.d2.dy,f.p.z+f.d2.dz); glEnd(); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); } void dessineFacette(facetteTriangulaire *fc) { dessinPoint(&fc->p); glPushMatrix(); glTranslatef(fc->p.x,fc->p.y,fc->p.z); flecheEnVolume(fc->d1.dx,fc->d1.dy,fc->d1.dz,0.1F,0.5F,0.025F); flecheEnVolume(fc->d2.dx,fc->d2.dy,fc->d2.dz,0.1F,0.5F,0.025F); glPopMatrix(); direction n; normale(fc,&n); glBegin(GL_POLYGON); glNormal3f(n.dx,n.dy,n.dz); glVertex3fv((float *) &fc->p); glVertex3f(fc->p.x+fc->d1.dx,fc->p.y+fc->d1.dy,fc->p.z+fc->d1.dz); glVertex3f(fc->p.x+fc->d2.dx,fc->p.y+fc->d2.dy,fc->p.z+fc->d2.dz); glEnd(); } void scene5(void) { glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge(0.5F)); dessineFacette(&f); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBleu(0.5F)); dessineFacette(ft); } void display5() { ft = &fc1; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); scene5(); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); } void display6() { ft = &fc2; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); scene5(); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); } void dessineFacette(facettePolygonale *fp) { dessinPoint(&fp->p); glPushMatrix(); glTranslatef(fp->p.x,fp->p.y,fp->p.z); int i; for ( i = 0 ; i < fp->nbs-1 ; i++ ) dessinPoint((position *) &fp->d[i]); glBegin(GL_POLYGON); glVertex3f(0.0F,0.0F,0.0F); for ( i = 0 ; i < fp->nbs-1 ; i++ ) glVertex3f(fp->d[i].dx, fp->d[i].dy, fp->d[i].dz); glEnd(); glPopMatrix(); } void display7() { fp = &fp1; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurVert(0.5F)); dessineFacette(&fp1); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); } void display8() { fp = &fp2; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurVert(0.5F)); dessineFacette(&fp2); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); } void display9() { fp = &fp1; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurCyan(0.5F)); dessineFacette(&fp1); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); } void display10() { fp = &fp3; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurCyan(0.5F)); dessineFacette(&fp3); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); } void displayV1(void) { glClearColor(0.0F,0.0F,0.0F,1.0F) ; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); float pos = 1.0F; glColor4fv(couleurJaune()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"P1 : %8.4f %8.4f %8.4f",p1.x,p1.y,p1.z); pos += 1.0F; glColor4fv(couleurBleu()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"P2 : %8.4f %8.4f %8.4f",p2.x,p2.y,p2.z); pos += 1.0F; glColor4fv(couleurVert()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"V : %8.4f %8.4f %8.4f",v.dx,v.dy,v.dz); pos += 1.0F; glColor4fv(couleurBlanc()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"NORME : %8.4f",norme(&v)); pos += 1.0F; glColor4fv(couleurRouge()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"N : %8.4f %8.4f %8.4f",n.dx,n.dy,n.dz); glPopMatrix(); glFlush(); glutSwapBuffers(); } void displayV2(void) { glClearColor(0.0F,0.0F,0.0F,1.0F) ; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); float pos = 1.0F; glColor4fv(couleurVert()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"V1 : %8.4f %8.4f %8.4f",v1->dx,v1->dy,v1->dz); pos += 1.0F; glColor4fv(couleurRouge()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"V2 : %8.4f %8.4f %8.4f",v2->dx,v2->dy,v2->dz); pos += 1.0F; glColor4fv(couleurBlanc()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"V1.V2 : %8.4f",produitScalaire(v1,v2)); pos += 1.0F; glColor4fv(couleurJaune()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"V1^V2 : %8.4f %8.4f %8.4f",pv.dx,pv.dy,pv.dz); glPopMatrix(); glFlush(); glutSwapBuffers(); } void displayV4(void) { glClearColor(0.0F,0.0F,0.0F,1.0F) ; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); float pos = 1.0F; glColor4fv(couleurBleu()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"P : %8.4f %8.4f %8.4f",f.p.x,f.p.y,f.p.z); pos += 1.0F; glColor4fv(couleurRouge()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"D1 : %8.4f %8.4f %8.4f",f.d1.dx,f.d1.dy,f.d1.dz); pos += 1.0F; glColor4fv(couleurRouge()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"D2 : %8.4f %8.4f %8.4f",f.d2.dx,f.d2.dy,f.d2.dz); pos += 1.0F; glColor4fv(couleurBlanc()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"N : %8.4f %8.4f %8.4f",n.dx,n.dy,n.dz); glPopMatrix(); glFlush(); glutSwapBuffers(); } void displayV5(void) { glClearColor(0.0F,0.0F,0.0F,1.0F) ; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); float pos = 1.0F; glColor4fv(couleurRouge()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"F1 P : %8.4f %8.4f %8.4f",f.p.x,f.p.y,f.p.z); pos += 1.0F; placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"F1 D1 : %8.4f %8.4f %8.4f",f.d1.dx,f.d1.dy,f.d1.dz); pos += 1.0F; placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"F1 D2 : %8.4f %8.4f %8.4f",f.d2.dx,f.d2.dy,f.d2.dz); pos += 1.0F; glColor4fv(couleurBleu()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"F2 P : %8.4f %8.4f %8.4f",ft->p.x,ft->p.y,ft->p.z); pos += 1.0F; placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"F2 D1 : %8.4f %8.4f %8.4f",ft->d1.dx,ft->d1.dy,ft->d1.dz); pos += 1.0F; placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"F2 D2 : %8.4f %8.4f %8.4f",ft->d2.dx,ft->d2.dy,ft->d2.dz); pos += 1.0F; glColor4fv(couleurBlanc()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; if ( testParallelisme(&f,ft) ) simpleBitmapOutput(1,REGULAR8x13,"FACETTES PARALLELES"); else simpleBitmapOutput(1,REGULAR8x13,"FACETTES NON PARALLELES"); glPopMatrix(); glFlush(); glutSwapBuffers(); } void displayV7(void) { glClearColor(0.0F,0.0F,0.0F,1.0F) ; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); float pos = 1.0F; glColor4fv(couleurJaune()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"P : %8.4f %8.4f %8.4f",fp->p.x,fp->p.y,fp->p.z); glColor4fv(couleurVert()); pos += 1.0F; for ( int i = 0 ; i < fp->nbs-1 ; i++ ) { placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"D[%d] : %8.4f %8.4f %8.4f",i,fp->d[i].dx,fp->d[i].dy,fp->d[i].dz); pos += 1.0F; } glColor4fv(couleurBlanc()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; if ( testPlanarite(fp) ) simpleBitmapOutput(1,REGULAR8x13,"FACETTE PLANAIRE"); else simpleBitmapOutput(1,REGULAR8x13,"FACETTE NON PLANAIRE"); glPopMatrix(); glFlush(); glutSwapBuffers(); } void displayV9(void) { glClearColor(0.0F,0.0F,0.0F,1.0F) ; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); float pos = 1.0F; glColor4fv(couleurJaune()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"P : %8.4f %8.4f %8.4f",fp->p.x,fp->p.y,fp->p.z); glColor4fv(couleurCyan()); pos += 1.0F; for ( int i = 0 ; i < fp->nbs-1 ; i++ ) { placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"D[%d] : %8.4f %8.4f %8.4f",i,fp->d[i].dx,fp->d[i].dy,fp->d[i].dz); pos += 1.0F; } glColor4fv(couleurBlanc()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; if ( testConvexite(fp) ) simpleBitmapOutput(1,REGULAR8x13,"FACETTE CONVEXE"); else simpleBitmapOutput(1,REGULAR8x13,"FACETTE CONCAVE"); glPopMatrix(); glFlush(); glutSwapBuffers(); } void key(unsigned char k,int x,int y) { switch ( k ) { case 0x0D : { question = (question+1)%10; int win = glutGetWindow(); switch ( question ) { case 0 : glutSetWindow(f1); glutDisplayFunc(display1); glutSetWindow(f2); glutReshapeWindow(370,110); glutDisplayFunc(displayV1); break; case 1 : glutSetWindow(f1); glutDisplayFunc(display2); glutSetWindow(f2); glutReshapeWindow(370,90); glutDisplayFunc(displayV2); break; case 2 : glutSetWindow(f1); glutDisplayFunc(display3); glutSetWindow(f2); glutReshapeWindow(370,90); glutDisplayFunc(displayV2); break; case 3 : glutSetWindow(f1); glutDisplayFunc(display4); glutSetWindow(f2); glutReshapeWindow(370,90); glutDisplayFunc(displayV4); break; case 4 : glutSetWindow(f1); glutDisplayFunc(display5); glutSetWindow(f2); glutReshapeWindow(370,150); glutDisplayFunc(displayV5); break; case 5 : glutSetWindow(f1); glutDisplayFunc(display6); glutSetWindow(f2); glutReshapeWindow(370,150); glutDisplayFunc(displayV5); break; case 6 : glutSetWindow(f1); glutDisplayFunc(display7); glutSetWindow(f2); glutReshapeWindow(370,170); glutDisplayFunc(displayV7); break; case 7 : glutSetWindow(f1); glutDisplayFunc(display8); glutSetWindow(f2); glutReshapeWindow(370,170); glutDisplayFunc(displayV7); break; case 8 : glutSetWindow(f1); glutDisplayFunc(display9); glutSetWindow(f2); glutReshapeWindow(370,170); glutDisplayFunc(displayV9); break; case 9 : glutSetWindow(f1); glutDisplayFunc(display10); glutSetWindow(f2); glutReshapeWindow(370,170); glutDisplayFunc(displayV9); break; } glutSetWindow(win); glutPostWindowRedisplay(f1); } break; case '\033' : exit(0); break ; } } void special(int key,int x,int y) { if ( specialManipulateur(key,x,y) ) glutPostRedisplay(); else switch (key) { case GLUT_KEY_F1 : glutPostWindowRedisplay(f1); break; } } void myInit() { glEnable(GL_AUTO_NORMAL); glEnable(GL_NORMALIZE); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHT0); glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1); glShadeModel(GL_SMOOTH); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); glClearColor(0.5F,0.5F,0.5F,1.0F); } void reshapeV(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(); } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitWindowSize(250,250); glutInitWindowPosition(50,50); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); f1 = glutCreateWindow("Mathematiques elementaires"); myInit(); creationMenuBasique(); setParametresOrthoBasique(-2.5,2.5,-2.5,2.5,-50.0,50.0); setManipulateurDistance(1.0F); setManipulateurSourisAngle(10.0F,-20.0F,0.0F); glutReshapeFunc(reshapeOrthoBasique); glutMotionFunc(motionBasique); glutMouseFunc(sourisBasique); glutKeyboardFunc(key); glutDisplayFunc(display1); glutSpecialFunc(special); glutInitWindowSize(370,110); glutInitWindowPosition(60,360); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); f2 = glutCreateWindow("Valeurs"); creationMenuBasique(); glutDisplayFunc(displayV1); glutReshapeFunc(reshapeV); glutKeyboardFunc(key); glutSpecialFunc(special); glutMainLoop(); return(0); }