/* Auteur: Nicolas JANEY */ /* Avril 2001 */ /* Programmation du calcul */ /* d'une courbe de Bezier */ /* pour dessiner un cercle! */ #include #include #include #include #include #include #include "modulefont.h" static GLfloat view_rotx=0.0F ; static GLfloat view_roty=0.0F ; static GLfloat view_rotz=0.0F ; static int n = 100 ; float p = 0.55F ; float pts1[4][3] = { {1.0F,0.0F,0.0F}, {1.0F,p,0.0F}, {p,1.0F,0.0F}, {0.0F,1.0F,0.0F} } ; void traceCercle(float r) { glPushMatrix() ; glScalef(r,r,r) ; glColor3f(1.0,0.0,1.0); glBegin(GL_LINE_LOOP) ; for ( int i = 0 ; i < 360 ; i++ ) { float x =(float) cos(i*3.1459/180) ; float y =(float) sin(i*3.1459/180) ; glVertex2f(x,y) ; } glEnd() ; glPopMatrix() ; } void traceQuartCercleBezierGL(float r) { glPushMatrix() ; glScalef(r,r,r) ; glMap1f(GL_MAP1_VERTEX_3, 0.0,1.0,3,4,&pts1[0][0]); glEnable(GL_MAP1_VERTEX_3); glColor3f(0.0,1.0,1.0); glBegin(GL_POINTS); for ( int i = 0 ; i <= n ; i++ ) glEvalCoord1f((GLfloat) i/100.0F); glEnd(); glPopMatrix() ; } void traceCercleBezierGL(float r) { glPushMatrix() ; traceQuartCercleBezierGL(r) ; glRotatef(90.0F,0.0F,0.0F,1.0F) ; traceQuartCercleBezierGL(r) ; glRotatef(90.0F,0.0F,0.0F,1.0F) ; traceQuartCercleBezierGL(r) ; glRotatef(90.0F,0.0F,0.0F,1.0F) ; traceQuartCercleBezierGL(r) ; glPopMatrix() ; } void CALLBACK display(void) { glClear(GL_COLOR_BUFFER_BIT| GL_DEPTH_BUFFER_BIT); glPushMatrix(); glEnable(GL_DEPTH_TEST); glRotatef(view_rotx,1.0,0.0,0.0); glRotatef(view_roty,0.0,1.0,0.0); glRotatef(view_rotz,0.0,0.0,1.0); traceCercle(6.0F) ; traceCercleBezierGL(6.0F) ; glPopMatrix(); glPushMatrix(); glDisable(GL_DEPTH_TEST); glColor3f(1.0,1.0,0.0); glRasterPos2f(-6.5,-6.5); char st[50] ; sprintf(st,"p = %5.2f",p); printString(st); glPopMatrix(); glFlush(); auxSwapBuffers(); } void CALLBACK myReshape(int w,int h) { glViewport(0,0,w,h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if( w <= h ) { float y = 7.F*(float)h/(float)w ; glOrtho(-7.,7.,-y,y,-7.,7.); } else { float x = 7.F*(float)w/(float)h ; glOrtho(-x,x,-7.,7.,-7.,7.); } glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void myinit(void) { makeRasterFont(); glClearColor(0.0,0.0,0.0,1.0); glShadeModel(GL_FLAT); glDepthFunc(GL_LESS); } void CALLBACK keyRight(void) { p += 0.01F ; pts1[1][1] = p ; pts1[2][0] = p ; } void CALLBACK keyLeft(void) { p -= 0.01F ; pts1[1][1] = p ; pts1[2][0] = p ; } void CALLBACK keyx(void) { view_rotx += 2 ; } void CALLBACK keyX(void) { view_rotx -= 2 ; } void CALLBACK keyy(void) { view_roty += 2 ; } void CALLBACK keyY(void) { view_roty -= 2 ; } void CALLBACK keyz(void) { view_rotz += 2 ; } void CALLBACK keyZ(void) { view_rotz -= 2 ; } void main(void) { auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA|AUX_DEPTH); auxInitPosition(0,0,300,300); auxInitWindow("Courbe de Bezier"); myinit(); auxKeyFunc(AUX_x,keyx) ; auxKeyFunc(AUX_X,keyX) ; auxKeyFunc(AUX_y,keyy) ; auxKeyFunc(AUX_Y,keyY) ; auxKeyFunc(AUX_z,keyz) ; auxKeyFunc(AUX_Z,keyZ) ; auxKeyFunc(AUX_RIGHT,keyRight) ; auxKeyFunc(AUX_LEFT,keyLeft) ; auxReshapeFunc(myReshape); auxMainLoop(display); }