/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Novembre 2001 */
/* Utilisation des quadriques */
/* de la librairie Glu */
#include <stdio.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleManipulateur.h"
#include "ModuleCouleurs.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
#include "ModuleFont.h"
static int aff = 0 ;
static int disc = 20 ;
static int fillMode = 3;
static int normalMode = 2;
static double ir = 2.0;
static double er = 6.0;
static double h = 5.0;
void myinit(void) {
GLfloat light_position0[] = { 0.5F,0.5F,1.0F,0.0F };
glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir());
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc());
glLightfv(GL_LIGHT0,GL_SPECULAR,couleurBlanc());
glLightfv(GL_LIGHT0,GL_POSITION,light_position0);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHTING);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
setAlignement(CENTER);
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glPushMatrix() ;
manipulateurSouris();
manipulateurClavier();
glRotatef(-10.0F,1.0,0.0,0.0);
glRotatef(-15.0F,0.0,1.0,0.0);
GLUquadricObj *qobj;
qobj = gluNewQuadric();
switch (fillMode) {
case 0 : gluQuadricDrawStyle(qobj,GLU_POINT);
break;
case 1 : gluQuadricDrawStyle(qobj,GLU_LINE);
break;
case 2 : gluQuadricDrawStyle(qobj,GLU_SILHOUETTE);
break;
case 3 : gluQuadricDrawStyle(qobj,GLU_FILL);
break; }
switch (normalMode) {
case 0 : gluQuadricNormals(qobj,GLU_NONE);
break;
case 1 : gluQuadricNormals(qobj,GLU_FLAT);
break;
case 2 : gluQuadricNormals(qobj,GLU_SMOOTH);
break; }
switch (aff) {
case 0 : gluSphere(qobj,er,disc,disc);
break;
case 1 : gluCylinder(qobj,er,ir,h,disc,disc);
break;
case 2 : gluDisk(qobj,ir,er,disc,disc);
break;
case 3 : gluPartialDisk(qobj,ir,er,disc,disc,30.0,220.0);
break; }
gluDeleteQuadric(qobj);
glPopMatrix() ;
glColor4fv(couleurRouge());
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
glPushMatrix() ;
placeFontCursor(0.0F,-8.0F,0.0F) ;
switch (aff) {
case 0 : simpleBitmapOutput(REGULAR8x13,"SPHERE") ;
break;
case 1 : simpleBitmapOutput(REGULAR8x13,"CYLINDRE - CONE") ;
break;
case 2 : simpleBitmapOutput(REGULAR8x13,"DISQUE TROUE") ;
break;
case 3 : simpleBitmapOutput(REGULAR8x13,"DISQUE TROUE PARTIEL") ;
break; }
glPopMatrix() ;
glFlush();
glutSwapBuffers() ;
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 'e' : er += 0.1;
glutPostRedisplay();
break ;
case 'E' : er -= 0.1;
if ( er < 0.1 )
er = 0.1;
glutPostRedisplay();
break ;
case 'i' : ir += 0.1;
glutPostRedisplay();
break ;
case 'I' : ir -= 0.1;
if ( ir < 0.1 )
ir = 0.1;
glutPostRedisplay();
break ;
case 'h' : h += 0.1;
glutPostRedisplay();
break ;
case 'H' : h -= 0.1;
if ( h < 0.1 )
h = 0.1;
glutPostRedisplay();
break ;
case 43 : disc++;
glutPostRedisplay();
break ;
case 45 : disc--;
if ( disc < 3 )
disc = 3;
glutPostRedisplay();
break ;
case 0x0D : aff = (aff+1)%4 ;
glutPostRedisplay();
break ;
case ' ' : fillMode = (fillMode+1)%4 ;
glutPostRedisplay();
break ;
case 'n' :
case 'N' : normalMode = (normalMode+1)%3 ;
glutPostRedisplay();
break ; }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(250,200);
glutInitWindowPosition(50,50);
glutCreateWindow("Quadriques par la librairie GLU");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-10.0,10.0,-10.0,10.0,-500.0,500.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}