Le source: SchemaRadiosite.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Juin 2001 */
/* Facteur de forme en radiosite */
#include <stdio.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] ; } ;
static facette4 f1 = { {{ -5.0F,-3.0F,-3.0F },
{ -4.0F,-3.5F,4.0F },
{ 1.0F,-4.5F,3.0F },
{ 3.0F,-4.75F,-1.0F }} };
static facette4 f2 = { {{ 4.5F,-0.0F,-3.5F },
{ 2.0F,3.0F,-3.0F },
{ -2.0F,4.0F,-3.0F },
{ -1.0F,-1.0F,-4.0F }} };
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 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);
}
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();
}
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 display(void) {
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
direc3D n1;
direc3D n2;
coord3D c1;
coord3D c2;
normale(&f1,&n1);
normale(&f2,&n2);
centre(&f1,&c1);
centre(&f2,&c2);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
glColor4fv(couleurRose(0.4F));
traceFacette4(GL_QUADS,&f1);
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,&f2);
glClear(GL_DEPTH_BUFFER_BIT);
{ glColor4fv(couleurBleuCielFonce(0.4F));
direc3D d1;
direc3D d2;
vecteursOrthogonaux(&n2,&d1,&d2);
glBegin(GL_POLYGON);
glVertex3f(c2.x+d1.x/2+d2.x/2,c2.y+d1.y/2+d2.y/2,c2.z+d1.z/2+d2.z/2);
glVertex3f(c2.x+d1.x/2-d2.x/2,c2.y+d1.y/2-d2.y/2,c2.z+d1.z/2-d2.z/2);
glVertex3f(c2.x-d1.x/2-d2.x/2,c2.y-d1.y/2-d2.y/2,c2.z-d1.z/2-d2.z/2);
glVertex3f(c2.x-d1.x/2+d2.x/2,c2.y-d1.y/2+d2.y/2,c2.z-d1.z/2+d2.z/2);
glEnd(); }
glClear(GL_DEPTH_BUFFER_BIT);
glColor4fv(couleurRouge());
traceFacette4(GL_LINE_LOOP,&f1);
{ glColor4fv(couleurRougeFonce());
setAlignement(CENTER);
coord3D cc;
centrePondere(&f1,&cc,1.0F,1.0F,1.0F,8.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(&f1,&cc,1.0F,1.0F,4.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,&f2);
{ glColor4fv(couleurBleuFonce());
setAlignement(CENTER);
coord3D cc;
centrePondere(&f2,&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(couleurBleuFonce());
setAlignement(CENTER);
coord3D cc;
centrePondere(&f2,&cc,1.0F,1.0F,1.0F,4.0F);
placeFontCursor(cc.x,cc.y,cc.z) ;
simpleBitmapOutput(REGULAR8x13,"dA") ;
deplacementCursor(12,3,0) ;
simpleBitmapOutput(REGULAR6x10,"j") ; }
{ 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(couleurBleuFonce());
direc3D d1;
direc3D d2;
vecteursOrthogonaux(&n2,&d1,&d2);
glBegin(GL_LINE_LOOP);
glVertex3f(c2.x+d1.x/2+d2.x/2,c2.y+d1.y/2+d2.y/2,c2.z+d1.z/2+d2.z/2);
glVertex3f(c2.x+d1.x/2-d2.x/2,c2.y+d1.y/2-d2.y/2,c2.z+d1.z/2-d2.z/2);
glVertex3f(c2.x-d1.x/2-d2.x/2,c2.y-d1.y/2-d2.y/2,c2.z-d1.z/2-d2.z/2);
glVertex3f(c2.x-d1.x/2+d2.x/2,c2.y-d1.y/2+d2.y/2,c2.z-d1.z/2+d2.z/2);
glEnd(); }
glColor4fv(couleurNoir());
glBegin(GL_LINES);
glVertex3fv((float *) &c1);
glVertex3fv((float *) &c2);
glEnd();
coord3D c;
direc3D d;
c.x = (c1.x+c2.x)/2;
c.y = (c1.y+c2.y)/2;
c.z = (c1.z+c2.z)/2;
d.x = c1.x - c2.x;
d.y = c1.y - c2.y;
d.z = c1.z - c2.z;
{ setAlignement(CENTER);
placeFontCursor(c.x-c.y/3,c.y+c.x/3,c.z) ;
simpleBitmapOutput(REGULAR8x13,"r") ;
glPushMatrix();
glTranslatef(c.x-c.y/3+d.x/20,c.y+c.x/3+d.y/20,c.z+d.z/20) ;
flecheEnFilaire(d.x/5,d.y/5,d.z/5,0.08F,0.2F);
glPopMatrix();
glPushMatrix();
glTranslatef(c.x-c.y/3-d.x/20,c.y+c.x/3-d.y/20,c.z-d.z/20) ;
flecheEnFilaire(-d.x/5,-d.y/5,-d.z/5,0.08F,0.2F);
glPopMatrix(); }
{ setAlignement(CENTER);
coord3D ct;
ct.x = c1.x+(n1.x*1.5-d.x/4)/2;
ct.y = c1.y+(n1.y*1.5-d.y/4)/2;
ct.z = c1.z+(n1.z*1.5-d.z/4)/2;
placeFontCursor(ct.x,ct.y,ct.z) ;
deplacementCursor(-2,-2,0) ;
simpleBitmapOutput(SYMBOL,"q") ;
deplacementCursor(4,1,0) ;
simpleBitmapOutput(REGULAR6x10,"i") ; }
{ setAlignement(CENTER);
coord3D ct;
ct.x = c2.x+(n2.x*2+d.x/3)/2;
ct.y = c2.y+(n2.y*2+d.y/3)/2;
ct.z = c2.z+(n2.z*2+d.z/3)/2;
placeFontCursor(ct.x,ct.y,ct.z) ;
deplacementCursor(-2,-2,0) ;
simpleBitmapOutput(SYMBOL,"q") ;
deplacementCursor(4,1,0) ;
simpleBitmapOutput(REGULAR6x10,"j") ; }
{ glColor4fv(couleurRouge());
glPushMatrix();
glTranslatef(c1.x,c1.y,c1.z);
flecheEnVolume(n1.x*3,n1.y*3,n1.z*3,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,3,0) ;
simpleBitmapOutput(REGULAR6x10,"i") ;
deplacementCursor(4,-5,0) ;
simpleBitmapOutput(DESSIN,"TF") ; }
{ glColor4fv(couleurBleu());
glPushMatrix();
glTranslatef(c2.x,c2.y,c2.z);
flecheEnVolume(n2.x*3,n2.y*3,n2.z*3,0.1F,0.3F,0.02F);
glPopMatrix();
glColor4fv(couleurBleuFonce());
setAlignement(LEFT);
placeFontCursor(c2.x+n2.x*3,c2.y+n2.y*3,c2.z+n2.z*3) ;
deplacementCursor(5,-13,0) ;
simpleBitmapOutput(REGULAR8x13,"N") ;
deplacementCursor(15,-10,0) ;
simpleBitmapOutput(REGULAR6x10,"j") ;
deplacementCursor(4,-18,0) ;
simpleBitmapOutput(DESSIN,"TF") ; }
{ glPushMatrix();
glTranslatef(-4.5F,3.0F,1.5F);
axes();
glPopMatrix(); }
glPopMatrix();
glFlush();
glutSwapBuffers();
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
glutInitWindowPosition(10,10);
glutInitWindowSize(300,300);
glutCreateWindow("Facteur de forme 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(keyBasique);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}
/* ************************************************** */