L'exécutable
Le source: Morph3D.cpp
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glaux.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
static float Scale = 0.3F ;
static int tetradivisions = 23 ;
static int cubedivisions = 20 ;
static int octadivisions = 21 ;
static int dodecadivisions = 10 ;
static int icodivisions = 15 ;
static float tetraangle = 109.47122063449069174F ;
static float cubeangle = 90.000000000000000000F ;
static float octaangle = 109.47122063449069174F ;
static float dodecaangle = 63.434948822922009981F ;
static float icoangle = 41.810314895778596167F ;
static float Pi = 3.1415926535897932385F ;
static float sqrT2 = 1.4142135623730951455F ;
static float sqrT3 = 1.7320508075688771932F ;
static float sqrT5 = 2.2360679774997898051F ;
static float sqrT6 = 2.4494897427831778813F ;
static float sqrT15 = 3.8729833462074170214F ;
static float cossec36_2 = 0.8506508083520399322F ;
static float cos72 = 0.3090169943749474241F ;
static float sin72 = 0.9510565162951535721F ;
static float cos36 = 0.8090169943749474241F ;
static float sin36 = 0.5877852522924731292F ;
float VectMulx(float X1,float Y1,float Z1,float X2,float Y2,float Z2) {
return((Y1)*(Z2)-(Z1)*(Y2)) ;
}
float VectMuly(float X1,float Y1,float Z1,float X2,float Y2,float Z2) {
return((Z1)*(X2)-(X1)*(Z2)) ;
}
float VectMulz(float X1,float Y1,float Z1,float X2,float Y2,float Z2) {
return((X1)*(Y2)-(Y1)*(X2)) ;
}
float sqr(float a) {
return(a*a) ;
}
/*************************************************************************/
static int mono=0 ;
static int smooth=1 ;
static int WindH,WindW ;
static float step=0 ;
static float seno ;
static int object = 1 ;
static int edgedivisions ;
static float Magnitude ;
static float *MaterialColor[20] ;
static float front_shininess[] = { 60.0F } ;
static float front_specular[] = { 0.7F,0.7F,0.7F,1.0F } ;
static float ambient[] = { 0.0F,0.0F,0.0F,1.0F } ;
static float diffuse[] = { 1.0F,1.0F,1.0F,1.0F } ;
static float position0[] = { 1.0F,1.0F,1.0F,0.0F } ;
static float position1[] = { -1.0F,-1.0F,1.0F,0.0F } ;
static float lmodel_ambient[] = { 0.5F,0.5F,0.5F,1.0F } ;
static float lmodel_twoside[] = { 0.0F } ;
static float MaterialRed[] = { 0.7F,0.0F,0.0F,1.0F } ;
static float MaterialGreen[] = { 0.1F,0.5F,0.2F,1.0F } ;
static float MaterialBlue[] = { 0.0F,0.0F,0.7F,1.0F } ;
static float MaterialCyan[] = { 0.2F,0.5F,0.7F,1.0F } ;
static float MaterialYellow[] = { 0.7F,0.7F,0.0F,1.0F } ;
static float MaterialMagenta[] = { 0.6F,0.2F,0.5F,1.0F } ;
static float MaterialWhite[] = { 0.7F,0.7F,0.7F,1.0F } ;
static float MaterialGray[] = { 0.2F,0.2F,0.2F,1.0F } ;
void TRIANGLE(float Edge,float Amp,int Divisions,float Z) {
float Xf,Yf,Xa,Yb,Xf2,Yf2;
float Factor,Factor1,Factor2;
float VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ;
float Ax,Ay,Bx;
int Ri,Ti;
float Vr=(Edge)*sqrT3/3;
float AmpVr2=(Amp)/sqr(Vr);
float Zf=(Edge)*(Z);
Ax=(Edge)*(+0.5F/(Divisions));
Ay=(Edge)*(-sqrT3/(2*Divisions));
Bx=(Edge)*(-0.5F/(Divisions));
for (Ri=1; Ri<=(Divisions); Ri++) {
glBegin(GL_TRIANGLE_STRIP);
for (Ti=0; Ti<Ri; Ti++) {
Xf=(float)(Ri-Ti)*Ax + (float)Ti*Bx;
Yf=Vr+(float)(Ri-Ti)*Ay + (float)Ti*Ay;
Xa=Xf+0.001F;
Yb=Yf+0.001F;
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);
Factor2=1-((Xf2+sqr(Yb))*AmpVr2);
VertX=Factor*Xf;
VertY=Factor*Yf;
VertZ=Factor*Zf;
NeiAX=Factor1*Xa-VertX;
NeiAY=Factor1*Yf-VertY;
NeiAZ=Factor1*Zf-VertZ;
NeiBX=Factor2*Xf-VertX;
NeiBY=Factor2*Yb-VertY;
NeiBZ=Factor2*Zf-VertZ;
glNormal3f(VectMulx(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMuly(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMulz(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ));
glVertex3f(VertX,VertY,VertZ);
Xf=(float)(Ri-Ti-1)*Ax + (float)Ti*Bx;
Yf=Vr+(float)(Ri-Ti-1)*Ay + (float)Ti*Ay;
Xa=Xf+0.001F;
Yb=Yf+0.001F;
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);
Factor2=1-((Xf2+sqr(Yb))*AmpVr2);
VertX=Factor*Xf;
VertY=Factor*Yf;
VertZ=Factor*Zf;
NeiAX=Factor1*Xa-VertX;
NeiAY=Factor1*Yf-VertY;
NeiAZ=Factor1*Zf-VertZ;
NeiBX=Factor2*Xf-VertX;
NeiBY=Factor2*Yb-VertY;
NeiBZ=Factor2*Zf-VertZ;
glNormal3f(VectMulx(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMuly(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMulz(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ));
glVertex3f(VertX,VertY,VertZ); }
Xf=(float)Ri*Bx;
Yf=Vr+(float)Ri*Ay;
Xa=Xf+0.001F;
Yb=Yf+0.001F;
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);
Factor2=1-((Xf2+sqr(Yb))*AmpVr2);
VertX=Factor*Xf;
VertY=Factor*Yf;
VertZ=Factor*Zf;
NeiAX=Factor1*Xa-VertX;
NeiAY=Factor1*Yf-VertY;
NeiAZ=Factor1*Zf-VertZ;
NeiBX=Factor2*Xf-VertX;
NeiBY=Factor2*Yb-VertY;
NeiBZ=Factor2*Zf-VertZ;
glNormal3f(VectMulx(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMuly(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMulz(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ));
glVertex3f(VertX,VertY,VertZ);
glEnd(); }
}
void SQUARE(int Edge,float Amp,int Divisions,float Z) {
int Xi,Yi;
float Xf,Yf,Y,Xf2,Yf2,Y2,Xa,Yb;
float Factor,Factor1,Factor2;
float VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ;
float Zf=(Edge)*(Z);
float AmpVr2=(Amp)/sqr((Edge)*sqrT2/2);
for (Yi=0; Yi<(Divisions); Yi++) {
Yf=-((Edge)/2.0F) + ((float)Yi)/(Divisions)*(Edge);
Yf2=sqr(Yf);
Y=Yf+1.0F/(Divisions)*(Edge);
Y2=sqr(Y);
glBegin(GL_QUAD_STRIP);
for (Xi=0; Xi<=(Divisions); Xi++) {
Xf=-((Edge)/2.0F) + ((float)Xi)/(Divisions)*(Edge);
Xf2=sqr(Xf);
Xa=Xf+0.001F;
Yb=Y+0.001F;
Factor=1-((Xf2+Y2)*AmpVr2);
Factor1=1-((sqr(Xa)+Y2)*AmpVr2);
Factor2=1-((Xf2+sqr(Yb))*AmpVr2);
VertX=Factor*Xf;
VertY=Factor*Y;
VertZ=Factor*Zf;
NeiAX=Factor1*Xa-VertX;
NeiAY=Factor1*Y-VertY;
NeiAZ=Factor1*Zf-VertZ;
NeiBX=Factor2*Xf-VertX;
NeiBY=Factor2*Yb-VertY;
NeiBZ=Factor2*Zf-VertZ;
glNormal3f(VectMulx(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMuly(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMulz(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ));
glVertex3f(VertX,VertY,VertZ);
Xa=Xf+0.001F;
Yb=Yf+0.001F;
Factor=1-((Xf2+Yf2)*AmpVr2);
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);
Factor2=1-((Xf2+sqr(Yb))*AmpVr2);
VertX=Factor*Xf;
VertY=Factor*Yf;
VertZ=Factor*Zf;
NeiAX=Factor1*Xa-VertX;
NeiAY=Factor1*Yf-VertY;
NeiAZ=Factor1*Zf-VertZ;
NeiBX=Factor2*Xf-VertX;
NeiBY=Factor2*Yb-VertY;
NeiBZ=Factor2*Zf-VertZ;
glNormal3f(VectMulx(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMuly(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMulz(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ));
glVertex3f(VertX,VertY,VertZ); }
glEnd(); }
}
void PENTAGON(int Edge,float Amp,int Divisions,float Z) {
int Ri,Ti,Fi;
float Xf,Yf,Xa,Yb,Xf2,Yf2;
float x[6] ;
float y[6] ;
float Factor,Factor1,Factor2;
float VertX,VertY,VertZ,NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ;
float Zf=(Edge)*(Z);
float AmpVr2=(Amp)/sqr((Edge)*cossec36_2);
for(Fi=0;Fi<6;Fi++) {
x[Fi]=(float) (-cos(Fi*2*Pi/5 + Pi/10 )/(Divisions)*cossec36_2*(Edge));
y[Fi]=(float) (sin(Fi*2*Pi/5 + Pi/10 )/(Divisions)*cossec36_2*(Edge)); }
for (Ri=1; Ri<=(Divisions); Ri++) {
for (Fi=0; Fi<5; Fi++) {
glBegin(GL_TRIANGLE_STRIP);
for (Ti=0; Ti<Ri; Ti++) {
Xf=(float)(Ri-Ti)*x[Fi] + (float)Ti*x[Fi+1];
Yf=(float)(Ri-Ti)*y[Fi] + (float)Ti*y[Fi+1];
Xa=Xf+0.001F;
Yb=Yf+0.001F;
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);
Factor2=1-((Xf2+sqr(Yb))*AmpVr2);
VertX=Factor*Xf;
VertY=Factor*Yf;
VertZ=Factor*Zf;
NeiAX=Factor1*Xa-VertX;
NeiAY=Factor1*Yf-VertY;
NeiAZ=Factor1*Zf-VertZ;
NeiBX=Factor2*Xf-VertX;
NeiBY=Factor2*Yb-VertY;
NeiBZ=Factor2*Zf-VertZ;
glNormal3f(VectMulx(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMuly(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMulz(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ));
glVertex3f(VertX,VertY,VertZ);
Xf=(float)(Ri-Ti-1)*x[Fi] + (float)Ti*x[Fi+1];
Yf=(float)(Ri-Ti-1)*y[Fi] + (float)Ti*y[Fi+1];
Xa=Xf+0.001F;
Yb=Yf+0.001F;
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);
Factor2=1-((Xf2+sqr(Yb))*AmpVr2);
VertX=Factor*Xf;
VertY=Factor*Yf;
VertZ=Factor*Zf;
NeiAX=Factor1*Xa-VertX;
NeiAY=Factor1*Yf-VertY;
NeiAZ=Factor1*Zf-VertZ;
NeiBX=Factor2*Xf-VertX;
NeiBY=Factor2*Yb-VertY;
NeiBZ=Factor2*Zf-VertZ;
glNormal3f(VectMulx(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMuly(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMulz(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ));
glVertex3f(VertX,VertY,VertZ); }
Xf=(float)Ri*x[Fi+1];
Yf=(float)Ri*y[Fi+1];
Xa=Xf+0.001F;
Yb=Yf+0.001F;
Factor=1-(((Xf2=sqr(Xf))+(Yf2=sqr(Yf)))*AmpVr2);
Factor1=1-((sqr(Xa)+Yf2)*AmpVr2);
Factor2=1-((Xf2+sqr(Yb))*AmpVr2);
VertX=Factor*Xf;
VertY=Factor*Yf;
VertZ=Factor*Zf;
NeiAX=Factor1*Xa-VertX;
NeiAY=Factor1*Yf-VertY;
NeiAZ=Factor1*Zf-VertZ;
NeiBX=Factor2*Xf-VertX;
NeiBY=Factor2*Yb-VertY;
NeiBZ=Factor2*Zf-VertZ;
glNormal3f(VectMulx(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMuly(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ),VectMulz(NeiAX,NeiAY,NeiAZ,NeiBX,NeiBY,NeiBZ));
glVertex3f(VertX,VertY,VertZ);
glEnd(); } }
}
void draw_tetra() {
int list;
list = glGenLists(1);
glNewList(list,GL_COMPILE);
TRIANGLE(2,seno,edgedivisions,0.5F/sqrT6);
glEndList();
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[0]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,0,1);
glRotatef(-tetraangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[1]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+tetraangle,0.5F,sqrT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[2]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,1,0);
glRotatef(-180+tetraangle,0.5F,-sqrT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[3]);
glCallList(list);
glDeleteLists(list,1);
}
void draw_cube() {
int list;
list = glGenLists(1);
glNewList(list,GL_COMPILE);
SQUARE(2,seno,edgedivisions,0.5F) ;
glEndList();
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[0]);
glCallList(list);
glRotatef(cubeangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[1]);
glCallList(list);
glRotatef(cubeangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[2]);
glCallList(list);
glRotatef(cubeangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[3]);
glCallList(list);
glRotatef(cubeangle,0,1,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[4]);
glCallList(list);
glRotatef(2*cubeangle,0,1,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[5]);
glCallList(list);
glDeleteLists(list,1);
}
void draw_octa() {
int list;
list = glGenLists(1);
glNewList(list,GL_COMPILE);
TRIANGLE(2,seno,edgedivisions,1/sqrT6);
glEndList();
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[0]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,0,1);
glRotatef(-180+octaangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[1]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-octaangle,0.5F,sqrT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[2]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-octaangle,0.5F,-sqrT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[3]);
glCallList(list);
glPopMatrix();
glRotatef(180,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[4]);
glCallList(list);
glPushMatrix();
glRotatef(180,0,0,1);
glRotatef(-180+octaangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[5]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180,0,1,0);
glRotatef(-octaangle,0.5F,sqrT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[6]);
glCallList(list);
glPopMatrix();
glRotatef(180,0,1,0);
glRotatef(-octaangle,0.5F,-sqrT3/2,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[7]);
glCallList(list);
glDeleteLists(list,1);
}
void draw_dodeca() {
int list;
float TAU = ((sqrT5+1)/2) ;
list = glGenLists(1);
glNewList(list,GL_COMPILE);
PENTAGON(1,seno,edgedivisions,(float) (sqr(TAU) * sqrt((TAU+2)/5) / 2));
glEndList();
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[0]);
glCallList(list);
glRotatef(180,0,0,1);
glPushMatrix();
glRotatef(-dodecaangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[1]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(-dodecaangle,cos72,sin72,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[2]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(-dodecaangle,cos72,-sin72,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[3]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(dodecaangle,cos36,-sin36,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[4]);
glCallList(list);
glPopMatrix();
glRotatef(dodecaangle,cos36,sin36,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[5]);
glCallList(list);
glPopMatrix();
glRotatef(180,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[6]);
glCallList(list);
glRotatef(180,0,0,1);
glPushMatrix();
glRotatef(-dodecaangle,1,0,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[7]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(-dodecaangle,cos72,sin72,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[8]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(-dodecaangle,cos72,-sin72,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[9]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(dodecaangle,cos36,-sin36,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[10]);
glCallList(list);
glPopMatrix();
glRotatef(dodecaangle,cos36,sin36,0);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[11]);
glCallList(list);
glDeleteLists(list,1);
}
void draw_ico() {
int list;
list = glGenLists(1);
glNewList(list,GL_COMPILE);
TRIANGLE(1.5F,seno,edgedivisions,(3*sqrT3+sqrT15)/12.0F);
glEndList();
glPushMatrix();
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[0]);
glCallList(list);
glPushMatrix();
glRotatef(180,0.0F,0.0F,1.0F);
glRotatef(-icoangle,1.0F,0.0F,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[1]);
glCallList(list);
glPushMatrix();
glRotatef(180.0F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[2]);
glCallList(list);
glPopMatrix();
glRotatef(180.F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,-sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[3]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180.0F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[4]);
glCallList(list);
glPushMatrix();
glRotatef(180.0F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[5]);
glCallList(list);
glPopMatrix();
glRotatef(180.0F,0.0F,0.0F,1.0F);
glRotatef(-icoangle,1.0F,0.0F,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[6]);
glCallList(list);
glPopMatrix();
glRotatef(180.0F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,-sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[7]);
glCallList(list);
glPushMatrix();
glRotatef(180.0F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,-sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[8]);
glCallList(list);
glPopMatrix();
glRotatef(180.0F,0.0F,0.0F,1.0F);
glRotatef(-icoangle,1.0F,0.0F,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[9]);
glCallList(list);
glPopMatrix();
glRotatef(180.0F,1.0F,0.0F,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[10]);
glCallList(list);
glPushMatrix();
glRotatef(180.0F,0.0F,0.0F,1.0F);
glRotatef(-icoangle,1.0F,0.0F,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[11]);
glCallList(list);
glPushMatrix();
glRotatef(180.0F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[12]);
glCallList(list);
glPopMatrix();
glRotatef(180.0F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,-sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[13]);
glCallList(list);
glPopMatrix();
glPushMatrix();
glRotatef(180.0F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[14]);
glCallList(list);
glPushMatrix();
glRotatef(180.0F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[15]);
glCallList(list);
glPopMatrix();
glRotatef(180.0F,0.0F,0.0F,1.0F);
glRotatef(-icoangle,1.0F,0.0F,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[16]);
glCallList(list);
glPopMatrix();
glRotatef(180.0F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,-sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[17]);
glCallList(list);
glPushMatrix();
glRotatef(180.0F,0.0F,1.0F,0.0F);
glRotatef(-180+icoangle,0.5F,-sqrT3/2,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[18]);
glCallList(list);
glPopMatrix();
glRotatef(180.0F,0.0F,0.0F,1.0F);
glRotatef(-icoangle,1.0F,0.0F,0.0F);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,MaterialColor[19]);
glCallList(list);
glDeleteLists(list,1);
}
void CALLBACK display() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
glTranslatef(0.0F,0.0F,-10.0F);
glScalef(Scale*WindH/WindW,Scale,Scale);
glTranslatef((float) (2.5*WindW/WindH*sin(step*1.11)),(float) (2.5*cos(step*1.25*1.11)),0.0F);
glRotatef(step*100,1.0F,0.0F,0.0F);
glRotatef(step*95,0.0F,1.0F,0.0F);
glRotatef(step*90,0.0F,0.0F,1.0F);
seno=(float) ((sin(step)+1.0/3.0)*(4.0/5.0)*Magnitude);
switch(object) {
case 1 : draw_tetra() ;
break ;
case 2 : draw_cube() ;
break ;
case 3 : draw_octa() ;
break ;
case 4 : draw_dodeca() ;
break ;
case 5 : draw_ico() ; }
glPopMatrix();
glFlush();
auxSwapBuffers();
step+=0.05F;
}
void CALLBACK idle() {
display();
}
void CALLBACK reshape(int width,int height ) {
glViewport(0,0,WindW=width,WindH=height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-1.0,1.0,-1.0,1.0,5.0,15.0);
glMatrixMode(GL_MODELVIEW);
}
void pinit() {
switch(object) {
case 1: MaterialColor[0]=MaterialRed;
MaterialColor[1]=MaterialGreen;
MaterialColor[2]=MaterialBlue;
MaterialColor[3]=MaterialWhite;
edgedivisions=tetradivisions;
Magnitude=2.5F;
break;
case 2: MaterialColor[0]=MaterialRed;
MaterialColor[1]=MaterialGreen;
MaterialColor[2]=MaterialCyan;
MaterialColor[3]=MaterialMagenta;
MaterialColor[4]=MaterialYellow;
MaterialColor[5]=MaterialBlue;
edgedivisions=cubedivisions;
Magnitude=2.0F;
break;
case 3: MaterialColor[0]=MaterialRed;
MaterialColor[1]=MaterialGreen;
MaterialColor[2]=MaterialBlue;
MaterialColor[3]=MaterialWhite;
MaterialColor[4]=MaterialCyan;
MaterialColor[5]=MaterialMagenta;
MaterialColor[6]=MaterialGray;
MaterialColor[7]=MaterialYellow;
edgedivisions=octadivisions;
Magnitude=2.5F;
break;
case 4: MaterialColor[0]=MaterialRed;
MaterialColor[1]=MaterialGreen;
MaterialColor[2]=MaterialCyan;
MaterialColor[3]=MaterialBlue;
MaterialColor[4]=MaterialMagenta;
MaterialColor[5]=MaterialYellow;
MaterialColor[6]=MaterialGreen;
MaterialColor[7]=MaterialCyan;
MaterialColor[8]=MaterialRed;
MaterialColor[9]=MaterialMagenta;
MaterialColor[10]=MaterialBlue;
MaterialColor[11]=MaterialYellow;
edgedivisions=dodecadivisions;
Magnitude=2.0F;
break;
case 5: MaterialColor[0]=MaterialRed;
MaterialColor[1]=MaterialGreen;
MaterialColor[2]=MaterialBlue;
MaterialColor[3]=MaterialCyan;
MaterialColor[4]=MaterialYellow;
MaterialColor[5]=MaterialMagenta;
MaterialColor[6]=MaterialRed;
MaterialColor[7]=MaterialGreen;
MaterialColor[8]=MaterialBlue;
MaterialColor[9]=MaterialWhite;
MaterialColor[10]=MaterialCyan;
MaterialColor[11]=MaterialYellow;
MaterialColor[12]=MaterialMagenta;
MaterialColor[13]=MaterialRed;
MaterialColor[14]=MaterialGreen;
MaterialColor[15]=MaterialBlue;
MaterialColor[16]=MaterialCyan;
MaterialColor[17]=MaterialYellow;
MaterialColor[18]=MaterialMagenta;
MaterialColor[19]=MaterialGray;
edgedivisions=icodivisions;
Magnitude=2.5F;
break; }
if (mono != 0) {
int loop;
for (loop=0; loop<20; loop++) MaterialColor[loop]=MaterialGray; }
if (smooth != 0) {
glShadeModel(GL_SMOOTH); }
else {
glShadeModel(GL_FLAT); }
}
void CALLBACK auxKey1() {
object = 1 ;
pinit() ;
}
void CALLBACK auxKey2() {
object = 2 ;
pinit() ;
}
void CALLBACK auxKey3() {
object = 3 ;
pinit() ;
}
void CALLBACK auxKey4() {
object = 4 ;
pinit() ;
}
void CALLBACK auxKey5() {
object = 5 ;
pinit() ;
}
void CALLBACK auxKeySpace() {
mono ^= 1 ;
pinit() ;
}
void CALLBACK auxKeyReturn() {
smooth ^= 1 ;
pinit() ;
}
void initialise() {
object=1;
glClearDepth(1.0);
glClearColor(0.0F,0.0F,0.0F,1.0F);
glColor3f(1.0F,1.0F,1.0F);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glFlush();
glLightfv(GL_LIGHT0,GL_AMBIENT,ambient);
glLightfv(GL_LIGHT0,GL_DIFFUSE,diffuse);
glLightfv(GL_LIGHT0,GL_POSITION,position0);
glLightfv(GL_LIGHT1,GL_AMBIENT,ambient);
glLightfv(GL_LIGHT1,GL_DIFFUSE,diffuse);
glLightfv(GL_LIGHT1,GL_POSITION,position1);
glLightModelfv(GL_LIGHT_MODEL_AMBIENT,lmodel_ambient);
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE,lmodel_twoside);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE);
glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,front_shininess);
glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,front_specular);
glHint(GL_FOG_HINT,GL_FASTEST);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_FASTEST);
glHint(GL_POLYGON_SMOOTH_HINT,GL_FASTEST);
pinit();
}
void main(void) {
auxInitDisplayMode(AUX_DOUBLE|AUX_RGBA|AUX_DEPTH);
auxInitPosition (0,0,300,300);
auxInitWindow("Morph3D") ;
initialise();
auxReshapeFunc(reshape);
auxKeyFunc(AUX_1,auxKey1) ;
auxKeyFunc(AUX_2,auxKey2) ;
auxKeyFunc(AUX_3,auxKey3) ;
auxKeyFunc(AUX_4,auxKey4) ;
auxKeyFunc(AUX_5,auxKey5) ;
auxKeyFunc(AUX_SPACE,auxKeySpace) ;
auxKeyFunc(AUX_RETURN,auxKeyReturn) ;
auxIdleFunc(idle);
auxMainLoop(display);
}
RETOUR