Objet.h | Vecteur.h | Position.h | Direction.h |
Objet.cpp | Vecteur.cpp | Position.cpp | Direction.cpp |
Une droite est caractérisée par la donnée:
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Octobre 2005 */
/* Classe de gestion de droites 3D */
#ifndef DROITE
#define DROITE
#include "Objet.h"
#include "Position.h"
#include "Direction.h"
class Droite : public Objet {
public :
Position *p;
Direction *d;
public :
Droite(void);
Droite(float x,float y,float z,float dx,float dy,float dz);
Droite(Position *p,Direction *d);
~Droite(void);
Position *position(float t);
void dessine(void);
void dessine(float *c);
void print(char *format);
};
#endif
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Octobre 2005 */
/* Classe de gestion de surfaces */
/* spheriques */
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleFont.h"
#include "Droite.h"
Droite::Droite(void) {
p = new Position();
d = new Direction();
}
Droite::Droite(float x,float y,float z,
float dx,float dy,float dz) {
p = new Position(x,y,z);
d = new Direction(dx,dy,dz);
}
Droite::Droite(Position *p,Direction *d) {
this->p = new Position(p);
this->d = new Direction(d);
}
Droite::~Droite(void) {
delete(p);
delete(d);
}
Position *Droite::position(float t) {
Position *np = new Position();
np->x = p->x + t*d->x;
np->y = p->y + t*d->y;
np->z = p->z + t*d->z;
return(np);
}
void Droite::dessine(void) {
glPushMatrix();
glTranslatef(p->x,p->y,p->z);
glutSolidSphere(0.1,36,36);
glBegin(GL_LINES);
glVertex3f(d->x*100.0F,d->y*100.0F,d->z*100.0F);
glVertex3f(-d->x*100.0F,-d->y*100.0F,-d->z*100.0F);
glEnd();
glPopMatrix();
}
void Droite::dessine(float *c) {
int l = glIsEnabled(GL_LIGHTING);
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushMatrix();
glTranslatef(p->x,p->y,p->z);
glEnable(GL_LIGHTING);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,c);
glutSolidSphere(0.1,36,36);
glDisable(GL_LIGHTING);
glColor3fv(c);
glBegin(GL_LINES);
glVertex3f(d->x*100.0F,d->y*100.0F,d->z*100.0F);
glVertex3f(-d->x*100.0F,-d->y*100.0F,-d->z*100.0F);
glEnd();
glPopMatrix();
if ( l )
glEnable(GL_LIGHTING);
else
glDisable(GL_LIGHTING);
glPopAttrib();
}
void Droite::print(char *format) {
simpleBitmapOutput(1,REGULAR8x13,format,
p->x,p->y,p->z,d->x,d->y,d->z);
}
Un rayon lumineux dérive directement d'une droite. La position est le point d'émission. La direction est la direction d'émission. Cette direction est normée. Mathématiquement, un rayon est une 1/2 droite.
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Octobre 2005 */
/* Classe de gestion de rayons lumineux */
#ifndef RAYON
#define RAYON
#include "Droite.h"
class Rayon : public Droite {
public :
Rayon(void);
Rayon(float x,float y,float z,float dx,float dy,float dz);
Rayon(Position *p,Direction *d);
~Rayon(void);
void dessine(void);
void dessine(float *c);
};
#endif
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Octobre 2005 */
/* Classe de gestion de rayons lumineux */
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleFleche.h"
#include "Rayon.h"
Rayon::Rayon(void) : Droite() {
}
Rayon::Rayon(float x,float y,float z,
float dx,float dy,float dz) : Droite(x,y,z,dx,dy,dz) {
this->d->normalise();
}
Rayon::Rayon(Position *p,Direction *d) : Droite(p,d) {
this->d->normalise();
}
Rayon::~Rayon(void) {
}
void Rayon::dessine(void) {
glPushMatrix();
glTranslatef(p->x,p->y,p->z);
glutSolidSphere(0.1,36,36);
flecheEnVolume(d->x,d->y,d->z,0.1F,0.4F,0.03F);
glBegin(GL_LINES);
glVertex3f(d->x*100.0F,d->y*100.0F,d->z*100.0F);
glVertex3f(-d->x*100.0F,-d->y*100.0F,-d->z*100.0F);
glEnd();
glPopMatrix();
}
void Rayon::dessine(float *c) {
int l = glIsEnabled(GL_LIGHTING);
glPushAttrib(GL_ALL_ATTRIB_BITS);
glPushMatrix();
glTranslatef(p->x,p->y,p->z);
glEnable(GL_LIGHTING);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,c);
glutSolidSphere(0.1,36,36);
flecheEnVolume(d->x,d->y,d->z,0.1F,0.4F,0.03F);
glDisable(GL_LIGHTING);
glColor3fv(c);
glBegin(GL_LINES);
glVertex3f(d->x*100.0F,d->y*100.0F,d->z*100.0F);
glVertex3f(0.0F,0.0F,0.0F);
glEnd();
glPopMatrix();
if ( l )
glEnable(GL_LIGHTING);
else
glDisable(GL_LIGHTING);
glPopAttrib();
}
Une sphère est caractérisée par la donnée:
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Octobre 2005 */
/* Classe de gestion de surfaces */
/* spheriques */
#ifndef SPHERE
#define SPHERE
#include "Objet.h"
#include "Position.h"
#include "Droite.h"
#include "Rayon.h"
class Sphere : public Objet {
public :
Position *centre;
float rayon;
public :
Sphere(void);
Sphere(float x,float y,float z,float r);
Sphere(Position *p,float r);
~Sphere(void);
int testIntersection(Droite *d);
Position **intersection(Droite *d);
int testIntersection(Rayon *r);
Position *intersection(Rayon *r);
void dessine(void);
void print(char *format);
};
#endif
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Octobre 2005 */
/* Classe de gestion de surfaces */
/* spheriques */
#include <math.h>
#include <stdlib.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "ModuleFont.h"
#include "Sphere.h"
#include "Droite.h"
#include "Rayon.h"
Sphere::Sphere(void) {
centre = new Position();
rayon = 1.0F;
}
Sphere::Sphere(float x,float y,float z,float r) {
centre = new Position(x,y,z);
rayon = r;
}
Sphere::Sphere(Position *p,float r) {
centre = new Position(p);
rayon = r;
}
Sphere::~Sphere(void) {
delete(centre);
}
static float vmin(float a,float b) {
return(( a < b ) ? a : b);
}
static float vmax(float a,float b) {
return(( a > b ) ? a : b);
}
int Sphere::testIntersection(Droite *d) {
float a = d->d->x*d->d->x+
d->d->y*d->d->y+
d->d->z*d->d->z;
float b = 2*(d->d->x*(d->p->x-centre->x)+
d->d->y*(d->p->y-centre->y)+
d->d->z*(d->p->z-centre->z));
float c = (d->p->x-centre->x)*(d->p->x-centre->x)+
(d->p->y-centre->y)*(d->p->y-centre->y)+
(d->p->z-centre->z)*(d->p->z-centre->z)-
rayon*rayon;
float delta = b*b-4*a*c;
if ( fabs(delta) < 0.0001F )
return(1);
if ( delta < 0.0F )
return(0);
return(2);
}
Position **Sphere::intersection(Droite *d) {
float a = d->d->x*d->d->x+
d->d->y*d->d->y+
d->d->z*d->d->z;
float b = 2*(d->d->x*(d->p->x-centre->x)+
d->d->y*(d->p->y-centre->y)+
d->d->z*(d->p->z-centre->z));
float c = (d->p->x-centre->x)*(d->p->x-centre->x)+
(d->p->y-centre->y)*(d->p->y-centre->y)+
(d->p->z-centre->z)*(d->p->z-centre->z)-
rayon*rayon;
float delta = b*b-4*a*c;
if ( fabs(delta) < 0.0001F ) {
float t = -b/(2.0F*a);
Position **pts =(Position **) calloc(2,sizeof(Position *));
pts[0] = d->position(t);
pts[1] = NULL;
return(pts); }
if ( delta < 0.0F )
return(NULL);
float t1 = (-b-sqrt(delta))/(2.0F*a);
float t2 = (-b+sqrt(delta))/(2.0F*a);
Position **pts =(Position **) calloc(2,sizeof(Position *));
pts[0] = d->position(t1);
pts[1] = d->position(t2);
return(pts);
}
int Sphere::testIntersection(Rayon *r) {
float b = 2*(r->d->x*(r->p->x-centre->x)+
r->d->y*(r->p->y-centre->y)+
r->d->z*(r->p->z-centre->z));
float c = (r->p->x-centre->x)*(r->p->x-centre->x)+
(r->p->y-centre->y)*(r->p->y-centre->y)+
(r->p->z-centre->z)*(r->p->z-centre->z)-
rayon*rayon;
float delta = b*b-4*c;
if ( fabs(delta) < 0.0001F ) {
float t = -b/2.0F;
if ( t >= 0.0F )
return(1);
return(0); }
if ( delta < 0.0F )
return(0);
float t1 = (-b-sqrt(delta))/2.0F;
float t2 = (-b+sqrt(delta))/2.0F;
if ( ( t1 < 0.0F ) && ( t2 < 0.0F ) )
return(0);
if ( ( t1 >= 0.0F ) && ( t2 >= 0.0F ) )
return(2);
return(1);
}
Position *Sphere::intersection(Rayon *r) {
float b = 2*(r->d->x*(r->p->x-centre->x)+
r->d->y*(r->p->y-centre->y)+
r->d->z*(r->p->z-centre->z));
float c = (r->p->x-centre->x)*(r->p->x-centre->x)+
(r->p->y-centre->y)*(r->p->y-centre->y)+
(r->p->z-centre->z)*(r->p->z-centre->z)-
rayon*rayon;
float delta = b*b-4*c;
if ( fabs(delta) < 0.0001F ) {
float t = -b/2.0F;
if ( t >= 0.0F )
return(r->position(t));
return(NULL); }
if ( delta < 0.0F )
return(NULL);
float t1 = (-b-sqrt(delta))/2.0F;
float t2 = (-b+sqrt(delta))/2.0F;
if ( ( t1 < 0.0F ) && ( t2 < 0.0F ) )
return(NULL);
if ( ( t1 >= 0.0F ) && ( t2 >= 0.0F ) )
return(r->position(min(t1,t2)));
return(r->position(max(t1,t2)));
}
void Sphere::dessine(void) {
glPushMatrix();
glTranslatef(centre->x,centre->y,centre->z);
glutSolidSphere(rayon,36,36);
glPopMatrix();
}
void Sphere::print(char *format) {
simpleBitmapOutput(1,REGULAR8x13,format,
centre->x,centre->y,centre->z,rayon);
}
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Octobre 2005 */
/* Recherche des intersections entre */
/* des rayons lumineux et des spheres */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include "Position.h"
#include "Direction.h"
#include "Sphere.h"
#include "Droite.h"
#include "Rayon.h"
#include "ModuleCouleurs.h"
#include "ModuleManipulateur.h"
#include "ModuleAxes.h"
#include "ModuleFleche.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
#include "ModuleFont.h"
static int question = 0;
static int exemple = 0;
static int aff = 1;
static int f1 ;
static int f2 ;
static Position *sp1 = new Position(-1.3F,0.7F,-1.5F);
static Position *sp2 = new Position(1.9F,-0.4F, 0.8F);
static Position *sp3 = new Position(-0.7F,-1.2F, 1.8F);
static Sphere *s1 = new Sphere(sp1,1.2F);
static Sphere *s2 = new Sphere(sp2,0.9F);
static Sphere *s3 = new Sphere(sp3,0.86721912F);
static Sphere *s = new Sphere();
static Position *dp1 = new Position(-1.3F,1.6F,-1.5F);
static Position *dp2 = new Position(0.5F,-0.7F, 0.6F);
static Position *dp3 = new Position(0.2F,-0.2F, 0.1F);
static Direction *dd1 = new Direction(0.8F,-0.5F,0.5F);
static Direction *dd2 = new Direction(1.7F,-0.9F, 1.1F);
static Direction *dd3 = new Direction(-1.2F,-0.6F, 0.9F);
static Droite *d1 = new Droite(dp1,dd1);
static Droite *d2 = new Droite(dp2,dd2);
static Droite *d3 = new Droite(dp3,dd3);
static Droite *d = new Droite();
static Rayon *r1 = new Rayon(dp1,dd1);
static Rayon *r2 = new Rayon(dp2,dd2);
static Rayon *r3 = new Rayon(dp3,dd3);
static Rayon *r = new Rayon();
static Sphere *ts[3] = { s1,s2,s3 };
static Droite *td[3] = { d1,d2,d3 };
static Rayon *tr[3] = { r1,r2,r3 };
void scene4(void) {
glDisable(GL_LIGHTING);
axes();
glEnable(GL_LIGHTING);
glPushMatrix();
r1->dessine(couleurBleu());
r2->dessine(couleurMagenta());
r3->dessine(couleurVert());
if ( aff ) {
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBlanc());
for ( int i = 0 ; i < 3 ; i++ )
for ( int j = 0 ; j < 3 ; j++ ) {
Position *pt = ts[i]->intersection(tr[j]);
if ( pt ) {
pt->dessine();
delete(pt); } } }
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge(0.5F));
s1->dessine();
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurJaune(0.5F));
s2->dessine();
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurCyan(0.5F));
s3->dessine();
glPopMatrix();
}
void display4() {
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
scene4();
glPopMatrix();
glFlush();
glutSwapBuffers();
glutPostWindowRedisplay(f2);
int error = glGetError();
if ( error != GL_NO_ERROR )
printf("Attention, erreur OpenGL %d\n",error);
}
void scene3(void) {
glDisable(GL_LIGHTING);
axes();
glEnable(GL_LIGHTING);
glPushMatrix();
r->dessine(couleurBlanc());
Position *pt = s->intersection(r);
if ( pt ) {
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge(0.5F));
pt->dessine();
delete(pt); }
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurJaune(0.5F));
s->dessine();
glPopMatrix();
}
void affecteExemple(void) {
switch ( exemple ) {
case 0 : s = s1;
d = d1;
r = r1;
break;
case 1 : s = s1;
d = d2;
r = r2;
break;
case 2 : s = s1;
d = d3;
r = r3;
break;
case 3 : s = s2;
d = d1;
r = r1;
break;
case 4 : s = s2;
d = d2;
r = r2;
break;
case 5 : s = s2;
d = d3;
r = r3;
break;
case 6 : s = s3;
d = d1;
r = r1;
break;
case 7 : s = s3;
d = d2;
r = r2;
break;
case 8 : s = s3;
d = d3;
r = r3;
break; }
}
void display3() {
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
affecteExemple();
scene3();
glPopMatrix();
glFlush();
glutSwapBuffers();
glutPostWindowRedisplay(f2);
int error = glGetError();
if ( error != GL_NO_ERROR )
printf("Attention, erreur OpenGL %d\n",error);
}
void scene2(void) {
glDisable(GL_LIGHTING);
axes();
glEnable(GL_LIGHTING);
glPushMatrix();
d1->dessine(couleurBleu());
d2->dessine(couleurMagenta());
d3->dessine(couleurVert());
if ( aff ) {
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurBlanc());
for ( int i = 0 ; i < 3 ; i++ )
for ( int j = 0 ; j < 3 ; j++ ) {
Position **pts = ts[i]->intersection(td[j]);
if ( pts ) {
pts[0]->dessine();
delete(pts[0]);
if ( pts[1] != NULL ) {
pts[1]->dessine();
delete(pts[1]); }
free(pts); } } }
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge(0.5F));
s1->dessine();
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurJaune(0.5F));
s2->dessine();
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurCyan(0.5F));
s3->dessine();
glPopMatrix();
}
void display2() {
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
scene2();
glPopMatrix();
glFlush();
glutSwapBuffers();
glutPostWindowRedisplay(f2);
int error = glGetError();
if ( error != GL_NO_ERROR )
printf("Attention, erreur OpenGL %d\n",error);
}
void scene1(void) {
glDisable(GL_LIGHTING);
axes();
glEnable(GL_LIGHTING);
glPushMatrix();
d->dessine(couleurBlanc());
if ( aff ) {
Position **pts = s->intersection(d);
if ( pts ) {
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurRouge(0.5F));
pts[0]->dessine();
delete(pts[0]);
if ( pts[1] != NULL ) {
pts[1]->dessine();
delete(pts[1]); }
free(pts); } }
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,couleurJaune(0.5F));
s->dessine();
glPopMatrix();
}
void display1() {
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
affecteExemple();
scene1();
glPopMatrix();
glFlush();
glutSwapBuffers();
glutPostWindowRedisplay(f2);
int error = glGetError();
if ( error != GL_NO_ERROR )
printf("Attention, erreur OpenGL %d\n",error);
}
void displayV4(void) {
glClearColor(0.0F,0.0F,0.0F,1.0F) ;
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
float pos = 1.0F;
glColor4fv(couleurRouge());
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
s1->print("SPHERE 1 : P (%7.3f %7.3f %7.3f) R %5.3f");
glColor4fv(couleurBleu());
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
r1->p->print("RAYON 1 : P (%7.3f %7.3f %7.3f)");
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
r1->d->print(" D (%7.3f %7.3f %7.3f)");
pos += 1.0F;
glColor4fv(couleurJaune());
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
s2->print("SPHERE 2 : P (%7.3f %7.3f %7.3f) R %5.3f");
glColor4fv(couleurMagenta());
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
r2->p->print("RAYON 2 : P (%7.3f %7.3f %7.3f)");
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
r2->d->print(" D (%7.3f %7.3f %7.3f)");
pos += 1.0F;
glColor4fv(couleurCyan());
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
s3->print("SPHERE 3 : P (%7.3f %7.3f %7.3f) R %5.3f");
glColor4fv(couleurVert());
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
r3->p->print("RAYON 3 : P (%7.3f %7.3f %7.3f)");
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
r3->d->print(" D (%7.3f %7.3f %7.3f)");
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void displayV3(void) {
glClearColor(0.0F,0.0F,0.0F,1.0F) ;
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
float pos = 1.0F;
glColor4fv(couleurJaune());
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
s->print("SPHERE : P (%7.3f %7.3f %7.3f) R %5.3f");
glColor4fv(couleurBlanc());
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
d->p->print("DROITE : P (%7.3f %7.3f %7.3f)");
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
d->d->print(" D (%7.3f %7.3f %7.3f)");
int inter = s->testIntersection(r);
pos += 1.0F;
glColor4fv(couleurRouge());
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"INTERSECTIONS ? : %s %d",
((inter == 0) ? "NON" : "OUI"),inter);
pos += 1.0F;
Position *pt = s->intersection(r);
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
if ( pt )
pt->print("POSITION : %7.3f %7.3f %7.3f");
delete(pt);
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void displayV2(void) {
glClearColor(0.0F,0.0F,0.0F,1.0F) ;
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
float pos = 1.0F;
glColor4fv(couleurRouge());
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
s1->print("SPHERE 1 : P (%7.3f %7.3f %7.3f) R %5.3f");
glColor4fv(couleurBleu());
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
d1->p->print("DROITE 1 : P (%7.3f %7.3f %7.3f)");
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
d1->d->print(" D (%7.3f %7.3f %7.3f)");
pos += 1.0F;
glColor4fv(couleurJaune());
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
s2->print("SPHERE 2 : P (%7.3f %7.3f %7.3f) R %5.3f");
glColor4fv(couleurMagenta());
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
d2->p->print("DROITE 2 : P (%7.3f %7.3f %7.3f)");
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
d2->d->print(" D (%7.3f %7.3f %7.3f)");
pos += 1.0F;
glColor4fv(couleurCyan());
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
s3->print("SPHERE 3 : P (%7.3f %7.3f %7.3f) R %5.3f");
glColor4fv(couleurVert());
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
d3->p->print("DROITE 3 : P (%7.3f %7.3f %7.3f)");
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
d3->d->print(" D (%7.3f %7.3f %7.3f)");
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void displayV1(void) {
glClearColor(0.0F,0.0F,0.0F,1.0F) ;
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glPushMatrix();
float pos = 1.0F;
glColor4fv(couleurJaune());
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
s->print("SPHERE : P (%7.3f %7.3f %7.3f) R %5.3f");
glColor4fv(couleurBlanc());
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
d->p->print("DROITE : P (%7.3f %7.3f %7.3f)");
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
d->d->print(" D (%7.3f %7.3f %7.3f)");
int inter = s->testIntersection(d);
glColor4fv(couleurRouge());
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"INTERSECTIONS ? : %s %d",
((inter == 0) ? "NON" : "OUI"),inter);
if (inter ) {
Position **pts = s->intersection(d);
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
pts[0]->print("INTERSECTION 1 : %8.4f %8.4f %8.4f");
delete(pts[0]);
if ( pts[1] != NULL ) {
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
pts[1]->print("INTERSECTION 2 : %8.4f %8.4f %8.4f");
delete(pts[1]); }
free(pts); }
glPopMatrix();
glFlush();
glutSwapBuffers();
}
void special(int key,int x,int y) {
if ( specialManipulateur(key,x,y) ) {
glutPostWindowRedisplay(f1); }
}
void key(unsigned char k,int x,int y) {
if ( keyManipulateur(k,x,y) )
glutPostWindowRedisplay(f1);
else
switch ( k ) {
case 'a' : { aff = !aff;
glutPostWindowRedisplay(f1); }
break;
case 0x0D : { question = (question+1)%4;
exemple = 0;
int win = glutGetWindow();
switch ( question ) {
case 1 : glutSetWindow(f1);
glutDisplayFunc(display1);
glutSetWindow(f2);
glutReshapeWindow(470,130);
glutDisplayFunc(displayV1);
break;
case 0 : glutSetWindow(f1);
glutDisplayFunc(display2);
glutSetWindow(f2);
glutReshapeWindow(490,190);
glutDisplayFunc(displayV2);
break;
case 3 : glutSetWindow(f1);
glutDisplayFunc(display3);
glutSetWindow(f2);
glutReshapeWindow(470,110);
glutDisplayFunc(displayV3);
break;
case 2 : glutSetWindow(f1);
glutDisplayFunc(display4);
glutSetWindow(f2);
glutReshapeWindow(490,190);
glutDisplayFunc(displayV4);
break; }
glutSetWindow(win);
glutPostWindowRedisplay(f1); }
break;
case ' ' : { exemple = (exemple+1)%9;
glutPostWindowRedisplay(f1); }
break; }
}
void myInit() {
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHT0);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE,1);
glShadeModel(GL_SMOOTH);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_CULL_FACE);
glClearColor(0.5F,0.5F,0.5F,1.0F);
}
void reshapeV(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();
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitWindowSize(270,270);
glutInitWindowPosition(50,50);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
f1 = glutCreateWindow("Intersection rayon-sphere");
myInit();
creationMenuBasique();
setParametresOrthoBasique(-2.5,2.5,-2.5,2.5,-50.0,50.0);
setManipulateurDistance(1.0F);
setManipulateurSourisAngle(10.0F,-20.0F,0.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutKeyboardFunc(key);
glutDisplayFunc(display2);
glutSpecialFunc(special);
glutInitWindowSize(490,190);
glutInitWindowPosition(60,360);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
f2 = glutCreateWindow("Valeurs");
creationMenuBasique();
glutDisplayFunc(displayV2);
glutReshapeFunc(reshapeV);
glutKeyboardFunc(key);
glutSpecialFunc(special);
glutMainLoop();
return(0);
}