Lumières colorées et lumières blanches sur cubes sans normales
Lumières colorées et lumières blanches sur cubes avec normales
Cylindres par facette
Cylindre par facette (peu de facettes)
Fichier source : EnsembleFacettesCubeCylindre.cpp
Modules utilitaires
/* Scenes dessinees */
static void mySolidCubeSansNormales(double ct) {
float c =(float) ct/2.0F;
glPushMatrix();
glBegin(GL_QUADS);
{ glVertex3f(-c, c,-c);
glVertex3f(-c,-c,-c);
glVertex3f( c,-c,-c);
glVertex3f( c, c,-c); }
{ glVertex3f( c, c, c);
glVertex3f(-c, c, c);
glVertex3f(-c,-c, c);
glVertex3f( c,-c, c); }
{ glVertex3f(-c, c,-c);
glVertex3f(-c,-c,-c);
glVertex3f(-c,-c, c);
glVertex3f(-c, c, c); }
{ glVertex3f( c, c, c);
glVertex3f( c,-c, c);
glVertex3f( c,-c,-c);
glVertex3f( c, c,-c); }
{ glVertex3f(-c,-c, c);
glVertex3f(-c,-c,-c);
glVertex3f( c,-c,-c);
glVertex3f( c,-c, c); }
{ glVertex3f( c, c, c);
glVertex3f( c, c,-c);
glVertex3f(-c, c,-c);
glVertex3f(-c, c, c); }
glEnd();
glPopMatrix();
}
static void mySolidCubeAvecNormales(double ct) {
float c =(float) ct/2.0F;
GLboolean nm = glIsEnabled(GL_NORMALIZE);
if ( !nm )
glEnable(GL_NORMALIZE);
float normale[4];
glGetFloatv(GL_CURRENT_NORMAL,normale);
glPushMatrix();
glBegin(GL_QUADS);
{ glNormal3f(0.0F,0.0F,-1.0F);
glTexCoord2f(0.0F,0.0F);
glVertex3f( c, c,-c);
glTexCoord2f(0.0F,1.0F);
glVertex3f( c,-c,-c);
glTexCoord2f(1.0F,1.0F);
glVertex3f(-c,-c,-c);
glTexCoord2f(1.0F,0.0F);
glVertex3f(-c, c,-c); }
{ glNormal3f(0.0F,0.0F,1.0F);
glTexCoord2f(0.0F,0.0F);
glVertex3f( c, c, c);
glTexCoord2f(0.0F,1.0F);
glVertex3f(-c, c, c);
glTexCoord2f(1.0F,1.0F);
glVertex3f(-c,-c, c);
glTexCoord2f(1.0F,0.0F);
glVertex3f( c,-c, c); }
{ glNormal3f(-1.0F,0.0F,0.0F);
glTexCoord2f(0.0F,0.0F);
glVertex3f(-c, c,-c);
glTexCoord2f(0.0F,1.0F);
glVertex3f(-c,-c,-c);
glTexCoord2f(1.0F,1.0F);
glVertex3f(-c,-c, c);
glTexCoord2f(1.0F,0.0F);
glVertex3f(-c, c, c); }
{ glNormal3f(1.0F,0.0F,0.0F);
glTexCoord2f(0.0F,0.0F);
glVertex3f( c, c, c);
glTexCoord2f(0.0F,1.0F);
glVertex3f( c,-c, c);
glTexCoord2f(1.0F,1.0F);
glVertex3f( c,-c,-c);
glTexCoord2f(1.0F,0.0F);
glVertex3f( c, c,-c); }
{ glNormal3f(0.0F,-1.0F,0.0F);
glTexCoord2f(0.0F,0.0F);
glVertex3f(-c,-c, c);
glTexCoord2f(0.0F,1.0F);
glVertex3f(-c,-c,-c);
glTexCoord2f(1.0F,1.0F);
glVertex3f( c,-c,-c);
glTexCoord2f(1.0F,0.0F);
glVertex3f( c,-c, c); }
{ glNormal3f(0.0F,1.0F,0.0F);
glTexCoord2f(0.0F,0.0F);
glVertex3f( c, c, c);
glTexCoord2f(0.0F,1.0F);
glVertex3f( c, c,-c);
glTexCoord2f(1.0F,1.0F);
glVertex3f(-c, c,-c);
glTexCoord2f(1.0F,0.0F);
glVertex3f(-c, c, c); }
glEnd();
glPopMatrix();
glNormal3f(normale[0],normale[1],normale[2]);
if ( !nm )
glDisable(GL_NORMALIZE);
}
static void mySolidCylindre(double hauteur,double rayon,int ns) {
GLboolean nm = glIsEnabled(GL_NORMALIZE);
if ( !nm )
glEnable(GL_NORMALIZE);
float normale[4];
glGetFloatv(GL_CURRENT_NORMAL,normale);
glPushMatrix();
hauteur /= 2.0F;
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,hauteur,z);
glVertex3f(x,-hauteur,z); }
glEnd();
glPopMatrix();
glNormal3f(normale[0],normale[1],normale[2]);
if ( !nm )
glDisable(GL_NORMALIZE);
}
static void mySolidCylindre(double hauteur,double rayon,int ns,int nl) {
GLboolean nm = glIsEnabled(GL_NORMALIZE);
if ( !nm )
glEnable(GL_NORMALIZE);
float normale[4];
glGetFloatv(GL_CURRENT_NORMAL,normale);
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(); }
glPopMatrix();
glNormal3f(normale[0],normale[1],normale[2]);
if ( !nm )
glDisable(GL_NORMALIZE);
}
static void mySolidCylindre(double hauteur,double rayon,int ns,int nl,int bases) {
GLboolean nm = glIsEnabled(GL_NORMALIZE);
if ( !nm )
glEnable(GL_NORMALIZE);
float normale[4];
glGetFloatv(GL_CURRENT_NORMAL,normale);
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(); }
if ( bases ) {
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();
glNormal3f(normale[0],normale[1],normale[2]);
if ( !nm )
glDisable(GL_NORMALIZE);
}