/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Fevrier 2002 */
/* Orientation des reperes lies */
/* au processus de visualisation */
/* Visualisation de Po vers Pv */
#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 "ModuleDessinArc.h"
#include "ModuleFleche.h"
#include "ModuleMatriceVecteur.h"
#include "ModuleFont.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleReshape.h"
#ifndef M_PI
#define M_PI 3.141459F
#endif
static int tscn = 1;
static int aa = 0;
static int vert = 0;
static int scn = 0;
static int vol = 0;
static int f1;
static int f2;
static int f3;
static vecteur pp1;
static float angle = -35.0F;
static float ay = -30.0F;
static float ax = -15.0F;
static float dist = -7.0F;
static float ratio = 1.0F;
static vecteur po = { -0.5,3.0,3.0 };
static vecteur pv = { 0.0F,0.0F,0.0F,1.0F };
void glutSolidCylinder(float r,float h,int n,int m) {
glPushMatrix();
glRotatef(90,1.0F,0.0F,0.0F);
glTranslatef(0.0F,0.0F,-h/2);
GLUquadricObj *qobj = gluNewQuadric();
gluQuadricDrawStyle(qobj,GLU_FILL);
gluCylinder(qobj,r,r,h,n,m);
gluDeleteQuadric(qobj);
glPopMatrix();
}
void axes(float lx1,float lx2,float ly1,float ly2,float lz1,float lz2,char *x,char *y,char *z) {
glPushAttrib(GL_LIGHTING);
glEnable(GL_LIGHTING);
setFont(GLUT_BITMAP_8_BY_13,CENTER);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge());
flecheEnVolume(1.0F,0.0F,0.0F,0.1F,0.3F,0.02F);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurVert());
flecheEnVolume(0.0F,1.0F,0.0F,0.1F,0.3F,0.02F);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBleu());
flecheEnVolume(0.0F,0.0F,1.0F,0.1F,0.3F,0.02F);
glDisable(GL_LIGHTING);
glColor4fv(couleurRougeFonce());
bitmapStringOutput(1.3F,0.0F,0.0F,x);
glColor4fv(couleurRougeFonce(0.5F));
glBegin(GL_LINES);
glVertex3f(lx1,0.0F,0.0F);
glVertex3f(-lx2,0.0F,0.0F);
glEnd();
glColor4fv(couleurVertFonce());
bitmapStringOutput(0.0F,1.3F,0.0F,y);
glColor4fv(couleurVertFonce(0.5F));
glBegin(GL_LINES);
glVertex3f(0.0F,ly1,0.0F);
glVertex3f(0.0F,-ly2,0.0F);
glEnd();
glColor4fv(couleurBleuFonce());
bitmapStringOutput(0.0F,0.0F,1.3F,z);
glColor4fv(couleurBleuFonce(0.5F));
glBegin(GL_LINES);
glVertex3f(0.0F,0.0F,lz1);
glVertex3f(0.0F,0.0F,-lz2);
glEnd();
setFont(GLUT_BITMAP_8_BY_13,LEFT);
glPopAttrib();
}
void myinit(void) {
GLfloat light_position0[] = { 1.0F,0.0F,1.0F,0.0F };
GLfloat light_position1[] = { -1.0F,0.0F,1.0F,0.0F };
glLightfv(GL_LIGHT0,GL_AMBIENT,couleurNoir());
glLightfv(GL_LIGHT0,GL_DIFFUSE,couleurBlanc());
glLightfv(GL_LIGHT1,GL_DIFFUSE,couleurBlanc());
glLightfv(GL_LIGHT0,GL_SPECULAR,couleurNoir());
glLightfv(GL_LIGHT0,GL_POSITION,light_position0);
glLightfv(GL_LIGHT1,GL_POSITION,light_position1);
glEnable(GL_LIGHT0);
glEnable(GL_LIGHT1);
glEnable(GL_AUTO_NORMAL);
glEnable(GL_NORMALIZE);
glDepthFunc(GL_LESS);
glEnable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
}
void dessineSphere(vecteur p) {
glPushMatrix();
glPushAttrib(GL_LIGHTING);
glEnable(GL_LIGHTING);
glTranslatef(p[0],p[1],p[2]);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurGrisMoyen());
glutSolidSphere(0.08,20,20);
glPopAttrib();
glPopMatrix();
}
void scene(void) {
glEnable(GL_CULL_FACE);
glEnable(GL_LIGHTING);
glEnable(GL_NORMALIZE);
glEnable(GL_AUTO_NORMAL);
if ( tscn ) {
glPushMatrix();
glTranslatef(2.5F,1.0F,-2.0F);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge(0.5F));
glutSolidSphere(0.5F,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(2.0F,1.0F,-1.0F);
glRotatef(50.0F,1.0F,1.0F,-1.0F);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBleu(0.5F));
glutSolidCone(0.6F,1.0F,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(1.5F,2.0F,-2.0F);
glRotatef(50.0F,1.0F,1.0F,-1.0F);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurMagenta(0.5F));
glutSolidCube(0.8F);
glPopMatrix();
glPushMatrix();
glTranslatef(3.0F,2.0F,-1.0F);
glRotatef(50.0F,0.0F,0.0F,1.0F);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurVert(0.5F));
glutSolidTorus(0.25F,0.4F,30,30);
glPopMatrix(); }
else {
glPushMatrix();
glTranslatef(2.5F,1.0F,-2.0F);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRouge(0.5F));
glutSolidCylinder(0.1F,2.0F,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(2.0F,1.0F,-1.0F);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurBleu(0.5F));
glutSolidCylinder(0.1F,2.0F,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(1.5F,2.0F,-2.0F);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurMagenta(0.5F));
glutSolidCylinder(0.1F,2.0F,30,30);
glPopMatrix();
glPushMatrix();
glTranslatef(3.0F,2.0F,-1.0F);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurVert(0.5F));
glutSolidCylinder(0.1F,2.0F,30,30);
glPopMatrix(); }
glDisable(GL_NORMALIZE);
glDisable(GL_AUTO_NORMAL);
glDisable(GL_LIGHTING);
glDisable(GL_CULL_FACE);
}
void volumeDeVisualisation(float vouv,float ratio,float cmin,float cmax) {
glEnable(GL_CULL_FACE);
float y1 = cmin * tan(vouv*M_PI/360.0F);
float x1 = y1*ratio;
glBegin(GL_LINE_LOOP);
glVertex3f(x1,y1,-cmin);
glVertex3f(x1,-y1,-cmin);
glVertex3f(-x1,-y1,-cmin);
glVertex3f(-x1,y1,-cmin);
glEnd();
float y2 = cmax * tan(vouv*M_PI/360.0F);
float x2 = y2*ratio;
glBegin(GL_LINE_LOOP);
glVertex3f(x2,y2,-cmax);
glVertex3f(x2,-y2,-cmax);
glVertex3f(-x2,-y2,-cmax);
glVertex3f(-x2,y2,-cmax);
glEnd();
glBegin(GL_LINES);
glVertex3f(x1,y1,-cmin);
glVertex3f(x2,y2,-cmax);
glVertex3f(x1,-y1,-cmin);
glVertex3f(x2,-y2,-cmax);
glVertex3f(-x1,-y1,-cmin);
glVertex3f(-x2,-y2,-cmax);
glVertex3f(-x1,y1,-cmin);
glVertex3f(-x2,y2,-cmax);
glEnd();
glBegin(GL_QUADS);
glColor4fv(couleurRose(0.3F));
glVertex3f(-x1,y1,-cmin);
glVertex3f(-x1,-y1,-cmin);
glVertex3f(x1,-y1,-cmin);
glVertex3f(x1,y1,-cmin);
glVertex3f(x2,y2,-cmax);
glVertex3f(x2,-y2,-cmax);
glVertex3f(-x2,-y2,-cmax);
glVertex3f(-x2,y2,-cmax);
glVertex3f(-x2,y2,-cmax);
glVertex3f(-x2,-y2,-cmax);
glVertex3f(-x1,-y1,-cmin);
glVertex3f(-x1,y1,-cmin);
glVertex3f(x1,y1,-cmin);
glVertex3f(x1,-y1,-cmin);
glVertex3f(x2,-y2,-cmax);
glVertex3f(x2,y2,-cmax);
glVertex3f(x2,y2,-cmax);
glVertex3f(-x2,y2,-cmax);
glVertex3f(-x1,y1,-cmin);
glVertex3f(x1,y1,-cmin);
glVertex3f(x1,-y1,-cmin);
glVertex3f(-x1,-y1,-cmin);
glVertex3f(-x2,-y2,-cmax);
glVertex3f(x2,-y2,-cmax);
glEnd();
glEnable(GL_CULL_FACE);
}
void display(void) {
glClearColor(0.85F,0.85F,0.65F,1.0F);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glPushMatrix() ;
glTranslatef(-1.0F,-1.0F,0.0F);
manipulateurSouris();
manipulateurClavier();
axes(4.0F,2.0F,4.0F,1.5F,4.0F,6.0F,"x","y","z");
glColor4fv(couleurNoir());
bitmapStringOutput(0.2F,-0.2F,0.2F,"O");
glColor4fv(couleurGrisFonce(0.5F));
glBegin(GL_LINES);
glVertex3f(po[0],po[1],po[2]);
glVertex3f(po[0],0.0F,po[2]);
glVertex3f(po[0],0.0F,po[2]);
glVertex3f(po[0],0.0F,0.0F);
glVertex3f(po[0],0.0F,po[2]);
glVertex3f(0.0F,0.0F,po[2]);
glEnd();
matrice m;
toTranslation(m,po[0],po[1],po[2]);
matrice r;
toRotation(r,ay,0.0F,1.0F,0.0F);
produitMatriceMatrice(m,r,m);
toRotation(r,ax,1.0F,0.0F,0.0F);
produitMatriceMatrice(m,r,m);
vecteur p1 = { 0.0F,1.5F,0.0F,1.0F };
produitMatriceVecteur(m,p1,p1);
matrice m2;
toRotation(r,(vert) ? 0.0F:angle,0.0F,0.0F,1.0F);
produitMatriceMatrice(m,r,m2);
vecteur p2 = { 0.0F,1.5F,0.0F,1.0F };
produitMatriceVecteur(m2,p2,p2);
matrice m1;
toTranslation(r,0.0F,0.0F,dist);
produitMatriceMatrice(m,r,m1);
pv[0] = pv[1] = pv[2] = 0.0F;
pv[3] = 1.0F;
produitMatriceVecteur(m1,pv,pv);
glColor4fv(couleurNoir());
bitmapStringOutput(pv[0]+0.3F,pv[1]+0.3F,pv[2]+0.3F,"Pv");
glColor4fv(couleurGrisFonce(0.5F));
glBegin(GL_LINES);
glVertex3f(pv[0],pv[1],pv[2]);
glVertex3f(pv[0],0.0F,pv[2]);
glVertex3f(pv[0],0.0F,pv[2]);
glVertex3f(pv[0],0.0F,0.0F);
glVertex3f(pv[0],0.0F,pv[2]);
glVertex3f(0.0F,0.0F,pv[2]);
glVertex3f(po[0]+(p1[0]-po[0])*2,po[1]+(p1[1]-po[1])*2,po[2]+(p1[2]-po[2])*2);
glVertex3f(po[0]-(p1[0]-po[0])*2,po[1]-(p1[1]-po[1])*2,po[2]-(p1[2]-po[2])*2);
glEnd();
dessineSphere(pv);
glPushMatrix() ;
glTranslatef(po[0],po[1],po[2]);
p1[0] -= po[0];
p1[1] -= po[1];
p1[2] -= po[2];
p2[0] -= po[0];
p2[1] -= po[1];
p2[2] -= po[2];
pp1[0] = p1[0];
pp1[1] = p1[1];
pp1[2] = p1[2];
glColor4fv(couleurNoir());
traceAngleFleche(p1,p2,30,1.0F,1,3,8.0F,0.1F) ;
vecteur pint;
positionIntermediaire(p1,p2,1.0F,pint);
placeFontCursor(pint[0],pint[1],pint[2]) ;
deplacementCursor(0,-10,0) ;
simpleBitmapOutput(1,SYMBOL,"q") ;
glRotatef(ay,0.0F,1.0F,0.0F);
glRotatef(ax,1.0F,0.0F,0.0F);
glRotatef((vert) ? 0.0F:angle,0.0F,0.0F,1.0F);
glColor4fv(couleurNoir());
bitmapStringOutput(-0.45F,0.0F,0.0F,"Po");
glColor4fv(couleurGrisFonce());
lineOutput(-8,-12,-8,-52);
lineOutput(-8,-12,-5,-12);
lineOutput(-8,-52,-5,-52);
lineOutput(21,-12,21,-52);
lineOutput(21,-12,18,-12);
lineOutput(21,-52,18,-52);
deplacementCursor(-5,-40,0);
bitmapStringOutput("Pox");
deplacementCursor(-5,-28,0);
bitmapStringOutput("Poy");
deplacementCursor(-5,-16,0);
bitmapStringOutput("Poz");
axes(0.0F,0.0F,3.0,2.0,2.0F,15.0F,"xo","yo","zo");
glPopMatrix() ;
if ( scn )
scene();
if ( vol ) {
glClear(GL_DEPTH_BUFFER_BIT);
glPushMatrix() ;
glTranslatef(po[0],po[1],po[2]);
glRotatef(ay,0.0F,1.0F,0.0F);
glRotatef(ax,1.0F,0.0F,0.0F);
glRotatef((vert) ? 0.0F:angle,0.0F,0.0F,1.0F);
glColor4fv(couleurNoir(0.5F));
volumeDeVisualisation(anglePerspectiveBasique(),ratioPerspectiveBasique(),4.0F,7.0F);
glPopMatrix() ; }
glPopMatrix() ;
glDisable(GL_DEPTH_TEST);
glFlush();
glutSwapBuffers() ;
glutPostWindowRedisplay(f2);
glutPostWindowRedisplay(f3);
}
void key2(unsigned char key,int x,int y) {
switch ( key ) {
case '1' : ay += 1.0F;
glutPostWindowRedisplay(f1);
break;
case '4' : ay -= 1.0F;
glutPostWindowRedisplay(f1);
break;
case '2' : ax += 1.0F;
glutPostWindowRedisplay(f1);
break;
case '5' : ax -= 1.0F;
glutPostWindowRedisplay(f1);
break;
case '3' : dist += 0.1F;
glutPostWindowRedisplay(f1);
break;
case '6' : dist -= 0.1F;
glutPostWindowRedisplay(f1);
break;
case 'e' : po[0] += 0.05F;
glutPostWindowRedisplay(f1);
break;
case 'r' : po[1] += 0.05F;
glutPostWindowRedisplay(f1);
break;
case 't' : po[2] += 0.05F;
glutPostWindowRedisplay(f1);
break;
case 'E' : po[0] -= 0.05F;
glutPostWindowRedisplay(f1);
break;
case 'R' : po[1] -= 0.05F;
glutPostWindowRedisplay(f1);
break;
case 'T' : po[2] -= 0.05F;
glutPostWindowRedisplay(f1);
break;
case 43 : angle += 1.0F;
glutPostWindowRedisplay(f1);
break;
case 45 : angle -= 1.0F;
glutPostWindowRedisplay(f1);
break;
case 's' : tscn = !tscn;
glutPostWindowRedisplay(f1);
break;
case 'v' : vert = !vert;
glutPostWindowRedisplay(f1);
break;
case 'a' : aa = !aa;
glutPostWindowRedisplay(f1);
break;
case 0x0D : scn = !scn;
glutPostWindowRedisplay(f1);
break;
case ' ' : vol = !vol;
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());
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"Po : %6.3f %6.3f %6.3f",po[0],po[1],po[2]) ;
pos += 1.0F;
if ( aa ) {
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"ThetaY : %8.3f",ay) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"ThetaX : %8.3f",ax) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"Distance : %6.3f",dist) ;
pos += 1.0F; }
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"Pv : %6.3f %6.3f %6.3f",pv[0],pv[1],pv[2]) ;
pos += 1.0F;
placeFontCursor(5.0F,-pos*20.0F,0.0F) ;
simpleBitmapOutput(1,REGULAR8x13,"Theta : %8.3f",(vert) ? 0.0F:angle) ;
glPopMatrix();
glutSwapBuffers();
}
void display3() {
glEnable(GL_DEPTH_TEST);
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glClearColor(0.25F,0.25F,0.25F,1.0F) ;
glPushMatrix();
glRotatef((vert) ? 0.0F:angle,0.0F,0.0F,-1.0F);
gluLookAt(po[0],po[1],po[2],pv[0],pv[1],pv[2],pp1[0],pp1[1],pp1[2]);
dessineSphere(pv);
scene();
glPopMatrix();
glutSwapBuffers();
glDisable(GL_DEPTH_TEST);
}
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowPosition(10,50);
glutInitWindowSize(400,280);
f1 = glutCreateWindow("Visualisation de Po vers Pv");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-2.7,2.7,-2.7,2.7,-100.0,100.0);
setManipulateurDistance(1.0F);
setManipulateurClavierAngle(25.0F,-15.0F,0.0F);
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutDisplayFunc(display);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutInitWindowSize(340,130);
glutInitWindowPosition(40,380);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
f2 = glutCreateWindow("Valeurs");
creationMenuBasique();
glutDisplayFunc(display2);
glutReshapeFunc(reshape2);
glutKeyboardFunc(key2);
glutSpecialFunc(special);
glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_DOUBLE);
glutInitWindowPosition(430,50);
glutInitWindowSize(250,250);
f3 = glutCreateWindow("Scene");
myinit();
creationMenuBasique();
setParametresPerspectiveBasique(35.0F,1.0F,4.0F,7.0F,0.0F,0.0F,0.0F,f1);
glutReshapeFunc(reshapePerspectiveBasique);
glutKeyboardFunc(key2);
glutSpecialFunc(special);
glutDisplayFunc(display3);
glutMainLoop();
return(0);
}