Fichier source : BrasRobotCylindres.cpp
Modules utilitaires
/* Scene dessinee avec des cylindres */
static void cylindre(double hauteur,double rayon,int ns,int nl) {
/* Protection contre la modification de la normale */
/* et du flag normalisation */
GLboolean nm = glIsEnabled(GL_NORMALIZE);
if ( !nm )
glEnable(GL_NORMALIZE);
float normale[4];
glGetFloatv(GL_CURRENT_NORMAL,normale);
/* Modelisation geometrique */
glPushMatrix();
for ( int j = 0 ; j < nl ; j++ ) {
float hi = hauteur/2-j*hauteur/nl;
float hf = hi-hauteur/nl;
glBegin(GL_QUAD_STRIP);
for( int i = 0 ; i <= ns ; i++ ) {
float a = (2*M_PI*i)/ns;
float cs = cos(a);
float sn = -sin(a);
glNormal3f(cs,0.0F,sn);
float x = rayon*cs;
float z = rayon*sn;
glVertex3f(x,hi,z);
glVertex3f(x,hf,z); }
glEnd(); }
glBegin(GL_POLYGON);
glNormal3f(0.0F,1.0F,0.0F);
for( int i = 0 ; i < ns ; i++ ) {
float a = (2*M_PI*i)/ns;
float cs = cos(a);
float sn = -sin(a);
float x = rayon*cs;
float z = rayon*sn;
glVertex3f(x,hauteur/2.0F,z); }
glEnd();
glBegin(GL_POLYGON);
glNormal3f(0.0F,-1.0F,0.0F);
for( int i = 0 ; i < ns ; i++ ) {
float a = (2*M_PI*i)/ns;
float cs = cos(a);
float sn = sin(a);
float x = rayon*cs;
float z = rayon*sn;
glVertex3f(x,-hauteur/2.0F,z); }
glEnd();
glPopMatrix();
/* Restoration de la normale et du flag normalisation */
glNormal3f(normale[0],normale[1],normale[2]);
if ( !nm )
glDisable(GL_NORMALIZE);
}
static void scene() {
glPushMatrix();
glRotatef(r1,0.0F,1.0F,0.0F);
glTranslatef(1.5F,0.0F,0.0F);
glPushMatrix();
glRotatef(90.0F,0.0F,0.0F,1.0F);
cylindre(3.0,0.5,12,12);
glPopMatrix();
glTranslatef(1.5F,0.0F,0.0F);
glRotatef(r2,0.0F,1.0F,0.0F);
glTranslatef(1.5F,0.0F,0.0F);
glPushMatrix();
glRotatef(90.0F,0.0F,0.0F,1.0F);
cylindre(3.0,0.4,12,12);
glPopMatrix();
glPopMatrix();
}