/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Fevrier 2002 */ /* Fonctions de dessin de cylindre */ #include #include #include #include #include #include #include "ModuleCouleurs.h" #include "ModuleManipulateur.h" #include "ModuleMenus.h" #include "ModuleReshape.h" void glutSolidCubeSansNormales(float x,float y,float z){ glPushMatrix(); glNormal3f(0.0F,0.0F,1.0F); glBegin(GL_QUADS); glVertex3f(x/2,y/2,-z/2); glVertex3f(x/2,-y/2,-z/2); glVertex3f(-x/2,-y/2,-z/2); glVertex3f(-x/2,y/2,-z/2); glVertex3f(x/2,y/2,z/2); glVertex3f(-x/2,y/2,z/2); glVertex3f(-x/2,-y/2,z/2); glVertex3f(x/2,-y/2,z/2); glVertex3f(-x/2,y/2,-z/2); glVertex3f(-x/2,-y/2,-z/2); glVertex3f(-x/2,-y/2,z/2); glVertex3f(-x/2,y/2,z/2); glVertex3f(x/2,y/2,z/2); glVertex3f(x/2,-y/2,z/2); glVertex3f(x/2,-y/2,-z/2); glVertex3f(x/2,y/2,-z/2); glVertex3f(-x/2,-y/2,z/2); glVertex3f(-x/2,-y/2,-z/2); glVertex3f(x/2,-y/2,-z/2); glVertex3f(x/2,-y/2,z/2); glVertex3f(x/2,y/2,z/2); glVertex3f(x/2,y/2,-z/2); glVertex3f(-x/2,y/2,-z/2); glVertex3f(-x/2,y/2,z/2); glEnd(); glPopMatrix(); } void glutSolidCubeAvecNormales(float x,float y,float z){ glPushMatrix(); glNormal3f(0.0F,0.0F,1.0F); glBegin(GL_QUADS); glNormal3f(0.0F,0.0F,-1.0F); glVertex3f(x/2,y/2,-z/2); glVertex3f(x/2,-y/2,-z/2); glVertex3f(-x/2,-y/2,-z/2); glVertex3f(-x/2,y/2,-z/2); glNormal3f(0.0F,0.0F,1.0F); glVertex3f(x/2,y/2,z/2); glVertex3f(-x/2,y/2,z/2); glVertex3f(-x/2,-y/2,z/2); glVertex3f(x/2,-y/2,z/2); glNormal3f(-1.0F,0.0F,0.0F); glVertex3f(-x/2,y/2,-z/2); glVertex3f(-x/2,-y/2,-z/2); glVertex3f(-x/2,-y/2,z/2); glVertex3f(-x/2,y/2,z/2); glNormal3f(1.0F,0.0F,0.0F); glVertex3f(x/2,y/2,z/2); glVertex3f(x/2,-y/2,z/2); glVertex3f(x/2,-y/2,-z/2); glVertex3f(x/2,y/2,-z/2); glNormal3f(0.0F,-1.0F,0.0F); glVertex3f(-x/2,-y/2,z/2); glVertex3f(-x/2,-y/2,-z/2); glVertex3f(x/2,-y/2,-z/2); glVertex3f(x/2,-y/2,z/2); glNormal3f(0.0F,1.0F,0.0F); glVertex3f(x/2,y/2,z/2); glVertex3f(x/2,y/2,-z/2); glVertex3f(-x/2,y/2,-z/2); glVertex3f(-x/2,y/2,z/2); glEnd(); glPopMatrix(); } void display(void) { glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBleu()) ; glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,couleurJaune()) ; glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,90) ; glTranslatef(0.0F,0.65F,0.0F) ; glNormal3f(0.0f,0.0f,1.0f); glutSolidCubeAvecNormales(0.7,0.8,1.2) ; glPopMatrix(); glPushMatrix(); glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge()) ; glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,couleurJaune()) ; glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,90) ; glTranslatef(0.0F,-0.65F,0.0F) ; glutSolidCubeSansNormales(0.7,0.8,1.2) ; glPopMatrix(); glPopMatrix(); glFlush(); glutSwapBuffers(); } void myinit (void) { glClearColor(0.5F,0.5F,0.5F,0.0F); glShadeModel(GL_SMOOTH); glEnable(GL_NORMALIZE); glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); float dir[4] = { 1.0F,1.0F,1.0F,0.0F }; glLightfv(GL_LIGHT0,GL_POSITION,dir) ; glLightfv(GL_LIGHT0,GL_SPECULAR,couleurJauneClair()) ; } int main(int argc,char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE); glutInitWindowSize(250,250); glutInitWindowPosition(50,50); glutCreateWindow("Cubes"); myinit(); creationMenuBasique(); setParametresOrthoBasique(-1.3F,1.3F,-1.3F,1.3F,-50.0,50.0); setManipulateurDistance(1.0F); glutReshapeFunc(reshapeOrthoBasique); glutKeyboardFunc(keyBasique); glutSpecialFunc(specialBasique); glutMotionFunc(motionBasique); glutMouseFunc(sourisBasique); glutDisplayFunc(display); glutMainLoop(); return(0); }