/* Auteur: Nicolas JANEY */ /* nicolas.janey@univ-fcomte.fr */ /* Juin 2001 */ /* L'Hemicube en radiosite */ #include #include #include #include #include #include #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 double ff = 0.0; static int f1; static int f2; static int aff = 0; static float cote = 4.0F; static int disc = 20; 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 = { {{ 4.5F,-0.0F,-5.5F }, { 2.0F,3.0F,-5.0F }, { -2.0F,4.0F,-5.0F }, { -1.0F,-1.0F,-6.0F }} }; static facette4 fj2 = { {{ 3.5F,2.0F,2.5F }, { 2.0F,2.0F,-3.0F }, { -2.0F,2.0F,-3.5F }, { -1.0F,2.0F,3.0F }} }; static facette4 fj3 = { {{ 7.5F,2.0F,6.5F }, { 8.0F,2.0F,-7.0F }, { -6.0F,2.0F,-8.5F }, { -5.0F,2.0F,7.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) { glColor4fv(couleurBleuCielFonce(0.4F)); 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 display(void) { direc3D n1; direc3D n2; coord3D c1; coord3D c2; normale(&fi,&n1); normale(&fj,&n2); centre(&fi,&c1); centre(&fj,&c2); glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); manipulateurSouris(); manipulateurClavier(); 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); glClear(GL_DEPTH_BUFFER_BIT); glPopMatrix(); glColor4fv(couleurRose(0.4F)); traceFacette4(GL_QUADS,&fi); 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,&fj); glClear(GL_DEPTH_BUFFER_BIT); glColor4fv(couleurRouge(0.8F)); traceFacette4(GL_LINE_LOOP,&fi); { glColor4fv(couleurRougeFonce(0.8F)); setAlignement(CENTER); coord3D cc; centrePondere(&fi,&cc,1.0F,12.0F,1.0F,1.0F); placeFontCursor(cc.x,cc.y,cc.z) ; simpleBitmapOutput(REGULAR8x13,"A") ; deplacementCursor(8,3,0) ; simpleBitmapOutput(REGULAR6x10,"i") ; } { glColor4fv(couleurRougeFonce(0.8F)); 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,&fj); { glColor4fv(couleurBleuFonce()); setAlignement(CENTER); coord3D cc; centrePondere(&fj,&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(couleurRougeFonce(0.8F)); 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()); 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(); } afficheIntersection(&fj.pt[0],cote,&c1); afficheIntersection(&fj.pt[1],cote,&c1); afficheIntersection(&fj.pt[2],cote,&c1); afficheIntersection(&fj.pt[3],cote,&c1); glColor4fv(couleurBleuCielFonce(0.4F)); 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); glClear(GL_DEPTH_BUFFER_BIT); glColor4fv(couleurNoir()); glBegin(GL_LINES); glVertex3fv((float *) &c1); glVertex3fv((float *) &c2); glEnd(); { 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(0.8F)); 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,3,0) ; simpleBitmapOutput(REGULAR6x10,"i") ; deplacementCursor(4,-5,0) ; simpleBitmapOutput(DESSIN,"TF") ; } { glPushMatrix(); glTranslatef(-4.5F,2.0F,1.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 32 : aff = (aff+1)%3 ; 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); 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("L'Hemicube en radiosite"); myinit(); creationMenuBasique(); setParametresOrthoBasique(-6.0,6.0,-6.0,6.0,-500.0,500.0); setManipulateurDistance(1.0F); setManipulateurClavierAngle(20.0F,-60.0F,0.0F) ; glutReshapeFunc(reshapeOrthoBasique); glutKeyboardFunc(key); glutSpecialFunc(specialBasique); glutMotionFunc(motionBasique); glutMouseFunc(sourisBasique); glutDisplayFunc(display); glutInitWindowSize(310,30); 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); } /* ************************************************** */