Le source: SchemaHemicubeZBuffer.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Juillet 2001 */
/* ZBuffer sur hemicube en radiosite */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleCouleurs.h"
#include "ModuleReshape.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleFont.h"
#include "ModuleFleche.h"
struct coord3D {
float x;
float y;
float z; } ;
struct direc3D {
float x;
float y;
float z; } ;
struct facette4 {
coord3D pt[4] ; } ;
struct facette3 {
coord3D pt[3] ; } ;
struct rayon {
coord3D o ;
direc3D d ; } ;
static int f1;
static int f2;
static double ff = 0.0;
static double ff1 = 0.0;
static double ff2 = 0.0;
static double ff3 = 0.0;
static int aff = 0;
static float cote = 4.0F;
static int disc = 10;
static int fac = 0;
static facette4 fi = { {{ -5.0F,-4.0F,-3.0F },
{ -4.0F,-4.0F,3.5F },
{ 5.5F,-4.0F,4.5F },
{ 3.5F,-4.0F,-5.0F }} };
static facette4 fj1 = { {{ -1.0F,-1.0F,-10.0F },
{ 4.5F,0.5F,-7.5F },
{ 2.0F,5.0F,-5.0F },
{ -2.0F,6.5F,-5.0F }} };
static facette4 fj2 = { {{ -1.0F,5.5F,3.0F },
{ 3.5F,6.5F,2.5F },
{ 2.0F,4.5F,-4.0F },
{ -3.0F,3.5F,-3.0F }} };
static facette4 fj3 = { {{ 5.5F,2.5F,4.5F },
{ 6.0F,2.5F,-5.0F },
{ -4.0F,2.5F,-6.5F },
{ -3.0F,2.5F,5.5F }} };
static facette4 *fj = &fj1;
static double ***fe;
static double totfe;
double facteurElementaire(int pi,int pj,int aff,int disc) {
double ff = 0.0F;
int ii,jj;
switch (aff) {
case 0 : ii = ( pi < disc) ? disc-1-pi : pi-disc ;
jj = ( pj < disc) ? disc-1-pj : pj-disc;
ff = fe[0][ii][jj]/totfe;
break;
case 1 : ii = ( pi < disc) ? disc-1-pi : pi-disc ;
jj = pj ;
ff = fe[1][ii][jj]/totfe;
break; }
return(ff);
}
double ***calculFacteursElementaires(int disc) {
double ***fe ;
int i,j;
fe =(double ***) calloc(2,sizeof(double **));
for ( i = 0 ; i < 2 ; i++ ) {
fe[i] =(double **) calloc(disc,sizeof(double *));
for ( j = 0 ; j < disc ; j++ )
fe[i][j] =(double *) calloc(disc,sizeof(double)); }
double deltaA = 1.0/disc/disc ;
double inc = 1.0/disc;
double x = 0.5/disc;
double z;
for ( i = 0 ; i < disc ; i++,x += inc ) {
z = 0.5/disc;
for ( j = 0 ; j < disc ; j++,z += inc ) {
double dn = x*x + z*z + 1.0;
fe[0][i][j] = deltaA / (3.14159*dn*dn); } }
x = 0.5/disc;
for ( i = 0 ; i < disc ; i++,x += inc ) {
z = 0.5/disc;
for ( j = 0 ; j < disc ; j++,z += inc ) {
double dn = x*x + z*z + 1.0;
fe[1][i][j] = z*deltaA / (3.14159*dn*dn); } }
return(fe);
}
void liberationFacteursElementaires(int disc,double ***fe) {
int i,j ;
for ( i = 0 ; i < 2 ; i++ ) {
for ( j = 0 ; j < disc ; j++ ) {
free(fe[i][j]); }
free(fe[i]); }
}
double sommeTotaleFacteursElementaires(int disc,double ***fe) {
int i,j ;
double t1 = 0,t2 = 0;
for ( i = 0 ; i < disc ; i++ )
for ( j = 0 ; j < disc ; j++ ) {
t1 += fe[0][i][j];
t2 += fe[1][i][j]; }
return(4*t1+8*t2);
}
float produitScalaire(direc3D *v1,direc3D *v2) {
return(v1->x*v2->x+v1->y*v2->y+v1->z*v2->z);
}
void produitVectoriel(direc3D *v1,direc3D *v2,direc3D *v) {
v->x = v1->y*v2->z-v2->y*v1->z;
v->y = v1->z*v2->x-v2->z*v1->x;
v->z = v1->x*v2->y-v2->x*v1->y;
}
void vecteur(coord3D *p1,coord3D *p2,direc3D *v) {
v->x = p2->x - p1->x;
v->y = p2->y - p1->y;
v->z = p2->z - p1->z;
}
void normalize(direc3D *n) {
double d =sqrt(n->x*n->x+n->y*n->y+n->z*n->z);
if ( d != 0.0 ) {
n->x /= d;
n->y /= d;
n->z /= d; }
}
void normale(facette4 *f,direc3D *n) {
direc3D v1;
direc3D v2;
vecteur(&f->pt[0],&f->pt[1],&v1);
vecteur(&f->pt[0],&f->pt[2],&v2);
produitVectoriel(&v1,&v2,n);
normalize(n);
}
void centre(facette4 *f,coord3D *p) {
p->x = (f->pt[0].x+f->pt[1].x+f->pt[2].x+f->pt[3].x)/4.0F;
p->y = (f->pt[0].y+f->pt[1].y+f->pt[2].y+f->pt[3].y)/4.0F;
p->z = (f->pt[0].z+f->pt[1].z+f->pt[2].z+f->pt[3].z)/4.0F;
}
void centrePondere(facette4 *f,coord3D *p,float c0,float c1,float c2,float c3) {
p->x = (f->pt[0].x*c0+f->pt[1].x*c1+f->pt[2].x*c2+f->pt[3].x*c3)/(c0+c1+c2+c3);
p->y = (f->pt[0].y*c0+f->pt[1].y*c1+f->pt[2].y*c2+f->pt[3].y*c3)/(c0+c1+c2+c3);
p->z = (f->pt[0].z*c0+f->pt[1].z*c1+f->pt[2].z*c2+f->pt[3].z*c3)/(c0+c1+c2+c3);
}
void vecteursOrthogonaux(direc3D *d,direc3D *d1,direc3D *d2) {
d1->x = d->y;
d1->y = -d->x;
d1->z = 0.0F;
normalize(d1);
produitVectoriel(d,d1,d2);
}
void afficheSommet(coord3D *p) {
glPushMatrix();
glTranslatef(p->x,p->y,p->z);
glEnable(GL_LIGHTING);
glutSolidSphere(0.1,10,10);
glDisable(GL_LIGHTING);
glPopMatrix();
}
void myinit(void) {
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE) ;
glEnable(GL_LIGHT0);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glClearColor(1.0F,1.0F,0.9F,0.0F);
fe = calculFacteursElementaires(disc);
totfe = sommeTotaleFacteursElementaires(disc,fe);
}
void traceFacette4(int type,facette4 *f) {
glBegin(type);
for ( int i = 0 ; i < 4 ; i++ )
glVertex3f(f->pt[i].x,f->pt[i].y,f->pt[i].z);
glEnd();
}
int intersectionFaceDessus(coord3D *p,float cote,coord3D *centre,coord3D *inter) {
direc3D v ;
vecteur(centre,p,&v) ;
float alpha = cote/v.y;
if ( alpha > 0 ) {
inter->x = v.x*alpha + centre->x;
inter->y = v.y*alpha + centre->y;
inter->z = v.z*alpha + centre->z;
if ( ( inter->x >= centre->x-cote ) && ( inter->x <= centre->x+cote ) &&
( inter->z >= centre->z-cote ) && ( inter->z <= centre->z+cote ) )
return(1); }
return(0);
}
int intersectionFaceCoteDroit(coord3D *p,float cote,coord3D *centre,coord3D *inter) {
direc3D v ;
vecteur(centre,p,&v) ;
float alpha = cote/v.x;
if ( alpha > 0 ) {
inter->x = v.x*alpha + centre->x;
inter->y = v.y*alpha + centre->y;
inter->z = v.z*alpha + centre->z;
if ( ( inter->y >= centre->y ) && ( inter->y <= centre->y+cote ) &&
( inter->z >= centre->z-cote ) && ( inter->z <= centre->z+cote ) )
return(1); }
return(0);
}
int intersectionFaceCoteGauche(coord3D *p,float cote,coord3D *centre,coord3D *inter) {
direc3D v ;
vecteur(centre,p,&v) ;
float alpha = -cote/v.x;
if ( alpha > 0 ) {
inter->x = v.x*alpha + centre->x;
inter->y = v.y*alpha + centre->y;
inter->z = v.z*alpha + centre->z;
if ( ( inter->y >= centre->y ) && ( inter->y <= centre->y+cote ) &&
( inter->z >= centre->z-cote ) && ( inter->z <= centre->z+cote ) )
return(1); }
return(0);
}
int intersectionFaceCoteDevant(coord3D *p,float cote,coord3D *centre,coord3D *inter) {
direc3D v ;
vecteur(centre,p,&v) ;
float alpha = cote/v.z;
if ( alpha > 0 ) {
inter->x = v.x*alpha + centre->x;
inter->y = v.y*alpha + centre->y;
inter->z = v.z*alpha + centre->z;
if ( ( inter->y >= centre->y ) && ( inter->y <= centre->y+cote ) &&
( inter->x >= centre->x-cote ) && ( inter->x <= centre->x+cote ) )
return(1); }
return(0);
}
int intersectionFaceCoteDerriere(coord3D *p,float cote,coord3D *centre,coord3D *inter) {
direc3D v ;
vecteur(centre,p,&v) ;
float alpha = -cote/v.z;
if ( alpha > 0 ) {
inter->x = v.x*alpha + centre->x;
inter->y = v.y*alpha + centre->y;
inter->z = v.z*alpha + centre->z;
if ( ( inter->y >= centre->y ) && ( inter->y <= centre->y+cote ) &&
( inter->x >= centre->x-cote ) && ( inter->x <= centre->x+cote ) )
return(1); }
return(0);
}
void afficheIntersection(coord3D *p,float cote,coord3D *c1) {
coord3D inter ;
if ( intersectionFaceDessus(p,cote,c1,&inter) )
afficheSommet(&inter);
else
if ( intersectionFaceCoteDroit(p,cote,c1,&inter) )
afficheSommet(&inter);
else
if ( intersectionFaceCoteGauche(p,cote,c1,&inter) )
afficheSommet(&inter);
else
if ( intersectionFaceCoteDevant(p,cote,c1,&inter) )
afficheSommet(&inter);
else
if ( intersectionFaceCoteDerriere(p,cote,c1,&inter) )
afficheSommet(&inter);
}
int testIntersectionRayonFacette(facette3 *f,rayon *r) {
float x1 = f->pt[1].x-f->pt[0].x;
float y1 = f->pt[1].y-f->pt[0].y;
float z1 = f->pt[1].z-f->pt[0].z;
float x2 = f->pt[2].x-f->pt[0].x;
float y2 = f->pt[2].y-f->pt[0].y;
float z2 = f->pt[2].z-f->pt[0].z;
float x3 = r->d.x;
float y3 = r->d.y;
float z3 = r->d.z;
float dx = r->o.x - f->pt[0].x;
float dy = r->o.y - f->pt[0].y;
float dz = r->o.z - f->pt[0].z;
float d = z1*y3*x2-y1*z3*x2-x3*z1*y2-y3*x1*z2+z3*x1*y2+x3*y1*z2;
if ( d != 0.0F ) {
float v = -(-x3*y1*dz-z3*x1*dy+y1*z3*dx+x3*z1*dy+y3*x1*dz-z1*y3*dx)/d;
if ( v >= 0.0F ) {
float u = (-y3*dx*z2+y3*x2*dz-x2*z3*dy+dx*z3*y2-x3*y2*dz+x3*dy*z2)/d;
if ( ( u >= 0.0F ) && ( u+v <= 1.0F ) ) {
float t = -(-dx*z1*y2+dx*y1*z2+x1*y2*dz-x1*dy*z2-x2*y1*dz+x2*z1*dy)/d;
if ( t > 0.0F ) {
return(1); } } } }
return(0);
}
void afficheElement(coord3D *p,int t,float cote,int disc) {
glBegin(GL_QUADS);
switch(t) {
case 0 : glVertex3f(p->x-cote/disc/2,p->y,p->z-cote/disc/2);
glVertex3f(p->x+cote/disc/2,p->y,p->z-cote/disc/2);
glVertex3f(p->x+cote/disc/2,p->y,p->z+cote/disc/2);
glVertex3f(p->x-cote/disc/2,p->y,p->z+cote/disc/2);
break;
case 2 : glVertex3f(p->x,p->y-cote/disc/2,p->z-cote/disc/2);
glVertex3f(p->x,p->y+cote/disc/2,p->z-cote/disc/2);
glVertex3f(p->x,p->y+cote/disc/2,p->z+cote/disc/2);
glVertex3f(p->x,p->y-cote/disc/2,p->z+cote/disc/2);
break;
case 1 : glVertex3f(p->x-cote/disc/2,p->y-cote/disc/2,p->z);
glVertex3f(p->x-cote/disc/2,p->y+cote/disc/2,p->z);
glVertex3f(p->x+cote/disc/2,p->y+cote/disc/2,p->z);
glVertex3f(p->x+cote/disc/2,p->y-cote/disc/2,p->z);
break; }
glEnd();
}
double afficheElementsDuDessus(facette4 *f,float cote,coord3D *c,int disc) {
int i,j;
double ff = 0.0;
float y = c->y+cote;
float x = c->x-cote+cote/disc/2;
facette3 f1;
facette3 f2;
f1.pt[0] = f->pt[0];
f1.pt[1] = f->pt[1];
f1.pt[2] = f->pt[2];
f2.pt[0] = f->pt[0];
f2.pt[1] = f->pt[2];
f2.pt[2] = f->pt[3];
for ( i = 0 ; i < 2*disc ; i++,x += cote/disc ) {
float z = c->z-cote+cote/disc/2;
for ( j = 0 ; j < 2*disc ; j++,z += cote/disc ) {
rayon r;
r.o = *c;
r.d.x = x-c->x;
r.d.y = y-c->y;
r.d.z = z-c->z;
coord3D p = { x,y,z };
if ( testIntersectionRayonFacette(&f1,&r) ) {
ff += facteurElementaire(i,j,0,disc);
afficheElement(&p,0,cote,disc); }
else
if ( testIntersectionRayonFacette(&f2,&r) ) {
ff += facteurElementaire(i,j,0,disc);
afficheElement(&p,0,cote,disc); } } }
return(ff);
}
double afficheElementsDeDerriere(facette4 *f,float cote,coord3D *c,int disc) {
int i,j;
double ff = 0.0;
float x = c->x-cote+cote/disc/2;
float z = c->z-cote;
facette3 f1;
facette3 f2;
f1.pt[0] = f->pt[0];
f1.pt[1] = f->pt[1];
f1.pt[2] = f->pt[2];
f2.pt[0] = f->pt[0];
f2.pt[1] = f->pt[2];
f2.pt[2] = f->pt[3];
for ( i = 0 ; i < 2*disc ; i++,x += cote/disc ) {
float y = c->y+cote/disc/2;
for ( j = 0 ; j < disc ; j++,y += cote/disc ) {
rayon r;
r.o = *c;
r.d.x = x-c->x;
r.d.y = y-c->y;
r.d.z = z-c->z;
coord3D p = { x,y,z };
if ( testIntersectionRayonFacette(&f1,&r) ) {
ff += facteurElementaire(i,j,1,disc);
afficheElement(&p,1,cote,disc); }
else
if ( testIntersectionRayonFacette(&f2,&r) ) {
ff += facteurElementaire(i,j,1,disc);
afficheElement(&p,1,cote,disc); } } }
return(ff);
}
double afficheElementsDeDevant(facette4 *f,float cote,coord3D *c,int disc) {
int i,j;
double ff = 0.0;
float x = c->x-cote+cote/disc/2;
float z = c->z+cote;
facette3 f1;
facette3 f2;
f1.pt[0] = f->pt[0];
f1.pt[1] = f->pt[1];
f1.pt[2] = f->pt[2];
f2.pt[0] = f->pt[0];
f2.pt[1] = f->pt[2];
f2.pt[2] = f->pt[3];
for ( i = 0 ; i < 2*disc ; i++,x += cote/disc ) {
float y = c->y+cote/disc/2;
for ( j = 0 ; j < disc ; j++,y += cote/disc ) {
rayon r;
r.o = *c;
r.d.x = x-c->x;
r.d.y = y-c->y;
r.d.z = z-c->z;
coord3D p = { x,y,z };
if ( testIntersectionRayonFacette(&f1,&r) ) {
ff += facteurElementaire(i,j,1,disc);
afficheElement(&p,1,cote,disc); }
else
if ( testIntersectionRayonFacette(&f2,&r) ) {
ff += facteurElementaire(i,j,1,disc);
afficheElement(&p,1,cote,disc); } } }
return(ff);
}
double afficheElementsDeDroite(facette4 *f,float cote,coord3D *c,int disc) {
int i,j;
double ff = 0.0;
float x = c->x+cote;
float z = c->z-cote+cote/disc/2;
facette3 f1;
facette3 f2;
f1.pt[0] = f->pt[0];
f1.pt[1] = f->pt[1];
f1.pt[2] = f->pt[2];
f2.pt[0] = f->pt[0];
f2.pt[1] = f->pt[2];
f2.pt[2] = f->pt[3];
for ( i = 0 ; i < 2*disc ; i++,z += cote/disc ) {
float y = c->y+cote/disc/2;
for ( j = 0 ; j < disc ; j++,y += cote/disc ) {
rayon r;
r.o = *c;
r.d.x = x-c->x;
r.d.y = y-c->y;
r.d.z = z-c->z;
coord3D p = { x,y,z };
if ( testIntersectionRayonFacette(&f1,&r) ) {
ff += facteurElementaire(i,j,1,disc);
afficheElement(&p,2,cote,disc); }
else
if ( testIntersectionRayonFacette(&f2,&r) ) {
ff += facteurElementaire(i,j,1,disc);
afficheElement(&p,2,cote,disc); } } }
return(ff);
}
double afficheElementsDeGauche(facette4 *f,float cote,coord3D *c,int disc) {
int i,j;
double ff = 0.0;
float x = c->x-cote;
float z = c->z-cote+cote/disc/2;
facette3 f1;
facette3 f2;
f1.pt[0] = f->pt[0];
f1.pt[1] = f->pt[1];
f1.pt[2] = f->pt[2];
f2.pt[0] = f->pt[0];
f2.pt[1] = f->pt[2];
f2.pt[2] = f->pt[3];
for ( i = 0 ; i < 2*disc ; i++,z += cote/disc ) {
float y = c->y+cote/disc/2;
for ( j = 0 ; j < disc ; j++,y += cote/disc ) {
rayon r;
r.o = *c;
r.d.x = x-c->x;
r.d.y = y-c->y;
r.d.z = z-c->z;
coord3D p = { x,y,z };
if ( testIntersectionRayonFacette(&f1,&r) ) {
ff += facteurElementaire(i,j,1,disc);
afficheElement(&p,2,cote,disc); }
else
if ( testIntersectionRayonFacette(&f2,&r) ) {
ff += facteurElementaire(i,j,1,disc);
afficheElement(&p,2,cote,disc); } } }
return(ff);
}
void axes() {
setFont(GLUT_BITMAP_8_BY_13,CENTER);
glColor4fv(couleurRouge());
flecheEnVolume(1.0F,0.0F,0.0F,0.1F,0.3F,0.02F);
glColor4fv(couleurVert());
flecheEnVolume(0.0F,1.0F,0.0F,0.1F,0.3F,0.02F);
glColor4fv(couleurBleu());
flecheEnVolume(0.0F,0.0F,1.0F,0.1F,0.3F,0.02F);
glPushAttrib(GL_DEPTH_TEST);
glDisable(GL_DEPTH_TEST);
glColor4fv(couleurRougeFonce());
bitmapStringOutput(1.3F,0.0F,0.0F,"x");
glColor4fv(couleurVertFonce());
bitmapStringOutput(0.0F,1.3F,0.0F,"y");
glColor4fv(couleurBleuFonce());
bitmapStringOutput(0.0F,0.0F,1.3F,"z");
glPopAttrib();
}
void solidHemicube(double c,int n) {
glEnable(GL_LIGHTING);
glBegin(GL_QUADS);
glNormal3f(0.0F,1.0F,0.0F);
glVertex3f(c/2,c/2,c/2);
glVertex3f(c/2,c/2,-c/2);
glVertex3f(-c/2,c/2,-c/2);
glVertex3f(-c/2,c/2,c/2);
glEnd();
glBegin(GL_QUADS);
glNormal3f(1.0F,0.0F,0.0F);
glVertex3f(c/2,c/2,c/2);
glVertex3f(c/2,0.0F,c/2);
glVertex3f(c/2,0.0F,-c/2);
glVertex3f(c/2,c/2,-c/2);
glEnd();
glBegin(GL_QUADS);
glNormal3f(-1.0F,0.0F,0.0F);
glVertex3f(-c/2,c/2,-c/2);
glVertex3f(-c/2,0.0F,-c/2);
glVertex3f(-c/2,0.0F,c/2);
glVertex3f(-c/2,c/2,c/2);
glEnd();
glBegin(GL_QUADS);
glNormal3f(0.0F,0.0F,1.0F);
glVertex3f(-c/2,c/2,c/2);
glVertex3f(-c/2,0.0F,c/2);
glVertex3f(c/2,0.0F,c/2);
glVertex3f(c/2,c/2,c/2);
glEnd();
glBegin(GL_QUADS);
glNormal3f(0.0F,0.0F,-1.0F);
glVertex3f(c/2,c/2,-c/2);
glVertex3f(c/2,0.0F,-c/2);
glVertex3f(-c/2,0.0F,-c/2);
glVertex3f(-c/2,c/2,-c/2);
glEnd();
glDisable(GL_LIGHTING);
glClear(GL_DEPTH_BUFFER_BIT);
glColor4fv(couleurGrisFonce());
glBegin(GL_LINES);
glVertex3f(c/2,c/2,c/2);
glVertex3f(c/2,c/2,-c/2);
glVertex3f(c/2,c/2,-c/2);
glVertex3f(-c/2,c/2,-c/2);
glVertex3f(-c/2,c/2,-c/2);
glVertex3f(-c/2,c/2,c/2);
glVertex3f(-c/2,c/2,c/2);
glVertex3f(c/2,c/2,c/2);
glVertex3f(c/2,c/2,c/2);
glVertex3f(c/2,0.0F,c/2);
glVertex3f(-c/2,c/2,c/2);
glVertex3f(-c/2,0.0F,c/2);
glVertex3f(-c/2,c/2,-c/2);
glVertex3f(-c/2,0.0F,-c/2);
glVertex3f(c/2,c/2,-c/2);
glVertex3f(c/2,0.0F,-c/2);
glVertex3f(c/2,0.0F,c/2);
glVertex3f(c/2,0.0F,-c/2);
glVertex3f(c/2,0.0F,-c/2);
glVertex3f(-c/2,0.0F,-c/2);
glVertex3f(-c/2,0.0F,-c/2);
glVertex3f(-c/2,0.0F,c/2);
glVertex3f(-c/2,0.0F,c/2);
glVertex3f(c/2,0.0F,c/2);
glEnd();
int i;
glBegin(GL_LINES);
for ( i = 1 ; i < 2*n ; i++ ) {
glVertex3f(c/2,c/2,-c/2+i*c/2.0F/n);
glVertex3f(-c/2,c/2,-c/2+i*c/2.0F/n); }
for ( i = 1 ; i < 2*n ; i++ ) {
glVertex3f(-c/2+i*c/2.0F/n,c/2,c/2);
glVertex3f(-c/2+i*c/2.0F/n,c/2,-c/2); }
for ( i = 1 ; i < 2*n ; i++ ) {
glVertex3f(c/2,c/2,-c/2+i*c/2.0F/n);
glVertex3f(c/2,0.0F,-c/2+i*c/2.0F/n); }
for ( i = 1 ; i < 2*n ; i++ ) {
glVertex3f(-c/2,c/2,-c/2+i*c/2.0F/n);
glVertex3f(-c/2,0.0F,-c/2+i*c/2.0F/n); }
for ( i = 1 ; i < 2*n ; i++ ) {
glVertex3f(-c/2+i*c/2.0F/n,c/2,c/2);
glVertex3f(-c/2+i*c/2.0F/n,0.0F,c/2); }
for ( i = 1 ; i < 2*n ; i++ ) {
glVertex3f(-c/2+i*c/2.0F/n,c/2,-c/2);
glVertex3f(-c/2+i*c/2.0F/n,0.0F,-c/2); }
for ( i = 1 ; i < n ; i++ ) {
glVertex3f(-c/2,c/2-i*c/2.0F/n,-c/2);
glVertex3f(c/2,c/2-i*c/2.0F/n,-c/2); }
for ( i = 1 ; i < n ; i++ ) {
glVertex3f(-c/2,c/2-i*c/2.0F/n,c/2);
glVertex3f(c/2,c/2-i*c/2.0F/n,c/2); }
for ( i = 1 ; i < n ; i++ ) {
glVertex3f(-c/2,c/2-i*c/2.0F/n,-c/2);
glVertex3f(-c/2,c/2-i*c/2.0F/n,c/2); }
for ( i = 1 ; i < n ; i++ ) {
glVertex3f(c/2,c/2-i*c/2.0F/n,-c/2);
glVertex3f(c/2,c/2-i*c/2.0F/n,c/2); }
glEnd();
}
void solidBaseHemicube(double c) {
glEnable(GL_LIGHTING);
glBegin(GL_QUADS);
glNormal3f(0.0F,-1.0F,0.0F);
glVertex3f(c/2,0.0F,c/2);
glVertex3f(-c/2,0.0F,c/2);
glVertex3f(-c/2,0.0F,-c/2);
glVertex3f(c/2,0.0F,-c/2);
glEnd();
glDisable(GL_LIGHTING);
}
void axeDeProjectionSommets(facette4 *fj,coord3D *c1) {
glBegin(GL_LINES);
glVertex3fv((float *) c1);
glVertex3fv((float *) &fj->pt[0]);
glVertex3fv((float *) c1);
glVertex3fv((float *) &fj->pt[1]);
glVertex3fv((float *) c1);
glVertex3fv((float *) &fj->pt[2]);
glVertex3fv((float *) c1);
glVertex3fv((float *) &fj->pt[3]);
glEnd();
}
double afficheElementsFacetteSeule(facette4 *fj,float cote,coord3D *c1,int disc) {
afficheIntersection(&fj->pt[0],cote,c1);
afficheIntersection(&fj->pt[1],cote,c1);
afficheIntersection(&fj->pt[2],cote,c1);
afficheIntersection(&fj->pt[3],cote,c1);
double ff = 0.0F;
ff += afficheElementsDuDessus(fj,cote,c1,disc);
ff += afficheElementsDeDerriere(fj,cote,c1,disc);
ff += afficheElementsDeDevant(fj,cote,c1,disc);
ff += afficheElementsDeDroite(fj,cote,c1,disc);
ff += afficheElementsDeGauche(fj,cote,c1,disc);
return(ff);
}
int testIntersectionRayonFacetteDist(facette3 *f,rayon *r,float *dist) {
float x1 = f->pt[1].x-f->pt[0].x;
float y1 = f->pt[1].y-f->pt[0].y;
float z1 = f->pt[1].z-f->pt[0].z;
float x2 = f->pt[2].x-f->pt[0].x;
float y2 = f->pt[2].y-f->pt[0].y;
float z2 = f->pt[2].z-f->pt[0].z;
float x3 = r->d.x;
float y3 = r->d.y;
float z3 = r->d.z;
float dx = r->o.x - f->pt[0].x;
float dy = r->o.y - f->pt[0].y;
float dz = r->o.z - f->pt[0].z;
float d = z1*y3*x2-y1*z3*x2-x3*z1*y2-y3*x1*z2+z3*x1*y2+x3*y1*z2;
if ( d != 0.0F ) {
float v = -(-x3*y1*dz-z3*x1*dy+y1*z3*dx+x3*z1*dy+y3*x1*dz-z1*y3*dx)/d;
if ( v >= 0.0F ) {
float u = (-y3*dx*z2+y3*x2*dz-x2*z3*dy+dx*z3*y2-x3*y2*dz+x3*dy*z2)/d;
if ( ( u >= 0.0F ) && ( u+v <= 1.0F ) ) {
float t = -(-dx*z1*y2+dx*y1*z2+x1*y2*dz-x1*dy*z2-x2*y1*dz+x2*z1*dy)/d;
if ( t > 0.0F ) {
*dist = t ;
return(1); } } } }
return(0);
}
void decompositionFacette4(facette4 *f,facette3 *f1,facette3 *f2) {
f1->pt[0] = f->pt[0];
f1->pt[1] = f->pt[1];
f1->pt[2] = f->pt[2];
f2->pt[0] = f->pt[0];
f2->pt[1] = f->pt[2];
f2->pt[2] = f->pt[3];
}
void afficheElementsDuDessusAvecZBuffer(facette4 *fc1,float *c1,double *ff1,facette4 *fc2,float *c2,double *ff2,facette4 *fc3,float *c3,double *ff3,float cote,coord3D *c,int disc) {
int i,j;
float y = c->y+cote;
float x = c->x-cote+cote/disc/2;
facette3 f11;
facette3 f12;
decompositionFacette4(fc1,&f11,&f12);
facette3 f21;
facette3 f22;
decompositionFacette4(fc2,&f21,&f22);
facette3 f31;
facette3 f32;
decompositionFacette4(fc3,&f31,&f32);
for ( i = 0 ; i < 2*disc ; i++,x += cote/disc ) {
float z = c->z-cote+cote/disc/2;
for ( j = 0 ; j < 2*disc ; j++,z += cote/disc ) {
rayon r;
r.o = *c;
r.d.x = x-c->x;
r.d.y = y-c->y;
r.d.z = z-c->z;
coord3D p = { x,y,z };
float dist1 = 100000.0F,dist2 = 100000.0F,dist3 = 100000.0F;
int i1,i2,i3;
i1 = testIntersectionRayonFacetteDist(&f11,&r,&dist1);
if ( !i1 )
i1 = testIntersectionRayonFacetteDist(&f12,&r,&dist1);
i2 = testIntersectionRayonFacetteDist(&f21,&r,&dist2);
if ( !i2 )
i2 = testIntersectionRayonFacetteDist(&f22,&r,&dist2);
i3 = testIntersectionRayonFacetteDist(&f31,&r,&dist3);
if ( !i3 )
i3 = testIntersectionRayonFacetteDist(&f32,&r,&dist3);
if ( i1+i2+i3 != 0 ) {
if ( ( dist1 < dist2 ) && ( dist1 < dist3 ) ) {
*ff1 += facteurElementaire(i,j,0,disc);
glColor4fv(c1); }
else
if ( ( dist2 < dist3 ) && ( dist2 < dist1 ) ) {
*ff2 += facteurElementaire(i,j,0,disc);
glColor4fv(c2); }
else {
*ff3 += facteurElementaire(i,j,0,disc);
glColor4fv(c3); }
afficheElement(&p,0,cote,disc); } } }
}
void afficheElementsDeDroiteAvecZBuffer(facette4 *fc1,float *c1,double *ff1,facette4 *fc2,float *c2,double *ff2,facette4 *fc3,float *c3,double *ff3,float cote,coord3D *c,int disc) {
int i,j;
float x = c->x+cote;
float z = c->z-cote+cote/disc/2;
facette3 f11;
facette3 f12;
decompositionFacette4(fc1,&f11,&f12);
facette3 f21;
facette3 f22;
decompositionFacette4(fc2,&f21,&f22);
facette3 f31;
facette3 f32;
decompositionFacette4(fc3,&f31,&f32);
for ( i = 0 ; i < 2*disc ; i++,z += cote/disc ) {
float y = c->y+cote/disc/2;
for ( j = 0 ; j < disc ; j++,y += cote/disc ) {
rayon r;
r.o = *c;
r.d.x = x-c->x;
r.d.y = y-c->y;
r.d.z = z-c->z;
coord3D p = { x,y,z };
float dist1 = 100000.0F,dist2 = 100000.0F,dist3 = 100000.0F;
int i1,i2,i3;
i1 = testIntersectionRayonFacetteDist(&f11,&r,&dist1);
if ( !i1 )
i1 = testIntersectionRayonFacetteDist(&f12,&r,&dist1);
i2 = testIntersectionRayonFacetteDist(&f21,&r,&dist2);
if ( !i2 )
i2 = testIntersectionRayonFacetteDist(&f22,&r,&dist2);
i3 = testIntersectionRayonFacetteDist(&f31,&r,&dist3);
if ( !i3 )
i3 = testIntersectionRayonFacetteDist(&f32,&r,&dist3);
if ( i1+i2+i3 != 0 ) {
if ( ( dist1 < dist2 ) && ( dist1 < dist3 ) ) {
*ff1 += facteurElementaire(i,j,1,disc);
glColor4fv(c1); }
else
if ( ( dist2 < dist3 ) && ( dist2 < dist1 ) ) {
*ff2 += facteurElementaire(i,j,1,disc);
glColor4fv(c2); }
else {
*ff3 += facteurElementaire(i,j,1,disc);
glColor4fv(c3); }
afficheElement(&p,2,cote,disc); } } }
}
void afficheElementsDeGaucheAvecZBuffer(facette4 *fc1,float *c1,double *ff1,facette4 *fc2,float *c2,double *ff2,facette4 *fc3,float *c3,double *ff3,float cote,coord3D *c,int disc) {
int i,j;
float x = c->x-cote;
float z = c->z-cote+cote/disc/2;
facette3 f11;
facette3 f12;
decompositionFacette4(fc1,&f11,&f12);
facette3 f21;
facette3 f22;
decompositionFacette4(fc2,&f21,&f22);
facette3 f31;
facette3 f32;
decompositionFacette4(fc3,&f31,&f32);
for ( i = 0 ; i < 2*disc ; i++,z += cote/disc ) {
float y = c->y+cote/disc/2;
for ( j = 0 ; j < disc ; j++,y += cote/disc ) {
rayon r;
r.o = *c;
r.d.x = x-c->x;
r.d.y = y-c->y;
r.d.z = z-c->z;
coord3D p = { x,y,z };
float dist1 = 100000.0F,dist2 = 100000.0F,dist3 = 100000.0F;
int i1,i2,i3;
i1 = testIntersectionRayonFacetteDist(&f11,&r,&dist1);
if ( !i1 )
i1 = testIntersectionRayonFacetteDist(&f12,&r,&dist1);
i2 = testIntersectionRayonFacetteDist(&f21,&r,&dist2);
if ( !i2 )
i2 = testIntersectionRayonFacetteDist(&f22,&r,&dist2);
i3 = testIntersectionRayonFacetteDist(&f31,&r,&dist3);
if ( !i3 )
i3 = testIntersectionRayonFacetteDist(&f32,&r,&dist3);
if ( i1+i2+i3 != 0 ) {
if ( ( dist1 < dist2 ) && ( dist1 < dist3 ) ) {
*ff1 += facteurElementaire(i,j,1,disc);
glColor4fv(c1); }
else
if ( ( dist2 < dist3 ) && ( dist2 < dist1 ) ) {
*ff2 += facteurElementaire(i,j,1,disc);
glColor4fv(c2); }
else {
*ff3 += facteurElementaire(i,j,1,disc);
glColor4fv(c3); }
afficheElement(&p,2,cote,disc); } } }
}
void afficheElementsDeDevantAvecZBuffer(facette4 *fc1,float *c1,double *ff1,facette4 *fc2,float *c2,double *ff2,facette4 *fc3,float *c3,double *ff3,float cote,coord3D *c,int disc) {
int i,j;
float x = c->x-cote+cote/disc/2;
float z = c->z+cote;
facette3 f11;
facette3 f12;
decompositionFacette4(fc1,&f11,&f12);
facette3 f21;
facette3 f22;
decompositionFacette4(fc2,&f21,&f22);
facette3 f31;
facette3 f32;
decompositionFacette4(fc3,&f31,&f32);
for ( i = 0 ; i < 2*disc ; i++,x += cote/disc ) {
float y = c->y+cote/disc/2;
for ( j = 0 ; j < disc ; j++,y += cote/disc ) {
rayon r;
r.o = *c;
r.d.x = x-c->x;
r.d.y = y-c->y;
r.d.z = z-c->z;
coord3D p = { x,y,z };
float dist1 = 100000.0F,dist2 = 100000.0F,dist3 = 100000.0F;
int i1,i2,i3;
i1 = testIntersectionRayonFacetteDist(&f11,&r,&dist1);
if ( !i1 )
i1 = testIntersectionRayonFacetteDist(&f12,&r,&dist1);
i2 = testIntersectionRayonFacetteDist(&f21,&r,&dist2);
if ( !i2 )
i2 = testIntersectionRayonFacetteDist(&f22,&r,&dist2);
i3 = testIntersectionRayonFacetteDist(&f31,&r,&dist3);
if ( !i3 )
i3 = testIntersectionRayonFacetteDist(&f32,&r,&dist3);
if ( i1+i2+i3 != 0 ) {
if ( ( dist1 < dist2 ) && ( dist1 < dist3 ) ) {
*ff1 += facteurElementaire(i,j,1,disc);
glColor4fv(c1); }
else
if ( ( dist2 < dist3 ) && ( dist2 < dist1 ) ) {
*ff2 += facteurElementaire(i,j,1,disc);
glColor4fv(c2); }
else {
*ff3 += facteurElementaire(i,j,1,disc);
glColor4fv(c3); }
afficheElement(&p,1,cote,disc); } } }
}
void afficheElementsDeDerriereAvecZBuffer(facette4 *fc1,float *c1,double *ff1,facette4 *fc2,float *c2,double *ff2,facette4 *fc3,float *c3,double *ff3,float cote,coord3D *c,int disc) {
int i,j;
float x = c->x-cote+cote/disc/2;
float z = c->z-cote;
facette3 f11;
facette3 f12;
decompositionFacette4(fc1,&f11,&f12);
facette3 f21;
facette3 f22;
decompositionFacette4(fc2,&f21,&f22);
facette3 f31;
facette3 f32;
decompositionFacette4(fc3,&f31,&f32);
for ( i = 0 ; i < 2*disc ; i++,x += cote/disc ) {
float y = c->y+cote/disc/2;
for ( j = 0 ; j < disc ; j++,y += cote/disc ) {
rayon r;
r.o = *c;
r.d.x = x-c->x;
r.d.y = y-c->y;
r.d.z = z-c->z;
coord3D p = { x,y,z };
float dist1 = 100000.0F,dist2 = 100000.0F,dist3 = 100000.0F;
int i1,i2,i3;
i1 = testIntersectionRayonFacetteDist(&f11,&r,&dist1);
if ( !i1 )
i1 = testIntersectionRayonFacetteDist(&f12,&r,&dist1);
i2 = testIntersectionRayonFacetteDist(&f21,&r,&dist2);
if ( !i2 )
i2 = testIntersectionRayonFacetteDist(&f22,&r,&dist2);
i3 = testIntersectionRayonFacetteDist(&f31,&r,&dist3);
if ( !i3 )
i3 = testIntersectionRayonFacetteDist(&f32,&r,&dist3);
if ( i1+i2+i3 != 0 ) {
if ( ( dist1 < dist2 ) && ( dist1 < dist3 ) ) {
*ff1 += facteurElementaire(i,j,1,disc);
glColor4fv(c1); }
else
if ( ( dist2 < dist3 ) && ( dist2 < dist1 ) ) {
*ff2 += facteurElementaire(i,j,1,disc);
glColor4fv(c2); }
else {
*ff3 += facteurElementaire(i,j,1,disc);
glColor4fv(c3); }
afficheElement(&p,1,cote,disc); } } }
}
void afficheElementsFacettes(facette4 *fj1,float *c1,double *ff1,facette4 *fj2,float *c2,double *ff2,facette4 *fj3,float *c3,double *ff3,float cote,coord3D *c,int disc) {
afficheIntersection(&fj1->pt[0],cote,c);
afficheIntersection(&fj1->pt[1],cote,c);
afficheIntersection(&fj1->pt[2],cote,c);
afficheIntersection(&fj1->pt[3],cote,c);
afficheIntersection(&fj2->pt[0],cote,c);
afficheIntersection(&fj2->pt[1],cote,c);
afficheIntersection(&fj2->pt[2],cote,c);
afficheIntersection(&fj2->pt[3],cote,c);
afficheIntersection(&fj3->pt[0],cote,c);
afficheIntersection(&fj3->pt[1],cote,c);
afficheIntersection(&fj3->pt[2],cote,c);
afficheIntersection(&fj3->pt[3],cote,c);
afficheElementsDuDessusAvecZBuffer(fj1,c1,ff1,fj2,c2,ff2,fj3,c3,ff3,cote,c,disc);
afficheElementsDeDerriereAvecZBuffer(fj1,c1,ff1,fj2,c2,ff2,fj3,c3,ff3,cote,c,disc);
afficheElementsDeDevantAvecZBuffer(fj1,c1,ff1,fj2,c2,ff2,fj3,c3,ff3,cote,c,disc);
afficheElementsDeDroiteAvecZBuffer(fj1,c1,ff1,fj2,c2,ff2,fj3,c3,ff3,cote,c,disc);
afficheElementsDeGaucheAvecZBuffer(fj1,c1,ff1,fj2,c2,ff2,fj3,c3,ff3,cote,c,disc);
}
void display(void) {
ff = 0.0;
ff1 = 0.0;
ff2 = 0.0;
ff3 = 0.0;
direc3D n1;
coord3D c1;
normale(&fi,&n1);
centre(&fi,&c1);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
glClear(GL_DEPTH_BUFFER_BIT);
glColor4fv(couleurCyan(0.3F));
traceFacette4(GL_QUADS,&fi);
glColor4fv(couleurCyan(0.5F));
traceFacette4(GL_LINE_LOOP,&fi);
glClear(GL_DEPTH_BUFFER_BIT);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurVertFonce(0.4F));
glPushMatrix();
glTranslatef(c1.x,c1.y,c1.z);
glEnable(GL_CULL_FACE);
solidHemicube(cote*2,disc);
solidBaseHemicube(cote*2);
glDisable(GL_CULL_FACE);
glPopMatrix();
glClear(GL_DEPTH_BUFFER_BIT);
{ glColor4fv(couleurRoseFonce(0.4F));
direc3D d1;
direc3D d2;
vecteursOrthogonaux(&n1,&d1,&d2);
glBegin(GL_POLYGON);
glVertex3f(c1.x+d1.x/2+d2.x/2,c1.y+d1.y/2+d2.y/2,c1.z+d1.z/2+d2.z/2);
glVertex3f(c1.x+d1.x/2-d2.x/2,c1.y+d1.y/2-d2.y/2,c1.z+d1.z/2-d2.z/2);
glVertex3f(c1.x-d1.x/2-d2.x/2,c1.y-d1.y/2-d2.y/2,c1.z-d1.z/2-d2.z/2);
glVertex3f(c1.x-d1.x/2+d2.x/2,c1.y-d1.y/2+d2.y/2,c1.z-d1.z/2+d2.z/2);
glEnd(); }
glClear(GL_DEPTH_BUFFER_BIT);
glColor4fv(couleurBleuCiel(0.4F));
traceFacette4(GL_QUADS,&fj1);
glColor4fv(couleurJauneClair(0.4F));
traceFacette4(GL_QUADS,&fj2);
glColor4fv(couleurRose(0.4F));
traceFacette4(GL_QUADS,&fj3);
glClear(GL_DEPTH_BUFFER_BIT);
{ glColor4fv(couleurCyanFonce());
setAlignement(CENTER);
coord3D cc;
centrePondere(&fi,&cc,1.0F,1.0F,12.0F,1.0F);
placeFontCursor(cc.x,cc.y,cc.z) ;
simpleBitmapOutput(REGULAR8x13,"A") ;
deplacementCursor(8,3,0) ;
simpleBitmapOutput(REGULAR6x10,"i") ; }
{ glColor4fv(couleurRougeFonce());
setAlignement(CENTER);
coord3D cc;
centrePondere(&fi,&cc,1.0F,1.0F,2.0F,1.0F);
placeFontCursor(cc.x,cc.y,cc.z) ;
simpleBitmapOutput(REGULAR8x13,"dA") ;
deplacementCursor(12,3,0) ;
simpleBitmapOutput(REGULAR6x10,"i") ; }
glColor4fv(couleurBleu());
traceFacette4(GL_LINE_LOOP,&fj1);
glColor4fv(couleurJaune());
traceFacette4(GL_LINE_LOOP,&fj2);
glColor4fv(couleurRouge());
traceFacette4(GL_LINE_LOOP,&fj3);
{ glColor4fv(couleurRouge());
glPushMatrix();
glTranslatef(c1.x,c1.y,c1.z);
flecheEnVolume(n1.x*cote,n1.y*cote,n1.z*cote,0.1F,0.3F,0.02F);
glPopMatrix();
glColor4fv(couleurRougeFonce());
setAlignement(LEFT);
placeFontCursor(c1.x+n1.x*2.5,c1.y+n1.y*2.5,c1.z+n1.z*2.5) ;
deplacementCursor(5,0,0) ;
simpleBitmapOutput(REGULAR8x13,"N") ;
deplacementCursor(15,0,0) ;
simpleBitmapOutput(REGULAR6x10,"i") ;
deplacementCursor(4,-5,0) ;
simpleBitmapOutput(DESSIN,"TF") ; }
{ glColor4fv(couleurBleuFonce());
setAlignement(CENTER);
coord3D cc;
centrePondere(&fj1,&cc,8.0F,1.0F,1.0F,1.0F);
placeFontCursor(cc.x,cc.y,cc.z) ;
simpleBitmapOutput(REGULAR8x13,"A") ;
deplacementCursor(8,3,0) ;
simpleBitmapOutput(REGULAR6x10,"j") ; }
{ glColor4fv(couleurJauneFonce());
setAlignement(CENTER);
coord3D cc;
centrePondere(&fj2,&cc,8.0F,1.0F,1.0F,1.0F);
placeFontCursor(cc.x,cc.y,cc.z) ;
simpleBitmapOutput(REGULAR8x13,"A") ;
deplacementCursor(8,3,0) ;
simpleBitmapOutput(REGULAR6x10,"k") ; }
{ glColor4fv(couleurRougeFonce());
setAlignement(CENTER);
coord3D cc;
centrePondere(&fj3,&cc,8.0F,1.0F,1.0F,1.0F);
placeFontCursor(cc.x,cc.y,cc.z) ;
simpleBitmapOutput(REGULAR8x13,"A") ;
deplacementCursor(8,3,0) ;
simpleBitmapOutput(REGULAR6x10,"l") ; }
{ glColor4fv(couleurRougeFonce());
direc3D d1;
direc3D d2;
vecteursOrthogonaux(&n1,&d1,&d2);
glBegin(GL_LINE_LOOP);
glVertex3f(c1.x+d1.x/2+d2.x/2,c1.y+d1.y/2+d2.y/2,c1.z+d1.z/2+d2.z/2);
glVertex3f(c1.x+d1.x/2-d2.x/2,c1.y+d1.y/2-d2.y/2,c1.z+d1.z/2-d2.z/2);
glVertex3f(c1.x-d1.x/2-d2.x/2,c1.y-d1.y/2-d2.y/2,c1.z-d1.z/2-d2.z/2);
glVertex3f(c1.x-d1.x/2+d2.x/2,c1.y-d1.y/2+d2.y/2,c1.z-d1.z/2+d2.z/2);
glEnd(); }
{ glColor4fv(couleurBleu());
axeDeProjectionSommets(&fj1,&c1) ;
glColor4fv(couleurJaune());
axeDeProjectionSommets(&fj2,&c1) ;
glColor4fv(couleurRouge());
axeDeProjectionSommets(&fj3,&c1) ; }
if ( aff == 3 ) {
afficheElementsFacettes(&fj1,couleurBleuCielFonce(0.4F),&ff1,&fj2,couleurJauneClair(0.4F),&ff2,&fj3,couleurRoseFonce(0.4F),&ff3,cote,&c1,disc); }
else {
switch ( aff ) {
case 0 : glColor4fv(couleurBleuCielFonce(0.4F));
break;
case 1 : glColor4fv(couleurJauneClair(0.4F));
break;
case 2 : glColor4fv(couleurRoseFonce(0.4F));
break; }
ff = afficheElementsFacetteSeule(fj,cote,&c1,disc); }
glClear(GL_DEPTH_BUFFER_BIT);
{ glPushMatrix();
glTranslatef(4.5F,1.0F,5.5F);
axes();
glPopMatrix(); }
glPopMatrix();
glFlush();
glutSwapBuffers();
glutPostWindowRedisplay(f2);
}
void key2(unsigned char key,int x,int y) {
switch ( key ) {
case 'a' : fj->pt[0].x += 0.1F ;
fj->pt[1].x += 0.1F ;
fj->pt[2].x += 0.1F ;
fj->pt[3].x += 0.1F ;
glutPostWindowRedisplay(f1);
break;
case 'A' : fj->pt[0].x -= 0.1F ;
fj->pt[1].x -= 0.1F ;
fj->pt[2].x -= 0.1F ;
fj->pt[3].x -= 0.1F ;
glutPostWindowRedisplay(f1);
break;
case 'b' : fj->pt[0].y += 0.1F ;
fj->pt[1].y += 0.1F ;
fj->pt[2].y += 0.1F ;
fj->pt[3].y += 0.1F ;
glutPostWindowRedisplay(f1);
break;
case 'B' : fj->pt[0].y -= 0.1F ;
fj->pt[1].y -= 0.1F ;
fj->pt[2].y -= 0.1F ;
fj->pt[3].y -= 0.1F ;
glutPostWindowRedisplay(f1);
break;
case 'c' : fj->pt[0].z += 0.1F ;
fj->pt[1].z += 0.1F ;
fj->pt[2].z += 0.1F ;
fj->pt[3].z += 0.1F ;
glutPostWindowRedisplay(f1);
break;
case 'C' : fj->pt[0].z -= 0.1F ;
fj->pt[1].z -= 0.1F ;
fj->pt[2].z -= 0.1F ;
fj->pt[3].z -= 0.1F ;
glutPostWindowRedisplay(f1);
break;
case 43 : liberationFacteursElementaires(disc,fe);
disc++ ;
fe = calculFacteursElementaires(disc);
totfe = sommeTotaleFacteursElementaires(disc,fe);
glutPostWindowRedisplay(f1);
break;
case 45 : liberationFacteursElementaires(disc,fe);
disc-- ;
if ( disc < 2 )
disc = 2 ;
fe = calculFacteursElementaires(disc);
totfe = sommeTotaleFacteursElementaires(disc,fe);
glutPostWindowRedisplay(f1);
break;
case 0x0D : fac = (fac+1)%3 ;
switch ( fac ) {
case 0 : fj = &fj1 ;
break;
case 1 : fj = &fj2 ;
break;
case 2 : fj = &fj3 ;
break; }
glutPostWindowRedisplay(f1);
break;
case 32 : aff = (aff+1)%4 ;
switch ( aff ) {
case 0 : fj = &fj1 ;
break;
case 1 : fj = &fj2 ;
break;
case 2 : fj = &fj3 ;
break; }
glutPostWindowRedisplay(f1);
break;
case 0x1B : exit(0);
break; }
}
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostWindowRedisplay(f1);
else
key2(key,x,y);
}
void special(int key,int x,int y) {
if ( specialManipulateur(key,x,y) ) {
glutPostWindowRedisplay(f1); }
}
void reshape2(int w,int h) {
glViewport(0,0,w,h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0,w,-h,0,-1.0,1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void display2() {
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glClearColor(0.0F,0.0F,0.0F,1.0F) ;
glPushMatrix();
float pos = 1.0F;
glColor4fv(couleurBlanc());
setAlignement(LEFT);
if ( aff == 3 ) {
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"Facette j : %10.8lf",ff1) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"Facette k : %10.8lf",ff2) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"Facette l : %10.8lf",ff3) ;
pos += 1.0F; }
else {
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"Facteur de forme : %10.8lf",ff) ;
pos += 1.0F; }
glPopMatrix();
glFlush();
glutSwapBuffers();
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
glutInitWindowPosition(10,10);
glutInitWindowSize(400,300);
f1 = glutCreateWindow("ZBuffer sur hemicube en radiosite");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-7.5,7.5,-7.5,7.5,-100.0,100.0);
setManipulateurDistance(1.0F);
setManipulateurClavierAngle(30.0F,-120.0F,0.0F) ;
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutInitWindowSize(310,70);
glutInitWindowPosition(40,360);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
f2 = glutCreateWindow("Valeurs");
creationMenuBasique();
glutDisplayFunc(display2);
glutReshapeFunc(reshape2);
glutKeyboardFunc(key2);
glutSpecialFunc(special);
glutMainLoop();
return(0);
}
/* ************************************************** */