Le source : TD-Bezier-GL-Cercle.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Avril 2001 */
/* Programmation du calcul */
/* d'une courbe de Bezier */
/* pour dessiner un cercle! */
#include <math.h>
#include <stdio.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleCouleurs.h"
#include "ModuleFont.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
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) ;
glColor4fv(couleurMagenta());
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);
glColor4fv(couleurCyan());
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 display(void) {
glClear(GL_COLOR_BUFFER_BIT|
GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glEnable(GL_DEPTH_TEST);
manipulateurSouris();
manipulateurClavier();
traceCercle(6.0F) ;
traceCercleBezierGL(6.0F) ;
glPopMatrix();
glPushMatrix();
glDisable(GL_DEPTH_TEST);
glColor4fv(couleurJaune());
placeFontCursor(-6.5F,-6.5F,0.0F);
simpleBitmapOutput("p = %5.2f",p);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void myinit(void) {
glClearColor(0.0,0.0,0.0,1.0);
glShadeModel(GL_FLAT);
glDepthFunc(GL_LESS);
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 43 : p += 0.01F ;
pts1[1][1] = p ;
pts1[2][0] = p ;
glutPostRedisplay();
break;
case 45 : p -= 0.01F ;
pts1[1][1] = p ;
pts1[2][0] = p ;
glutPostRedisplay();
break; }
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowSize(300,300);
glutInitWindowPosition(50,50);
glutCreateWindow("Courbe de Bezier");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-7.0,7.0,-7.0,7.0,-500.0,500.0);
setManipulateurDistance(1.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}