/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Octobre 2005 */ /* Calculs mathematiques */ /* sur les vecteurs et les facettes */ #include #include #include #include #include #include #include "Position.h" #include "Direction.h" #include "Triangle.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 Triangle *t; static Direction *v11 = new Direction(1.9F,0.0F,0.0F); static Direction *v21 = new Direction(0.0F,1.8F,0.0F); static Direction *v12 = new Direction(1.5F,1.0F,1.0F); static Direction *v22 = new Direction(-1.0F,-1.2F,-1.8F); static Position *p1 = new Position(-1.3F,1.6F,-1.5F); static Position *p2 = new Position(1.7F,-1.2F, 1.8F); static Direction *v = new Direction(); static Direction *n = new Direction(); static Direction *pv = new Direction(); static Triangle *f = new Triangle(new Position(-1.5F,-1.3F,-0.6F), new Direction(3.0F,-0.2F,3.1F), new Direction(2.4F,2.8F,0.3F)); static Triangle *t1 = new Triangle(new Position(-1.8F,-0.6F,1.1F), new Direction(3.0F,-0.2F,3.1F), new Direction(2.4F,2.8F,0.3F)); static Triangle *t2 = new Triangle(new Position(-1.8F,-0.6F,1.1F), new Direction(3.0F,-0.2F,3.1F), new Direction(2.1F,2.3F,1.8F)); void scene1(void) { glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glPushMatrix(); glTranslatef(p1->x,p1->y,p1->z); v = new Direction(p1,p2); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurVert()); flecheEnVolume(v->x,v->y,v->z,0.1F,0.5F,0.025F); n = new Direction(p1,p2); n->normalise(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge()); flecheEnVolume(n->x,n->y,n->z,0.1F,0.5F,0.04F); glPopMatrix(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurJaune()); p1->dessine(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBleu()); p2->dessine(); } void display1() { glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); scene1(); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); int error = glGetError(); if ( error != GL_NO_ERROR ) printf("Attention, erreur OpenGL %d\n",error); } void scene2() { glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurVert()); flecheEnVolume(v1->x,v1->y,v1->z,0.1F,0.5F,0.025F); glPopMatrix(); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge()); flecheEnVolume(v2->x,v2->y,v2->z,0.1F,0.5F,0.025F); glPopMatrix(); pv->produitVectoriel(v1,v2); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurJaune()); flecheEnVolume(pv->x,pv->y,pv->z,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); int error = glGetError(); if ( error != GL_NO_ERROR ) printf("Attention, erreur OpenGL %d\n",error); } void display3() { v1 = v12; v2 = v22; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); scene2(); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); int error = glGetError(); if ( error != GL_NO_ERROR ) printf("Attention, erreur OpenGL %d\n",error); } void scene4(void) { glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBleu()); f->p1->dessine(); glPushMatrix(); glTranslatef(f->p1->x,f->p1->y,f->p1->z); flecheEnVolume(f->d1->x,f->d1->y,f->d1->z,0.1F,0.5F,0.025F); flecheEnVolume(f->d2->x,f->d2->y,f->d2->z,0.1F,0.5F,0.025F); glPopMatrix(); n = f->normale(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBlanc()); glPushMatrix(); glTranslatef(f->p1->x+(f->d1->x+f->d2->x)/3.0F, f->p1->y+(f->d1->y+f->d2->y)/3.0F, f->p1->z+(f->d1->z+f->d2->z)/3.0F); flecheEnVolume(n->x,n->y,n->z,0.1F,0.5F,0.025F); glPopMatrix(); glPushMatrix(); glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge(0.5F)); glMaterialfv(GL_BACK,GL_DIFFUSE,couleurVert(0.5F)); glTranslatef(f->p1->x,f->p1->y,f->p1->z); glBegin(GL_POLYGON); glNormal3f(n->x,n->y,n->z); glVertex3f(0.0F,0.0F,0.0F); glVertex3f(f->d1->x,f->d1->y,f->d1->z); glVertex3f(f->d2->x,f->d2->y,f->d2->z); glEnd(); glPopMatrix(); } void display4() { glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); scene4(); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); int error = glGetError(); if ( error != GL_NO_ERROR ) printf("Attention, erreur OpenGL %d\n",error); } void scene5(void) { glDisable(GL_LIGHTING); axes(); glEnable(GL_LIGHTING); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge(0.5F)); f->dessine(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBleu(0.5F)); t->dessine(); } void display5() { t = t1; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); scene5(); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); int error = glGetError(); if ( error != GL_NO_ERROR ) printf("Attention, erreur OpenGL %d\n",error); } void display6() { t = t2; glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); scene5(); glPopMatrix(); glFlush(); glutSwapBuffers(); glutPostWindowRedisplay(f2); int error = glGetError(); if ( error != GL_NO_ERROR ) printf("Attention, erreur OpenGL %d\n",error); } 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) ; p1->print("P1 : %8.4f %8.4f %8.4f"); pos += 1.0F; glColor4fv(couleurBleu()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; p2->print("P2 : %8.4f %8.4f %8.4f"); pos += 1.0F; glColor4fv(couleurVert()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; v->print("V : %8.4f %8.4f %8.4f"); pos += 1.0F; glColor4fv(couleurBlanc()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"NORME : %8.4f",v->norme()); pos += 1.0F; glColor4fv(couleurRouge()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; n->print("N : %8.4f %8.4f %8.4f"); 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) ; v1->print("V1 : %8.4f %8.4f %8.4f"); pos += 1.0F; glColor4fv(couleurRouge()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; v2->print("V2 : %8.4f %8.4f %8.4f"); pos += 1.0F; glColor4fv(couleurBlanc()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; simpleBitmapOutput(1,REGULAR8x13,"V1.V2 : %8.4f",v1->produitScalaire(v2)); pos += 1.0F; glColor4fv(couleurJaune()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; pv->print("V1^V2 : %8.4f %8.4f %8.4f"); 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) ; f->p1->print("P : %8.4f %8.4f %8.4f"); pos += 1.0F; glColor4fv(couleurRouge()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; f->d1->print("D1 : %8.4f %8.4f %8.4f"); pos += 1.0F; glColor4fv(couleurRouge()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; f->d2->print("D2 : %8.4f %8.4f %8.4f"); pos += 1.0F; glColor4fv(couleurBlanc()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; n->print("N : %8.4f %8.4f %8.4f"); 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) ; f->p1->print("F1 P : %8.4f %8.4f %8.4f"); pos += 1.0F; placeFontCursor(5.0F,-pos*20.0F,0.0F) ; f->d1->print("F1 D1 : %8.4f %8.4f %8.4f"); pos += 1.0F; placeFontCursor(5.0F,-pos*20.0F,0.0F) ; f->d2->print("F1 D2 : %8.4f %8.4f %8.4f"); pos += 1.0F; glColor4fv(couleurBleu()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; t->p1->print("F2 P : %8.4f %8.4f %8.4f"); pos += 1.0F; placeFontCursor(5.0F,-pos*20.0F,0.0F) ; t->d1->print("F2 D1 : %8.4f %8.4f %8.4f"); pos += 1.0F; placeFontCursor(5.0F,-pos*20.0F,0.0F) ; t->d2->print("F2 D2 : %8.4f %8.4f %8.4f"); pos += 1.0F; glColor4fv(couleurBlanc()); placeFontCursor(5.0F,-pos*20.0F,0.0F) ; if ( f->estParallele(t) ) simpleBitmapOutput(1,REGULAR8x13,"FACETTES PARALLELES"); else simpleBitmapOutput(1,REGULAR8x13,"FACETTES NON PARALLELES"); glPopMatrix(); glFlush(); glutSwapBuffers(); } void special(int key,int x,int y) { if ( specialManipulateur(key,x,y) ) { glutPostWindowRedisplay(f1); } } void key(unsigned char k,int x,int y) { if ( keyManipulateur(k,x,y) ) glutPostWindowRedisplay(f1); else switch ( k ) { case 0x0D : { question = (question+1)%6; 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; } glutSetWindow(win); 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(270,270); glutInitWindowPosition(50,50); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); f1 = glutCreateWindow("Mathematiques de l'infographie"); 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); }