Le source: ProjectionParallele.cpp
/* Auteur: Nicolas JANEY */
/* nicolas.janey@univ-fcomte.fr */
/* Juin 2001 */
/* Shema de realisation d'une projection */
/* parallele */
#include <GL/glut.h>
#include <GL/gl.h>
#include <GL/glu.h>
#include <stdio.h>
#include <math.h>
#include "ModuleCouleurs.h"
#include "ModuleReshape.h"
#include "ModuleManipulateur.h"
#include "ModuleMenus.h"
#include "ModuleFont.h"
#include "ModuleFleche.h"
static int aff = 0;
static float pax = 6.0F;
static float pay = -4.0F;
static float paz = -14.0F;
static float pbx = -4.0F;
static float pby = 3.0F;
static float pbz = -9.0F;
void myinit(void) {
glDepthFunc(GL_LESS);
glEnable(GL_DEPTH_TEST);
glEnable(GL_NORMALIZE) ;
glEnable(GL_LIGHT0);
glClearColor(0.5F,0.5F,0.5F,0.0F);
}
void axeDeProjection(float x1,float y1,float z1,float x2,float y2,float z2,float fact) {
float dx = x2-x1;
float dy = y2-y1;
float dz = z2-z1;
glBegin(GL_LINES);
glVertex3f(x1-fact*dx,y1-fact*dy,z1-fact*dz);
glVertex3f(x1+fact*dx,y1+fact*dy,z1+fact*dz);
glEnd();
}
void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
manipulateurSouris();
manipulateurClavier();
glColor4fv(couleurBlanc());
glBegin(GL_LINE_LOOP);
glVertex3f(8.0F,6.0F,-3.0F);
glVertex3f(8.0F,-6.0F,-3.0F);
glVertex3f(-8.0F,-6.0F,-3.0F);
glVertex3f(-8.0F,6.0F,-3.0F);
glEnd();
glColor4fv(couleurJaune());
glBegin(GL_LINES);
glVertex3f(pax,pay,paz);
glVertex3f(pbx,pby,pbz);
glEnd();
glColor4fv(couleurRouge());
glBegin(GL_LINES);
glVertex3f(pax,pay,-3.0F);
glVertex3f(pbx,pby,-3.0F);
glEnd();
glEnable(GL_LIGHTING);
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurRougeFonce());
glPushMatrix();
glTranslatef(0.0F,0.0F,-15.0F);
flecheEnVolume(0.0F,0.0F,25.0F,0.3F,1.5F,0.1F) ;
glPopMatrix();
glMaterialfv(GL_FRONT,GL_DIFFUSE,couleurVertFonce());
glPushMatrix();
glTranslatef(pax,pay,paz);
flecheEnVolume(0.0F,0.0F,-3.0F-paz,0.3F,1.5F,0.1F) ;
glPopMatrix();
glPushMatrix();
glTranslatef(pbx,pby,pbz);
flecheEnVolume(0.0F,0.0F,-3.0F-pbz,0.3F,1.5F,0.1F) ;
glPopMatrix();
glDisable(GL_LIGHTING);
glColor4fv(couleurRouge());
axeDeProjection(0.0F,0.0F,1.0F,0.0F,0.0F,-1.0F,50);
glColor4fv(couleurVert());
axeDeProjection(pax,pay,paz,pax,pay,paz+1.0F,50);
axeDeProjection(pbx,pby,pbz,pbx,pby,pbz+1.0F,50);
glColor4fv(couleurRouge());
placeFontCursor(pax+0.1F,pay+0.1F,-2.9F);
simpleBitmapOutput("%s","A'");
placeFontCursor(pbx+0.1F,pby+0.1F,-2.9F);
simpleBitmapOutput("%s","B'");
glColor4fv(couleurJaune());
placeFontCursor(pax+0.1F,pay+0.1F,paz+0.1F);
simpleBitmapOutput("%s","A");
placeFontCursor(pbx+0.1F,pby+0.1F,pbz+0.1F);
simpleBitmapOutput("%s","B");
glColor4fv(couleurBlanc());
placeFontCursor(0.0F,-2.0F,21.0F);
simpleBitmapOutput("%s","Centre de projection");
placeFontCursor(3.0F,-3.0F,21.0F);
simpleBitmapOutput("%s","a l'infini");
glColor4fv(couleurRouge());
placeFontCursor(-2.0F,1.0F,21.0F);
simpleBitmapOutput("%s","Axe de projection");
glPopMatrix();
glFlush();
glutSwapBuffers();
}
/* -------------------------------------------------- */
void key(unsigned char key,int x,int y) {
if ( keyManipulateur(key,x,y) )
glutPostRedisplay();
else
switch ( key ) {
case 'e' : pax += 0.2F;
if ( pax > 8.0F )
pax = 8.0F;
glutPostRedisplay();
break;
case 'E' : pax -= 0.2F;
if ( pax < -8.0F )
pax = -8.0F;
glutPostRedisplay();
break;
case 'd' : pbx += 0.2F;
if ( pbx > 8.0F )
pbx = 8.0F;
glutPostRedisplay();
break;
case 'D' : pbx -= 0.2F;
if ( pbx < -8.0F )
pbx = -8.0F;
glutPostRedisplay();
break;
case 'r' : pay += 0.2F;
if ( pay > 8.0F )
pay = 8.0F;
glutPostRedisplay();
break;
case 'R' : pay -= 0.2F;
if ( pay < -8.0F )
pay = -8.0F;
glutPostRedisplay();
break;
case 'f' : pby += 0.2F;
if ( pby > 8.0F )
pby = 8.0F;
glutPostRedisplay();
break;
case 'F' : pby -= 0.2F;
if ( pby < -8.0F )
pby = -8.0F;
glutPostRedisplay();
break;
case 't' : paz += 0.2F;
glutPostRedisplay();
break;
case 'T' : paz -= 0.2F;
glutPostRedisplay();
break;
case 'g' : pbz += 0.2F;
glutPostRedisplay();
break;
case 'G' : pbz -= 0.2F;
glutPostRedisplay();
break;
case 32 : aff = (aff+1)%2 ;
glutPostRedisplay();
break; }
}
/* -------------------------------------------------- */
int main(int argc,char **argv) {
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA|GLUT_DEPTH);
glutInitWindowPosition(10,10);
glutInitWindowSize(400,250);
glutCreateWindow("Schema: Projection parallele orthographique");
myinit();
creationMenuBasique();
setParametresOrthoBasique(-10.0,10.0,-10.0,10.0,-500.0,500.0);
setManipulateurDistance(1.0F);
setManipulateurClavierAngle(22.0F,-40.0F,0.0F) ;
glutReshapeFunc(reshapeOrthoBasique);
glutKeyboardFunc(key);
glutSpecialFunc(specialBasique);
glutMotionFunc(motionBasique);
glutMouseFunc(sourisBasique);
glutDisplayFunc(display);
glutMainLoop();
return(0);
}
/* ************************************************** */