home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.hitl.washington.edu
/
ftp.hitl.washington.edu.tar
/
ftp.hitl.washington.edu
/
pub
/
people
/
habib
/
kodak
/
Vrml2_Viewer.cpp~
< prev
next >
Wrap
Text File
|
2000-04-18
|
86KB
|
2,349 lines
// By Habib Abi-Rached
// 3 March 1998.
// Using Glut / OpenGl
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <string.h>
#include <math.h> /* for cos(), sin(), and sqrt() */
#include <GL/glut.h>
#include "variables.h"
#include "f-gen.h"
#include "trackball.h"
#include "mirror.h"
#include <windows.h> // WinUnix
#include <mmsystem.h> // WinUnix
#include "interface.h"
#include <malloc.h>
#define DimX 400
#define DimY 150
#define DimZ 400
extern void Draw_Vrml(Type_Transform *, int numlist);
extern Type_Transform * Read_Vrml_File(char *);
extern "C" unsigned char * read_JPEG_file (char *, unsigned char *, int *, int *);
void
inline buildmf()
{
mf[0][0] = m[0][0];
mf[0][1] = m[0][1];
mf[0][2] = m[0][2];
mf[0][3] = m[0][3];
mf[1][0] = m[1][0];
mf[1][1] = m[1][1];
mf[1][2] = m[1][2];
mf[1][3] = m[1][3];
mf[2][0] = m[2][0];
mf[2][1] = m[2][1];
mf[2][2] = m[2][2];
mf[2][3] = m[2][3];
mf[3][0] = m[3][0];
mf[3][1] = m[3][1];
mf[3][2] = m[3][2];
mf[3][3] = m[3][3];
}
void
glerror()
{
GLenum errCode;
errCode = glGetError();
cout << gluErrorString(errCode) << endl;
}
void
inputdollar (char phrase[70])
{
char mot[20] ;
char blanc [2];
blanc[0] = ' ';
strcpy (phrase,""); /* pour vider input car on va lui faire un strcat. */
printf ("---> ");
while (blanc[0] == ' ')
{
scanf ("%s",mot);
scanf ("%1c",blanc);
strcat (phrase,mot);
strncat (phrase,blanc,1);
}
}
void
inline
showMessage(GLfloat x, GLfloat y, GLfloat z, char *message)
{
glPushMatrix();
// glDisable(GL_LIGHTING);
glRasterPos3f(x,y,z);
//glScalef(.02, .02, .02);
while (*message) {
//glutStrokeCharacter(GLUT_STROKE_ROMAN, *message);
glutBitmapCharacter(GLUT_BITMAP_8_BY_13, *message);
message++;
}
glPopMatrix();
if (FLAG_TOGGLE_MENU1) {
glEnable(GL_LIGHTING);
}
}
/*________________________trouver____________________________________*/
/* c'est une fct qui calcul la moyenne */
/* d'un tableau TABC et le min et le */
/* et le max du meme TABC et renvoie */
/* ces 3 valeurs en renvoyant une struc*/
inline
struct bmm trouver (float *tabc,int dim[1])
{ int i;
int local_dim = dim[0];
struct bmm bmm2;
bmm2.bar=0;
bmm2.min=tabc[0];
bmm2.max=tabc[0];
for (i=0; i<dim[0]; i++)
{
if (tabc[i] != NaN) {
bmm2.bar = bmm2.bar + tabc [i];
if (tabc[i]<bmm2.min) bmm2.min = tabc[i];
if (tabc[i]>bmm2.max) bmm2.max = tabc[i];
}
else local_dim = local_dim -1;
}
bmm2.bar = bmm2.bar/local_dim;
return bmm2;
}
/*_____________________trouver_bar_min_max_________________________
/* c'est une fct qui calcul le bar, max et min */
/* de 3 tableaux: xc, yc, zc.
//ftrouver_bar_min_max_sig
void
trouver_bar_min_max_sig(float *xc,float *yc, float* zc,int dim[1])
{ struct bmm bmm1[i];
bmm1[i]=trouver (xc,dim);
xmax = bmm1[i].max;
xbar = bmm1[i].bar;
xmin = bmm1[i].min;
bmm1[i]=trouver (yc,dim);
ymax = bmm1[i].max;
ybar = bmm1[i].bar;
ymin = bmm1[i].min;
bmm1[i]=trouver (zc,dim);
zmax = bmm1[i].max;
zbar = bmm1[i].bar;
zmin = bmm1[i].min;
// Calculating sigma and taking care of NaN.
sigx = sigy = sigz = 0;
int dimx, dimy, dimz; // to take care of NaN.
dimx = dimy = dimz = dim[0];
for (int i=0; i< dim[0]; i++){
if (xc[i] != NaN)
sigx = sigx + (xbar - xc[i]) * (xbar - xc[i]);
else dimx = dimx -1;
if (yc[i] != NaN)
sigy = sigy + (ybar - yc[i]) * (ybar - yc[i]);
else (dimy = dimy -1);
if (zc[i] != NaN)
sigz = sigz + (zbar - zc[i]) * (zbar - zc[i]);
else (dimz = dimz -1);
}
sigx = sigx/dimx;
sigy = sigy/dimy;
sigz = sigz/dimz;
sigx = sqrt (sigx);
sigy = sqrt (sigy);
sigz = sqrt (sigz);
// Normalizing sigma so that when we scale it keeps the smallest axes fix.
if ((sigx<sigy) && (sigx<sigz)) sig_min = sigx;
else
if ((sigy<sigx) && (sigy<sigz)) sig_min = sigy;
else sig_min = sigz;
sig_x_n = sigx/sig_min;
sig_y_n = sigy/sig_min;
sig_z_n = sigz/sig_min;
// Calculating delta.
deltax = fabs(xmax - xmin);
deltay = fabs(ymax - ymin);
deltaz = fabs(zmax - zmin);
// Normalizing sigma so that when we scale it keeps the smallest axes fix.
if ((deltax<deltay) && (deltax<deltaz)) delta_min = deltax;
else
if ((deltay<deltax) && (deltay<deltaz)) delta_min = deltay;
else delta_min = deltaz;
deltax_n = deltax/delta_min;
deltay_n = deltay/delta_min;
deltaz_n = deltaz/delta_min;
// Calculating xmin_e ... for some extraneous uses...
xmin_e = xmin - 0.3*deltax;
ymin_e = ymin - 0.3*deltay;
zmin_e = zmin - 0.3*deltaz;
xmax_e = xmax + 0.3*deltax;
ymax_e = ymax + 0.3*deltay;
zmax_e = zmax + 0.3*deltaz;
cout << "xmax=" << xmax << " ymax=" << ymax << " zmax=" << zmax << endl;
cout << "xmin=" << xmin << " ymin=" << ymin << " zmin=" << zmin << endl;
cout << "xbar=" << xbar << " ybar=" << ybar << " zbar=" << zbar << endl;
cout << "sigx="<< sigx << " sigy=" << sigy << " sigz=" << sigz << endl;
cout << "sig_x_n="<< sig_x_n << " sig_y_n=" << sig_y_n << " sig_z_n=" << sig_z_n << endl;
cout << "xmax-xmin=" << xmax - xmin << " ymax-ymin=" << ymax - ymin << " zmax-zmin=" << zmax - zmin << endl;
cout << "deltax=" << deltax << " deltay="<< deltay << " deltaz=" << deltaz << endl;
cout << "deltax_n=" << deltax_n << " deltay_n="<< deltay_n << " deltaz_n=" << deltaz_n << endl;
}*/
void
inline
draw_axes()
{
void dvertical_adjx();
glBegin(GL_LINES);
glColor3f (0.2f,0.2f,1.0f);
glVertex3f (0.0f, 0.0f, 0.0f);
glVertex3f (deltax, 0.0f, 0.0f);
glEnd();
showMessage(deltax,0,0, string3);
glBegin(GL_LINES);
glColor3f (0.15f,0.7f,0.15f);
glVertex3f (0.0f, 0.0f, 0.0f);
glVertex3f (0.0f, deltay, 0.0f);
glEnd();
showMessage(0,deltay,0, string2);
glBegin(GL_LINES);
glColor3f (1.0f,0.2f,0.2f);
glVertex3f (0, 0, 0);
glVertex3f (0.0, 0.0, deltaz);
glEnd();
showMessage(0,0,deltaz, string1);
}
void
inline
draw_box()
{
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
glVertex3f (xmin,ymax,zmax);
glVertex3f (xmax,ymax,zmax);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
glVertex3f (xmax,ymax,zmax);
glVertex3f (xmax,ymin,zmax);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
// glColor3f (0.5,0,0);
glVertex3f (xmax,ymin,zmax);
glVertex3f (xmin,ymin,zmax);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
// glColor3f (0.0,0.5,0.0);
glVertex3f (xmin,ymin,zmax);
glVertex3f (xmin,ymax,zmax);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
// glColor3f (0,0,0.8);
glVertex3f (xmin,ymax,zmax);
glVertex3f (xmin,ymax,zmin);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
//glColor3f (0,0,0.8);
glVertex3f (xmax,ymax,zmax);
glVertex3f (xmax,ymax,zmin);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
//glColor3f (0,0,0.8);
glVertex3f (xmax,ymin,zmax);
glVertex3f (xmax,ymin,zmin);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
//glColor3f (0,0,0.8);
glVertex3f (xmin,ymin,zmax);
glVertex3f (xmin,ymin,zmin);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
//glColor3f (0.0,0.5,0.0);
glVertex3f (xmin,ymax,zmin);
glVertex3f (xmin,ymin,zmin);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
//glColor3f (0.5,0,0);
glVertex3f (xmin,ymin,zmin);
glVertex3f (xmax,ymin,zmin);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
//glColor3f (0.0,0.5,0.0);
glVertex3f (xmax,ymin,zmin);
glVertex3f (xmax,ymax,zmin);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45f,0.45f,0.45f);
//glColor3f (0.5,0,0);
glVertex3f (xmax,ymax,zmin);
glVertex3f (xmin,ymax,zmin);
glEnd();
}
void
inline
recalcModelView(void) //frecalcmodelview
{
void init();
// GLfloat m[4][4]; Global variable because used after.
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPushMatrix();
if (LIGHTS_FIX_WITH_CAMERA) {
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);// Because light is affected by the scale.
glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambi);
}
double scalex, scaley, scalez;
// build_rotmatrix(m, curquat);
// I moved this block to interface because the rotation should be done as soon as we move the mouse.
//rotate the 3D up,lk,hor system.
/*lk_rt = mult_matrix_vector(m,lk); // lk is (0,0,1) lk_rt is the lk after the quaternion rotation
up_rt = mult_matrix_vector(m,up ); // up is (0,1,0) up_rt is up after the quaternion rotation.
hor_rt = mult_matrix_vector(m,hor); // hor is (1,0,0) hor_rt is hor after the quaternion rotation.*/
//up_rt = vectoriel (hor_rt,lk_rt);
// The translation is done in the interface mode.
// Translate lk_tr in the Z direction.
gluLookAt(eye.x,eye.y,eye.z, // eye is at (...
eye.x+lk_rt.x,eye.y+lk_rt.y,eye.z+lk_rt.z, // looking to
up_rt.x,up_rt.y,up_rt.z); // up is in positive Y direction */
// We should normalize scaling in order to maintain the same lenth for the smaller axes.
if (SCALE_SIGMA) {
scalex = 1/sigx;
scaley = 1/sigy;
scalez = 1/sigz;
}
// We should normalize scaling in order to maintain the same lenth for the smaller axes.
if (SCALE_MIDDLE) {
scalex = 1/deltax;
scaley = 1/deltay;
scalez = 1/deltaz;
}
else {
scalex = 1;
scaley = 1;
scalez = 1;
}
// Translate the origin ONLY IF INDICATED OTHERWHISE PUT IT IN 0,0,0
//
if (TRANSLATE_TO_GRAVITY) glTranslatef (-xbar*scalex,-ybar*scaley,-zbar*scalez);
if (TRANSLATE_TO_MIDDLE ) glTranslatef (-(xmin+xmax)*scalex/2,-(ymin+ymax)*scaley/2,-(zmin+zmax)*scalez/2);
// SCALE ONLY IF REQUESTED OTHERWISE DO NOT SCALE (1,1,1).
glScalef (scalex, scaley, scalez);
newModel = 0;
if (!LIGHTS_FIX_WITH_CAMERA) {
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);// Because light is affected by the scale.
glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
glLightfv(GL_LIGHT1, GL_AMBIENT, ambi);
}
}
void
inline
recalcModelViewOtherCars(void) //frecalcmodelviewothercars
{
void init();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPushMatrix();
// Translate lk_tr in the Z direction.
gluLookAt(eye.x,eye.y,eye.z, // eye is at (...
eye.x+lk_rt.x,eye.y+lk_rt.y,eye.z+lk_rt.z, // looking to
up_rt.x,up_rt.y,up_rt.z); // up is in positive Y direction */
}
void
inline
recalcModelView_Car(void) //frecalcmodelview
{
void init();
// GLfloat m[4][4]; Global variable because used after.
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPushMatrix();
if (LIGHTS_FIX_WITH_CAMERA) {
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
glLightfv(GL_LIGHT2, GL_POSITION, light2Position);
glLightfv(GL_LIGHT3, GL_POSITION, light3Position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor_Car);
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor_Car); // Because light is affected by the scale.
glLightfv(GL_LIGHT2, GL_DIFFUSE, lightZeroColor_Car);
glLightfv(GL_LIGHT3, GL_DIFFUSE, lightOneColor_Car); // Because light is affected by the scale.
}
double scalex, scaley, scalez;
// build_rotmatrix(m, curquat);
// I moved this block to interface because the rotation should be done as soon as we move the mouse.
//rotate the 3D up,lk,hor system.
/* lk_rt = mult_matrix_vector(m,lk); // lk is (0,0,1) lk_rt is the lk after the quaternion rotation
up_rt = mult_matrix_vector(m,up ); // up is (0,1,0) up_rt is up after the quaternion rotation.
hor_rt = mult_matrix_vector(m,hor); // hor is (1,0,0) hor_rt is hor after the quaternion rotation.*/
//up_rt = vectoriel (hor_rt,lk_rt);
// The translation is done in the interface mode.
// Translate lk_tr in the Z direction.
gluLookAt(eyec.x,eyec.y,eyec.z, // eye is at (...
eyec.x+lkc_rt.x,eyec.y+lkc_rt.y,eyec.z+lkc_rt.z, // looking to
upc_rt.x,upc_rt.y,upc_rt.z); // up is in positive Y direction */
// We should normalize scaling in order to maintain the same lenth for the smaller axes.
if (SCALE_SIGMA) {
scalex = 1/sigx;
scaley = 1/sigy;
scalez = 1/sigz;
}
// We should normalize scaling in order to maintain the same lenth for the smaller axes.
if (SCALE_MIDDLE) {
scalex = 1/deltax;
scaley = 1/deltay;
scalez = 1/deltaz;
}
else {
scalex = 1;
scaley = 1;
scalez = 1;
}
// Translate the origin ONLY IF INDICATED OTHERWHISE PUT IT IN 0,0,0
//
if (TRANSLATE_TO_GRAVITY) glTranslatef (-xbar*scalex,-ybar*scaley,-zbar*scalez);
if (TRANSLATE_TO_MIDDLE ) glTranslatef (-(xmin+xmax)*scalex/2,-(ymin+ymax)*scaley/2,-(zmin+zmax)*scalez/2);
// SCALE ONLY IF REQUESTED OTHERWISE DO NOT SCALE (1,1,1).
glScalef (scalex, scaley, scalez);
newModel = 0;
if (!LIGHTS_FIX_WITH_CAMERA) {
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
glLightfv(GL_LIGHT2, GL_POSITION, light2Position);
glLightfv(GL_LIGHT3, GL_POSITION, light3Position);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor_Car);
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor_Car); // Because light is affected by the scale.
glLightfv(GL_LIGHT2, GL_DIFFUSE, lightZeroColor_Car);
glLightfv(GL_LIGHT3, GL_DIFFUSE, lightOneColor_Car); // Because light is affected by the scale.
}
}
void
inline
recalcModelView_axes(void)
{
GLdouble m[4][4];
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPushMatrix();
build_rotmatrix(m, curquat);
gluLookAt(eye.x,eye.y,eye.z, // eye is at (...
0,0,0, // looking to
up.x,up.y,up.z); // up is in positive Y direction
// rotate
buildmf();
glMultMatrixf(&mf[0][0]);
// SCALE ONLY IF REQUESTED OTHERWISE DO NOT SCALE (1,1,1).
if (SCALE_SIGMA) glScalef (1/sigx,1/sigy,1/sigz); // normalized scaling.
else
if (SCALE_MIDDLE) glScalef (1/deltax,1/deltay,1/deltaz);
else
glScalef (1,1,1);
newModel = 0;
}
void
inline
recalcModelViewVehicleCentric()
{
// GLfloat m[4][4]; Global variable because used after.
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPushMatrix();
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
glLightfv(GL_LIGHT2, GL_POSITION, light2Position);
glLightfv(GL_LIGHT3, GL_POSITION, light3Position);
// Translating.
glTranslatef(TRANSLATE_X, TRANSLATE_Y,0.0);
/* Rotating.
build_rotmatrix(m, curquat_top_view);
buildmf();
glMultMatrixf(&mf[0][0]); */
gluLookAt(Geye.x, Geye.y, Geye.z, // eye is at (...
eyec.x, eyec.y, eyec.z, // looking to
Gup.x, Gup.y, Gup.z); // up is in positive Y direction */
}
void
inline
recalcModelViewTOPVIEW()
{
void init();
// GLfloat m[4][4]; Global variable because used after.
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
glPushMatrix();
// double scalex, scaley, scalez;
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
glTranslatef((LEFT + RIGHT)/2.0,(BOTTOM + TOP)/2.0,0.0);
glTranslatef(-(LEFT + RIGHT)/2.0,-(BOTTOM + TOP)/2.0,0.0);
build_rotmatrix(m, curquat_top_view);
// eye_tr = mult_matrix_vector(m,eye);
/* gluLookAt(eye_tr.x,eye_tr.y,eye_tr.z, // eye is at (...
0,0,0, // looking to
up.x,up.y,up.z); // up is in positive Y direction */
buildmf();
glTranslatef(TRANSLATE_X, TRANSLATE_Y,0.0);
glMultMatrixf(&mf[0][0]);
gluLookAt(0,0,100, // eye is at (...
0,0,0, // looking to
0,1,0); // up is in positive Y direction */
//glTranslatef(-(LEFT + RIGHT)/2.0,-(BOTTOM + TOP)/2.0,0.0);
// Draw the position of the camera (eye).
glPointSize (3);
glBegin(GL_LINES);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(eye.x,eye.y,eye.z);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(eye.x + 400*lk_rt.x,eye.y+ 400*lk_rt.y, eye.z+400*lk_rt.z);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(eye.x,eye.y,eye.z);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(eye.x + 200*up_rt.x,eye.y+ 200*up_rt.y, eye.z+200*up_rt.z);
glColor3f(1.0, 1.0, 1.0);
glEnd();
// Draw the position of mirror_eye.
glPointSize (3);
glBegin(GL_LINES);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(eye_mirror.x,eye_mirror.y,eye_mirror.z);
glColor3f(1.0, 1.0, 1.0);
glVertex3f(m1[FLAG_SELECTED_MIRROR].cr.x,m1[FLAG_SELECTED_MIRROR].cr.y,m1[FLAG_SELECTED_MIRROR].cr.z);
glColor3f(1.0, 1.0, 1.0);
glEnd();
// rotate
//glMultMatrixf(&m[0][0]);
// init();
}
inline
void
recalcboundingboxTOPVIEW()
{
glMatrixMode(GL_PROJECTION);/* set up projection transform */
glPopMatrix();
glLoadIdentity();
glOrtho (LEFT,RIGHT, BOTTOM,TOP, NEAR2,FAR2);
glPushMatrix();
}
inline
void
recalcboundingboxVehicleCentric()
{
glMatrixMode(GL_PROJECTION);/* set up projection transform */
glPopMatrix();
glLoadIdentity();
glOrtho (LEFT,RIGHT, BOTTOM,TOP, NEAR2,FAR2);
glPushMatrix();
}
inline
void
recalcboundingbox() //frecalcboundingbox
{
glMatrixMode(GL_PROJECTION);/* set up projection transform */
glPopMatrix();
glLoadIdentity();
if (FLAG_ORTHO_PERSP)
gluPerspective( /* field of view in degree */ cam_angle,
/* aspect blen, ratio */ aspect_ratio,
/* Z near */ 2.0,
/* Z far */ 2000.0);
else
glOrtho (LEFT,RIGHT, BOTTOM,TOP, NEAR2,FAR2);
glPushMatrix();
}
inline
void
recalcboundingbox_mirror(int i) //frecalcboundingbox
{
glMatrixMode(GL_PROJECTION);/* set up projection transform */
glPopMatrix();
glLoadIdentity();
/* glFrustum (-100,100,1,100,-100,20000);
glFrustum (m1[i].c1.x, m1[i].c3.x,
m1[i].c3.y, m1[i].c1.y,
calculer_distance_entre_2_plans_paralelles(m1[i].nl,
m1[i].cr,
eye_mirror), 2000); */
html //look at the hard paper called (mirror perspective) in your hard folder of VC++ Project Render.
double OD=longueur(eye_mirror,m1[i].cr);
struct point ODv = vect(m1[i].cr,eye_mirror);
gluPerspective( /* field of view in degree */
calc_angle_entre_2_vecteurs_def_par_3_pts (eye_mirror,interpoler(m1[i].c1,m1[i].c4),interpoler(m1[i].c2,m1[i].c3)),
html /* aspect ratio A'B' / m1[i].height*/ scalairv(m1[i].nl,ODv)*m1[i].width/OD/m1[i].height,
/* Z near */ OD,
/* Z far */ 500.0);
glPushMatrix();
}
void
inline
recalcModelView_mirror(int i) //frecalcmodelview
{
// GLdouble m[4][4]; Global variable because used after.
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
// glLoadIdentity();
glPushMatrix();
double scalex, scaley, scalez;
/* gluPerspective( /* field of view in degree (mirror angle) asin(vectoriel(
/* aspect blen, ratio 1.0,
/* Z near longueur(eye_mirror,m1[i].cr),
/* Z far 4000.0); */
gluLookAt(eye_mirror.x,eye_mirror.y,eye_mirror.z, // eye is at (...
m1[i].cr.x,m1[i].cr.y,m1[i].cr.z, // looking to
m1[i].up.x,m1[i].up.y,m1[i].up.z); // up is in positive Y direction
}
void
inline
texture_map_gods_eye(int i)
{
// Render what the mirror is seeing and create the texture map
// But do not display it yet, it only creates it in TEX_BUF buffer.
glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
recalcboundingboxTOPVIEW();
recalcModelViewTOPVIEW();
glCallList(9); // City.
glTranslatef (eyec.x,eyec.y,eyec.z);
glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
glCallList(19);//Vehicle
for (iti=0; iti<10; iti++) { // For each car
if (RouteNum[iti]){
recalcModelViewTOPVIEW();
glTranslatef ( CarLocationRec[iti][IndexCarLocRec[iti]].x, CarLocationRec[iti][IndexCarLocRec[iti]].y, CarLocationRec[iti][IndexCarLocRec[iti]].z);
glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
glCallList(19); // render car.
}
}
glFlush();
// reads the GL_Back buffer into the texture.
glReadBuffer(GL_BACK);
/* glCopyTexImage2D (GL_TEXTURE_2D, 0,
GL_RGB, 0, 0, 128, 128, 0); */ // very slow
glReadPixels (0,0, TEX_WIDTH,TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
glBindTexture(GL_TEXTURE_2D, texName[i]);
glTexImage2D( GL_TEXTURE_2D, // target
0, // level
//0, 0, // xoffset, yoffset
GL_RGB, // format
TEX_WIDTH, TEX_HEIGHT, // Width, Height
//im_width[0], im_height[0],
0, // border
GL_RGB, // format
GL_UNSIGNED_BYTE, // type
//image);
TEX_BUF[i][0][0]); // GLvoid *pixels */
glViewport(0,0,W, H);
}
int
calculate_closer_sensor (float x, float y, float z)
{
float toul,toul2;
int closer = 0;
toul = (x-sensors_W[0].x)*(x-sensors_W[0].x) +
(y-sensors_W[0].y)*(y-sensors_W[0].y) +
(z-sensors_W[0].z)*(z-sensors_W[0].z);
for (int wo = 1; wo<8; wo++){
toul2 = (x-sensors_W[wo].x)*(x-sensors_W[wo].x) +
(y-sensors_W[wo].y)*(y-sensors_W[wo].y) +
(z-sensors_W[wo].z)*(z-sensors_W[wo].z) ;
if (toul > toul2 ){
toul = toul2;
closer = wo;
}
}
return closer;
}
// based on my mouse rotation, it calulates Geye_V which is the God's
// eye in the vehicle coord system (eyec, lkc_rt, upc_rt, horc_rt)
void
inline
Calculate_Geye_in_Vehicle_coord(){
// Geye_V is the God's eye in the vehicle coord system (eyec, lkc_rt, upc_rt, horc_rt)
Geye_V.x = Geye_V.z=0;
Geye_V.y = GeyeHIGHT; // Original position of the Gods eye, in the Vehicle
// coordinate system (eyec, lkc_rt, upc_rt, horc_rt)
Gup_V.z=-1; // Original up position of the Gods eye, in the Vehicle
Gup_V.y=Gup_V.x=0; // coordinate system (eyec, lkc_rt, upc_rt, horc_rt)
build_rotmatrix(m, curquat_Geye);
Geye_V = mult_matrix_vector(m,Geye_V);
Gup_V = mult_matrix_vector(m, Gup_V);
}
// Geye is in the World Absolute coordinate system (000, 001, 010, 100).
void
inline
Calculate_Geye_in_Worlds_coord(){
Geye.x = Geye_V.x * horc_rt.x + Geye_V.y * upc_rt.x + Geye_V.z * lkc_rt.x;
Geye.y = Geye_V.x * horc_rt.y + Geye_V.y * upc_rt.y + Geye_V.z * lkc_rt.y;
Geye.z = Geye_V.x * horc_rt.z + Geye_V.y * upc_rt.z + Geye_V.z * lkc_rt.z;
Geye = add_vect_to_pt (Geye , eyec);
Gup.x = Gup_V.x * horc_rt.x + Gup_V.y * upc_rt.x + Gup_V.z * lkc_rt.x;
Gup.y = Gup_V.x * horc_rt.y + Gup_V.y * upc_rt.y + Gup_V.z * lkc_rt.y;
Gup.z = Gup_V.x * horc_rt.z + Gup_V.y * upc_rt.z + Gup_V.z * lkc_rt.z;
/*Gup.x = -lkc_rt.x;
Gup.y = -lkc_rt.y;
Gup.z = -lkc_rt.z; */
}
void
Calculate_Sensors_W(){
for (int wa=0; wa<8; wa++){
sensors_W[wa].x = sensors_V[wa].x * horc_rt.x + sensors_V[wa].y * upc_rt.x + sensors_V[wa].z * lkc_rt.x;
sensors_W[wa].y = sensors_V[wa].x * horc_rt.y + sensors_V[wa].y * upc_rt.y + sensors_V[wa].z * lkc_rt.y;
sensors_W[wa].z = sensors_V[wa].x * horc_rt.z + sensors_V[wa].y * upc_rt.z + sensors_V[wa].z * lkc_rt.z;
sensors_W[wa] = add_vect_to_pt (sensors_W[wa] , eyec);
}
}
void
renderBlueBox()
{
glutSolidCube(2.0);
}
void
renderRedBox()
{
glutSolidCube(2.0);
}
void
inline
texture_map_sensors_godseye(int i)
{
Calculate_Geye_in_Vehicle_coord();
Calculate_Geye_in_Worlds_coord();
Calculate_Sensors_W();
int closer_sensor;
// Render what the mirror is seeing and create the texture map
// But do not display it yet, it only creates it in TEX_BUF buffer.
glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
recalcboundingboxVehicleCentric();
recalcModelViewVehicleCentric();
// Draws the warning flashing lines on the gods eye display.
for (int ro=0; ro<10; ro++){
if (RouteNum[ro]){
if ( (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) *
(CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) +
(CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) *
(CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) +
(CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) *
(CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z)
< 25 * 25 ) {// if cars are distante more then 30 units then
closer_sensor = calculate_closer_sensor(CarLocationRec[ro][IndexCarLocRec[ro]].x, CarLocationRec[ro][IndexCarLocRec[ro]].y, CarLocationRec[ro][IndexCarLocRec[ro]].z);
recalcModelViewVehicleCentric();
glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
renderRedBox();
PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
}
else
if ( (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) *
(CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) +
(CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) *
(CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) +
(CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) *
(CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z)
< 40 * 40 ) {// if cars are distante more then 30 units then
closer_sensor = calculate_closer_sensor(CarLocationRec[ro][IndexCarLocRec[ro]].x, CarLocationRec[ro][IndexCarLocRec[ro]].y, CarLocationRec[ro][IndexCarLocRec[ro]].z);
recalcModelViewVehicleCentric();
glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
renderBlueBox();
PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
}
}
}
// Draws the warning flashing lines on the gods eye display.
// When we back up in the blue Stone.
if ( (eyec.x - 358.5) *
(eyec.x - 358.5) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 483.0) *
(eyec.z + 483.0)
< 25 * 25 ) {// if cars are distante more then 30 units then
closer_sensor = calculate_closer_sensor(358.5f, 0.0f, -483.0f);
recalcModelViewVehicleCentric();
glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
renderRedBox();
PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
}
else
if ( (eyec.x - 358.5) *
(eyec.x - 358.5) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 483.0) *
(eyec.z + 483.0)
< 40 * 40 ) {// if cars are distante more then 30 units then
closer_sensor = calculate_closer_sensor(358.5f, 0.0f, -483.0f);
recalcModelViewVehicleCentric();
glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
renderBlueBox();
PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
}
// Draws the warning flashing lines on the gods eye display.
// When we back up in the 2 stationary cars.
if ( (eyec.x - 274.61) *
(eyec.x - 274.61) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 722.49) *
(eyec.z + 722.49)
< 25 * 25 ) {// if cars are distante more then 30 units then
closer_sensor = calculate_closer_sensor(274.61f, 0.0f, -722.49f);
recalcModelViewVehicleCentric();
glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
renderRedBox();
PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
}
else
if ( (eyec.x - 274.61) *
(eyec.x - 274.61) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 722.49) *
(eyec.z + 722.49)
< 40 * 40 ) {// if cars are distante more then 30 units then
closer_sensor = calculate_closer_sensor(274.61f, 0.0f, -722.49f);
recalcModelViewVehicleCentric();
glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
renderBlueBox();
PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
}
// Draws the warning flashing lines on the gods eye display.
// When we back up in the 2 stationary cars.
if ( (eyec.x - 267.46) *
(eyec.x - 267.46) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 701.968) *
(eyec.z + 701.968)
< 25 * 25 ) {// if cars are distante more then 30 units then
closer_sensor = calculate_closer_sensor(267.46f, 0.0f, -701.968f);
recalcModelViewVehicleCentric();
glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
renderRedBox();
PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
}
else
if ( (eyec.x - 267.46) *
(eyec.x - 267.46) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 701.968) *
(eyec.z + 701.968)
< 40 * 40 ) {// if cars are distante more then 30 units then
closer_sensor = calculate_closer_sensor(267.46f, 0.0f, -701.968f);
recalcModelViewVehicleCentric();
glTranslatef (sensors_W[closer_sensor].x, sensors_W[closer_sensor].y, sensors_W[closer_sensor].z);
renderBlueBox();
PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
}
// glCallList(9); // City.
recalcModelViewVehicleCentric();
glTranslatef (eyec.x,eyec.y,eyec.z);
glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
glCallList(27); // render sensors.
for (iti=0; iti<10; iti++) { // For each car
if (RouteNum[iti]) {
recalcModelViewVehicleCentric();
glTranslatef ( CarLocationRec[iti][IndexCarLocRec[iti]].x, CarLocationRec[iti][IndexCarLocRec[iti]].y, CarLocationRec[iti][IndexCarLocRec[iti]].z);
glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
glCallList(19); // render other cars.
}
}
glFlush();
// reads the GL_Back buffer into the texture.
glReadBuffer(GL_BACK);
/* glCopyTexImage2D (GL_TEXTURE_2D, 0,
GL_RGB, 0, 0, 128, 128, 0); */ // very slow
glReadPixels (0,0, TEX_WIDTH, TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
glBindTexture(GL_TEXTURE_2D, texName[i]);
glTexImage2D( GL_TEXTURE_2D, // target
0, // level
//0, 0, // xoffset, yoffset
GL_RGB, // format
TEX_WIDTH, TEX_HEIGHT, // Width, Height
//im_width[0], im_height[0],
0, // border
GL_RGB, // format
GL_UNSIGNED_BYTE, // type
//image);
TEX_BUF[i][0][0]); // GLvoid *pixels */
glViewport(0,0,W, H);
}
void
inline
texture_map_symbolic_godseye(int i)
{
Calculate_Geye_in_Vehicle_coord();
Calculate_Geye_in_Worlds_coord();
// Render what the mirror is seeing and create the texture map
// But do not display it yet, it only creates it in TEX_BUF buffer.
glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
recalcboundingboxVehicleCentric();
recalcModelViewVehicleCentric();
// Draws the warning flashing lines on the gods eye display.
for (int ro=0; ro<10; ro++){
if (RouteNum[ro]){
if ( (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) *
(CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) +
(CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) *
(CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) +
(CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) *
(CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z)
< 25 * 25 ) {// if cars are distante more then 30 units then
glBegin(GL_LINES); // draw the line...
glColor3f (1.0f,1.0f,0.8f);
glVertex3f (CarLocationRec[ro][IndexCarLocRec[ro]].x,
CarLocationRec[ro][IndexCarLocRec[ro]].y,
CarLocationRec[ro][IndexCarLocRec[ro]].z );
glVertex3f (eyec.x, eyec.y, eyec.z);
PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
glEnd();
}
else
if ( (CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) *
(CarLocationRec[ro][IndexCarLocRec[ro]].x - eyec.x) +
(CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) *
(CarLocationRec[ro][IndexCarLocRec[ro]].y - eyec.y) +
(CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z) *
(CarLocationRec[ro][IndexCarLocRec[ro]].z - eyec.z)
< 40 * 40 ) {// if cars are distante more then 30 units then
glBegin(GL_LINES); // draw the line...
glColor3f (0.2f,0.2f,1.0f);
glVertex3f (CarLocationRec[ro][IndexCarLocRec[ro]].x,
CarLocationRec[ro][IndexCarLocRec[ro]].y,
CarLocationRec[ro][IndexCarLocRec[ro]].z );
PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
glVertex3f (eyec.x, eyec.y, eyec.z);
glEnd();
}
}
}
// Draws the warning lazer lines on the gods eye display.
// When we back up in the blue Stone.
if ( (eyec.x - 358.5) *
(eyec.x - 358.5) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 483.0) *
(eyec.z + 483.0)
< 25 * 25 ) {// if cars are distante more then 30 units then
glBegin(GL_LINES); // draw the line...
glColor3f (1.0f,1.0f,0.8f);
glVertex3f (358.5f, 0.0f, -483.0f );
glVertex3f (eyec.x, eyec.y, eyec.z);
PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
glEnd();
}
else
if ( (eyec.x - 358.5) *
(eyec.x - 358.5) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 483.0) *
(eyec.z + 483.0)
< 40 * 40 ) {// if cars are distante more then 30 units then
glBegin(GL_LINES); // draw the line...
glColor3f (0.2f,0.2f,1.0f);
glVertex3f (358.5f, 0.0f, -483.0f );
glVertex3f (eyec.x, eyec.y, eyec.z);
PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
glEnd();
}
// Draws the warning lazer lines on the gods eye display.
// When we back up in the 2 stationary cars.
if ( (eyec.x - 274.61) *
(eyec.x - 274.61) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 722.49) *
(eyec.z + 722.49)
< 25 * 25 ) {// if cars are distante more then 30 units then
glBegin(GL_LINES); // draw the line...
glColor3f (0.2f,0.2f,1.0f);
glVertex3f (274.61f, 0.0f, -722.49f );
glVertex3f (eyec.x, eyec.y, eyec.z);
PlaySound ("boom.wav",NULL,SND_ASYNC); //WinUnin
glEnd();
}
else
if ( (eyec.x - 274.61) *
(eyec.x - 274.61) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 722.49) *
(eyec.z + 722.49)
< 40 * 40 ) {// if cars are distante more then 30 units then
glBegin(GL_LINES); // draw the line...
glColor3f (0.2f,0.2f,1.0f);
glVertex3f (274.61f, 0.0f, -722.49f );
glVertex3f (eyec.x, eyec.y, eyec.z);
PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
glEnd();
}
// Draws the warning lazer lines on the gods eye display.
// When we back up in the 2 stationary cars.
if ( (eyec.x - 267.46) *
(eyec.x - 267.46) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 701.968) *
(eyec.z + 701.968)
< 25 * 25 ) {// if cars are distante more then 30 units then
glBegin(GL_LINES); // draw the line...
glColor3f (0.2f,0.2f,1.0f);
glVertex3f (267.46f, 0.0f, -701.968f );
glVertex3f (eyec.x, eyec.y, eyec.z);
PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
glEnd();
}
else
if ( (eyec.x - 267.46) *
(eyec.x - 267.46) +
(eyec.y - 0.0) *
(eyec.y - 0.0) +
(eyec.z + 701.968) *
(eyec.z + 701.968)
< 40 * 40 ) {// if cars are distante more then 30 units then
glBegin(GL_LINES); // draw the line...
glColor3f (0.2f,0.2f,1.0f);
glVertex3f (267.46f, 0.0f, -701.968f );
glVertex3f (eyec.x, eyec.y, eyec.z);
PlaySound ("booom.wav",NULL,SND_ASYNC); //WinUnin
glEnd();
}
// glCallList(9); // City.
glTranslatef (eyec.x,eyec.y,eyec.z);
glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
glCallList(19);//Vehicle
for (iti=0; iti<10; iti++) { // For each car
if (RouteNum[iti]){
recalcModelViewVehicleCentric();
glTranslatef ( CarLocationRec[iti][IndexCarLocRec[iti]].x, CarLocationRec[iti][IndexCarLocRec[iti]].y, CarLocationRec[iti][IndexCarLocRec[iti]].z);
glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
glCallList(19); // render car.
}
}
glFlush();
// reads the GL_Back buffer into the texture.
glReadBuffer(GL_BACK);
/* glCopyTexImage2D (GL_TEXTURE_2D, 0,
GL_RGB, 0, 0, 128, 128, 0); */ // very slow
glReadPixels (0,0, TEX_WIDTH, TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
glBindTexture(GL_TEXTURE_2D, texName[i]);
glTexImage2D( GL_TEXTURE_2D, // target
0, // level
//0, 0, // xoffset, yoffset
GL_RGB, // format
TEX_WIDTH, TEX_HEIGHT, // Width, Height
//im_width[0], im_height[0],
0, // border
GL_RGB, // format
GL_UNSIGNED_BYTE, // type
//image);
TEX_BUF[i][0][0]); // GLvoid *pixels */
glViewport(0,0,W, H);
}
void
inline
texture_map_vehicle_centric_display(int i)
{
Geye.x = eyec.x;
Geye.y = eyec.x+GeyeHIGHT;
Geye.z = eyec.z;
Gup.x = -lkc_rt.x;
Gup.y = -lkc_rt.y;
Gup.z = -lkc_rt.z;
Glk.x = Glk.z = 0;
Glk.y = -1.0;
// Render what the mirror is seeing and create the texture map
// But do not display it yet, it only creates it in TEX_BUF buffer.
glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
recalcboundingboxVehicleCentric();
recalcModelViewVehicleCentric();
glCallList(9); // City.
glTranslatef (eyec.x,eyec.y,eyec.z);
glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
glCallList(19);//Vehicle
for (iti=0; iti<10; iti++) { // For each car
if (RouteNum[iti]){
recalcModelViewVehicleCentric();
glTranslatef ( CarLocationRec[iti][IndexCarLocRec[iti]].x, CarLocationRec[iti][IndexCarLocRec[iti]].y, CarLocationRec[iti][IndexCarLocRec[iti]].z);
glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
glCallList(19); // render car.
}
}
glFlush();
// reads the GL_Back buffer into the texture.
glReadBuffer(GL_BACK);
/* glCopyTexImage2D (GL_TEXTURE_2D, 0,
GL_RGB, 0, 0, 128, 128, 0); */ // very slow
glReadPixels (0,0, TEX_WIDTH, TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
glBindTexture(GL_TEXTURE_2D, texName[i]);
glTexImage2D( GL_TEXTURE_2D, // target
0, // level
//0, 0, // xoffset, yoffset
GL_RGB, // format
TEX_WIDTH, TEX_HEIGHT, // Width, Height
//im_width[0], im_height[0],
0, // border
GL_RGB, // format
GL_UNSIGNED_BYTE, // type
//image);
TEX_BUF[i][0][0]); // GLvoid *pixels */
glViewport(0,0,W, H);
}
//____________________________________texture_map___________________________________________
//ftexture_map
void
inline
texture_map(int i) //ftexture_map
{
extern void Draw_Vrml(Type_Transform *, int numlist);
// Render what the mirror is seeing and create the texture map
// But do not display it yet, it only creates it in TEX_BUF buffer.
// calc the new postion of the virtual eye of the mirror.
eye_mirror = calc_the_symetric_of_a_pt_rel_to_a_plane(m1[i].nl,m1[i].cr,eye);
eye_mirror = add_vect_to_pt (eye_mirror,
mul_vect_par_nbr_reel(
sous_vect_to_pt (eye_mirror , m1[i].cr) ,
(mz[i]/200.0)));
// put the virtual camera behind the mirror symetrically to the eye.
// Recalc Model View.
glViewport(0,0, TEX_WIDTH, TEX_HEIGHT);
recalcboundingbox_mirror(i);
recalcModelView_mirror(i);
glCallList(9); // City.
//Render other cars.
for (iti=0; iti<10; iti++) { // For each other car
if (RouteNum[iti]) {
recalcModelView_mirror(i);
glTranslatef ( CarLocationRec[iti][IndexCarLocRec[iti]].x, CarLocationRec[iti][IndexCarLocRec[iti]].y, CarLocationRec[iti][IndexCarLocRec[iti]].z);
glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
glCallList(19); // render car.
}
}
glTranslatef (eyec.x,eyec.y,eyec.z);
glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
glScalef( car_scale_factor , -car_scale_factor , car_scale_factor);
glCallList(19);//Vehicle
glFlush();
// reads the GL_Back buffer into the texture.
glReadBuffer(GL_BACK);
/* glCopyTexImage2D (GL_TEXTURE_2D, 0,
GL_RGB, 0, 0, 128, 128, 0); */ // very slow
glReadPixels (0,0, TEX_WIDTH,TEX_HEIGHT, GL_RGB, GL_UNSIGNED_BYTE,TEX_BUF[i][0][0]); // image[0][0]); //
glBindTexture(GL_TEXTURE_2D, texName[i]);
glTexImage2D( GL_TEXTURE_2D, // target
0, // level
//0, 0, // xoffset, yoffset
GL_RGB, // format
TEX_WIDTH, TEX_HEIGHT, // Width, Height
//im_width[0], im_height[0],
0, // border
GL_RGB, // format
GL_UNSIGNED_BYTE, // type
//image);
TEX_BUF[i][0][0]); // GLvoid *pixels */
glViewport(0,0,W, H);
}
//_______________________________draw_mirror____________________________________________
//fdraw_mirror
inline
void draw_mirror(int i)
{
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
#ifdef GL_VERSION_1_1
glBindTexture(GL_TEXTURE_2D, texName[i]);
#endif
glBegin(GL_QUADS);
glTexCoord2f(1.0, 1.0);
glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
glTexCoord2f(1.0, 0.0);
glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
glTexCoord2f(0.0, 0.0);
glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
glTexCoord2f(0.0, 1.0);
glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
glEnd();
glPointSize (4);
glBegin(GL_LINES);
glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
}
inline
void draw_mirror_top_view(int i)
{
glPointSize (4);
glBegin(GL_LINES);
glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
glVertex3f(m1[i].c2.x, m1[i].c2.y, m1[i].c2.z); html //finitialize_some_var
glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
glVertex3f(m1[i].c3.x, m1[i].c3.y, m1[i].c3.z); html //finitialize_some_var
glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
glVertex3f(m1[i].c4.x, m1[i].c4.y, m1[i].c4.z); html //finitialize_some_var
glVertex3f(m1[i].c1.x, m1[i].c1.y, m1[i].c1.z); html //finitialize_some_var
glEnd();
glFlush();
glDisable(GL_TEXTURE_2D);
}
void
inline draw_bg()
{
// Set Projection Matrix
glMatrixMode(GL_PROJECTION);/* set up projection transform */
glLoadIdentity();
glOrtho (0,1, 0,1, -1,1);
// Set ModelView Matrix.
glMatrixMode (GL_MODELVIEW);
glLoadIdentity();
//glDisable(GL_LIGHTING);
// Draw bg
glBegin (GL_POLYGON);
glColor3f (0.5f, 0.0f,0.0f);
glVertex3f (1 , 0,-0.5f);
glColor3f (0.4f,0.0f,0.0f);
glVertex3f (1, 1,-0.5f);
glColor3f (0.9f,1.0f,0.0f);
glVertex3f (0,1,-0.5f);
glColor3f (0.2f,0.0f,1.0f);
glVertex3f (0 ,0,-0.5);
glEnd();
}
void inline draw_light_position()
{
glPointSize (5);
glBegin(GL_POINTS);
glColor3f (1.0f,1.0f,1.0f);
glVertex3f (lightZeroPosition[0], lightZeroPosition[1], lightZeroPosition[2]);
glVertex3f (lightOnePosition [0], lightOnePosition [1], lightOnePosition [2]);
glEnd();
}
void redraw4()
{
extern struct Virtual_Espace espace[DimX][DimY][DimZ];
void redraw();
if (FLAG_TOGGLE_MENU1) {
glEnable(GL_LIGHTING);
}
glDrawBuffer(GL_BACK_LEFT);
glClearColor (.1f,0.2f,0.1f,1);
glClearColor (.6f,0.4f,0.2f,0.4f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (viewport&& !FLAG_TOP_VIEW){
// draw command margin then set the viewport for the 3D
draw_commande_de_bord(); // Sets the control band viewport and draws in it.
glViewport (CDW,0,W,H); // set the viewport
}
else
if (viewport && FLAG_TOP_VIEW) {
draw_commande_de_bord(); // Sets the control band viewport and draws in it.
glViewport (TOP_V_X,TOP_V_Y,TOP_W,TOP_H);
draw_bg();
if (FLAG_TOGGLE_MENU1) glEnable(GL_LIGHTING);
recalcboundingboxTOPVIEW();
recalcModelViewTOPVIEW();
if (Draw_relative_axe) draw_axes();
if (SHOW_LOCATION_DIRECTION_OF_LIGHTS) draw_light_position();
for (int i= 0; i<DimX; i=i+2)
for (int j=0; j<DimY; j=j+2)
for (int k=0; k<DimZ; k=k+2)
if (espace[i][j][k].FULL){
glBegin (GL_POINTS);
glVertex3d (i,j,k);
glEnd();
}
glViewport (CDW,0,W,H-TOP_H); // establish the viewport for the rendering of the scene.
}
else {
// Set all the screen viewport for the 3D rendering the left eye..
glViewport (0,0,W ,H);
}
// at this point we know what the glViewport is for the main scene.
if (displayListInited) {
if (FLAG_TOGGLE_MENU1) { glEnable(GL_LIGHTING); }
// Recalc Model View.
recalcboundingbox();
recalcModelView();
for (int i= 0; i<DimX; i=i+2)
for (int j=0; j<DimY; j=j+2)
for (int k=0; k<DimZ; k=k+2)
if (espace[i][j][k].FULL){
glBegin (GL_POINTS);
glVertex3d (i,j,k);
glEnd();
}
}
else {
Draw_Vrml(CNC,9); // Draws the Vehicle CNC = Current Node City.
Draw_Vrml(CNV,19); // Draws the Vehicle CNV = Current Node Vehicle
displayListInited = 1;
redraw();
glFlush();
}
glutSwapBuffers();
}
inline void fix_light_car()
{
if (LIGHTS_FIX_WITH_CAMERA) {
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor_Car);
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor_Car);// Because light is affected by the scale.
}
if (!LIGHTS_FIX_WITH_CAMERA) {
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor_Car);
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor_Car); // Because light is affected by the scale.
}
}
void
redraw() //fredraw
{
extern struct Virtual_Espace espace[DimX][DimY][DimZ];
extern void Draw_Vrml(Type_Transform *, int numlist);
extern void recalc_mirror_coord_in_fix_coord_based_on_camera_movements(int i);
extern double XmaxVrmlCity, YmaxVrmlCity, ZmaxVrmlCity;
extern double XminVrmlCity, YminVrmlCity, ZminVrmlCity;
int i;
if (FLAG_TOGGLE_MENU1) {
glEnable(GL_LIGHTING);
}
else
glDisable (GL_LIGHTING);
glDrawBuffer(GL_BACK_LEFT);
glClearColor (0.05882f, 0.498f, 0.8353f,1.0f);
// Texture map all mirrors
for (i=0;i<number_of_mirrors; i++)
if (FLAG_TOGGLE_MIRROR[i]) {
if (FLAG_FIX_MIRROR) recalc_mirror_coord_in_fix_coord_based_on_camera_movements(i);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (FLAG_MOVE_GODS_EYE==1 && i==0)
texture_map_gods_eye(i);
else
if (FLAG_MOVE_GODS_EYE == 2 && i==0)
texture_map_vehicle_centric_display(0);
else
if (FLAG_MOVE_GODS_EYE == 3 && i==0)
texture_map_symbolic_godseye(0);
else if (FLAG_MOVE_GODS_EYE == 4 && i==0)
texture_map_sensors_godseye(0);
else
texture_map(i);
}
glClearColor (0.05882f, 0.498f, 0.8353f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (viewport&& !FLAG_TOP_VIEW){
// draw command margin then set the viewport for the 3D
draw_commande_de_bord(); // Sets the control band viewport and draws in it.
glViewport (CDW,0,W,H); // set the viewport
}
else
if (viewport && FLAG_TOP_VIEW) {
draw_commande_de_bord(); // Sets the control band viewport and draws in it.
glViewport (TOP_V_X,TOP_V_Y,TOP_W,TOP_H);
draw_bg();
if (FLAG_TOGGLE_MENU1) glEnable(GL_LIGHTING);
recalcboundingboxTOPVIEW();
recalcModelViewTOPVIEW();
if (Draw_relative_axe) draw_axes();
if (SHOW_LOCATION_DIRECTION_OF_LIGHTS) draw_light_position();
glCallList(9); // City.
for (i=0; i<number_of_mirrors; i++)
if (FLAG_TOGGLE_MIRROR[i]) {
draw_mirror_top_view(i);
}
// Rotate the car first
glTranslatef (eyec.x,eyec.y,eyec.z);
glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
glCallList(19);//Vehicle
/*for (int i=0; i<DimX; i=i+6)
for (int j=0; j<DimY; j=j+6)
for (int k=0; k<DimZ; k=k+6)
if (espace[i][j][k].FULL){
glBegin (GL_POINTS);
xx = i*(XmaxVrmlCity - XminVrmlCity)/DimX + XminVrmlCity;
yy = j*(YmaxVrmlCity - YminVrmlCity)/DimY + YminVrmlCity;
zz = k*(ZmaxVrmlCity - ZminVrmlCity)/DimZ + ZminVrmlCity;
glVertex3f (xx,yy,zz);
glEnd();
}*/
//recalcModelView_Car();
for (iti=0; iti<10; iti++) { // For each car
if (RouteNum[iti]){
recalcModelViewOtherCars();
glTranslatef ( CarLocationRec[iti][IndexCarLocRec[iti]].x, CarLocationRec[iti][IndexCarLocRec[iti]].y, CarLocationRec[iti][IndexCarLocRec[iti]].z);
glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
glCallList(19); // render car.
}
}
glViewport (CDW,0,W,H-TOP_H); // establish the viewport for the rendering of the scene.
} //if (viewport && FLAG_TOP_VIEW
else { // Set all the screen viewport for the 3D rendering the left eye..
glViewport (0,0,W ,H);
}
// at this point we know what the glViewport is for the main scene.
// at this point we know what the glViewport is for the main scene.
if (displayListInited) {
// Draw
// eye.x = -baseline;
// Draw axes left eye
if (FLAG_TOGGLE_MENU1) { glEnable(GL_LIGHTING); }
// Recalc Model View.
recalcboundingbox();
recalcModelView();
glCallList(9);
for (i=0; i<number_of_mirrors; i++)
if (FLAG_TOGGLE_MIRROR[i]) {
draw_mirror(i);
}
//recalcModelView_Car();
glTranslatef (eyec.x,eyec.y,eyec.z);
glRotatef (2*acos(curquatc[0])*180.0/3.15169,curquatc[1], curquatc[2],curquatc[3]);
glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
glCallList(19); // render car.
for (iti=0; iti<10; iti++) { // For each car
if (RouteNum[iti]){
recalcModelViewOtherCars();
glTranslatef ( CarLocationRec[iti][IndexCarLocRec[iti]].x, CarLocationRec[iti][IndexCarLocRec[iti]].y, CarLocationRec[iti][IndexCarLocRec[iti]].z);
glRotatef (2*acos(CarLocationRec[iti][IndexCarLocRec[iti]].quat[0])*180.0/3.15169,CarLocationRec[iti][IndexCarLocRec[iti]].quat[1], CarLocationRec[iti][IndexCarLocRec[iti]].quat[2],CarLocationRec[iti][IndexCarLocRec[iti]].quat[3]);
glScalef(car_scale_factor, -car_scale_factor, car_scale_factor);
glCallList(19); // render car.
}
}
}
else {
/* otherwise compile and execute to create the display list
glNewList(28, GL_COMPILE_AND_EXECUTE);
/* front face
glPointSize (pt_size);
glBegin(GL_POINTS);
/* glColor3f(0.0, 0.7, 0.1); green
printf ("Drawing for the first time \n");
for (i=0; i<dim[0]; i=i+fraction){
if ((xc[i] != NaN) && (yc[i] != NaN) && (zc[i] != NaN)){
glColor3f (cxx[i], cyy[i], czz[i]);
glVertex3f(xc[i],yc[i],zc[i]);
}
}
glEnd();
glEndList(); */
Draw_Vrml(CNC,9); // Draws the Vehicle CNV = Current Node City
Draw_Vrml(CNV,19); // Draws the Vehicle CNV = Current Node Vehicle
Draw_Vrml(CNSe,27);// Draws the display list 27 of the Censors.
displayListInited = 1;
redraw();
glFlush();
}
glutSwapBuffers();
}
void
load_configuration(char num)
{
FILE *file;
char configurationNum [15];
strcpy (configurationNum,"configuration");
strncat (configurationNum, &num,1);
if ((file = fopen (configurationNum,"r")) == NULL)
printf ("\n pas de chance l'ami ton fichier est corrompu 95478567\n");
fscanf (file, "number_of_mirrors %d \n",
&number_of_mirrors);
for (int v=0; v<6;v++){
fscanf (file, "m1[v].cr %f %f %f \n",
&m1[v].cr.x, &m1[v].cr.y, &m1[v].cr.z);
fscanf (file, "m1[v].c1 %f %f %f \n",
&m1[v].c1.x, &m1[v].c1.y, &m1[v].c1.z);
fscanf (file, "m1[v].c2 %f %f %f \n",
&m1[v].c2.x, &m1[v].c2.y, &m1[v].c2.z);
fscanf (file, "m1[v].c3 %f %f %f \n",
&m1[v].c3.x, &m1[v].c3.y, &m1[v].c3.z);
fscanf (file, "m1[v].c4 %f %f %f \n",
&m1[v].c4.x, &m1[v].c4.y, &m1[v].c4.z);
fscanf (file, "m1[v].cc1 %f %f %f \n",
&m1[v].cc1.x, &m1[v].cc1.y, &m1[v].cc1.z);
fscanf (file, "m1[v].cc2 %f %f %f \n",
&m1[v].cc2.x, &m1[v].cc2.y, &m1[v].cc2.z);
fscanf (file, "m1[v].cc3 %f %f %f \n",
&m1[v].cc3.x, &m1[v].cc3.y, &m1[v].cc3.z);
fscanf (file, "m1[v].cc4 %f %f %f \n",
&m1[v].cc4.x, &m1[v].cc4.y, &m1[v].cc4.z);
fscanf (file, "m1[v].nl %f %f %f \n",
&m1[v].nl.x , &m1[v].nl.y, &m1[v].nl.z);
fscanf (file, "m1[v].up %f %f %f \n",
&m1[v].up.x , &m1[v].up.y, &m1[v].up.z);
fscanf (file, "m1[v].side %f %f %f \n",
&m1[v].side.x , &m1[v].side.y, &m1[v].side.z);
fscanf (file, "m1[v].width %f, m1[v].height %f \n \n \n",
&m1[v].width , &m1[v].height);
}
fscanf (file, "angle %lf \n",
&angle);
fscanf (file, "curquat[.] %lf %lf %lf %lf \n",
&curquat[0], &curquat[1], &curquat[2], &curquat[3]);
fscanf (file, "curquatc[.] %lf %lf %lf %lf \n",
&curquatc[0], &curquatc[1], &curquatc[2], &curquatc[3]);
fscanf (file, "curquat_mirror[.] %lf %lf %lf %lf \n",
&curquat_mirror[0], &curquat_mirror[1], &curquat_mirror[2], &curquat_mirror[3]);
fscanf (file, "curquat_top_view[.] %lf %lf %lf %lf \n",
&curquat_top_view[0], &curquat_top_view[1], &curquat_top_view[2], &curquat_top_view[3]);
fscanf (file, "curquat_light0[.] %lf %lf %lf %lf \n",
&curquat_light0[0], &curquat_light0[1], &curquat_light0[2], &curquat_light0[3]);
fscanf (file, "curquat_light1[.] %lf %lf %lf %lf \n",
&curquat_light1[0], &curquat_light1[1], &curquat_light1[2], &curquat_light1[3]);
fscanf (file, "lastquat_top_view[.] %lf %lf %lf %lf \n",
&lastquat_top_view[0], &lastquat_top_view[1], &lastquat_top_view[2], &lastquat_top_view[3]);
fscanf (file, "lastquat[.] %lf %lf %lf %lf \n",
&lastquat[0], &lastquat[1], &lastquat[2], &lastquat[3]);
fscanf (file, "lastquat_mirror[.] %lf %lf %lf %lf \n",
&lastquat_mirror[0], &lastquat_mirror[1], &lastquat_mirror[2], &lastquat_mirror[3]);
fscanf (file, "lastquat_light0[.] %lf %lf %lf %lf \n",
&lastquat_light0[0], &lastquat_light0[1], &lastquat_light0[2], &lastquat_light0[3]);
fscanf (file, "lastquat_light1[.] %lf %lf %lf %lf \n",
&lastquat_light1[0], &lastquat_light1[1], &lastquat_light1[2], &lastquat_light1[3]);
fscanf (file, "newModel %d scalefactor %lf \n",
&newModel, &scalefactor);
fscanf (file, "TOP %lf \n BOTTOM %lf \n LEFT %lf \n RIGTH %lf \n TRANSLATE_X %lf \n TRANSLATE_Y %lf \n TRANSLATE_Z %lf \n TRANSLATE_H %lf \n NEAR2 %lf FAR2 %lf \n \n ",
&TOP, &BOTTOM, &LEFT, &RIGHT, &TRANSLATE_X, &TRANSLATE_Y, &TRANSLATE_Z, &TRANSLATE_H, &NEAR2, &FAR2);
fscanf (file, "FLAG_MOVE_CAR %d FLAG_MOVE_SCENE %d WALK_SLOWLY %d",
&FLAG_MOVE_CAR, &FLAG_MOVE_SCENE, &WALK_SLOWLY);
fscanf (file ,"DriverPos %f %f %f \n",
&DriverPos.x, &DriverPos.y, &DriverPos.z);
fscanf (file, "eye %f %f %f \n",
&eye.x, &eye.y, &eye.z);
fscanf (file, "eye1 %f %f %f \n",
&eye1.x, &eye1.y, &eye1.z);
fscanf (file, "eye2 %f %f %f \n",
&eye2.x, &eye2.y, &eye2.z);
fscanf (file, "eye_mirror %f %f %f \n",
&eye_mirror.x, &eye_mirror.y, &eye_mirror.z);
fscanf (file ,"eyec %f %f %f \n",
&eyec.x, &eyec.y, &eyec.z);
fscanf (file, "eyeP %f %f %f \n",
&eyeP.x, &eyeP.y, &eyeP.z);
fscanf (file, "lk %f %f %f \n",
&lk.x, &lk.y, &lk.z);
fscanf (file, "up %f %f %f \n",
&up.x, &up.y, &up.z);
fscanf (file, "hor %f %f %f \n",
&hor.x, &hor.y, &hor.z);
fscanf (file, "lk_rt %f %f %f \n",
&lk_rt.x, &lk_rt.y, &lk_rt.z);
fscanf (file, "up_rt %f %f %f \n",
&up_rt.x, &up_rt.y, &up_rt.z);
fscanf (file, "hor_rt %f %f %f \n",
&hor_rt.x, &hor_rt.y, &hor_rt.z);
fscanf (file, "lkc_rt %f %f %f \n",
&lkc_rt.x, &lkc_rt.y, &lkc_rt.z);
fscanf (file, "upc_rt %f %f %f \n",
&upc_rt.x, &upc_rt.y, &upc_rt.z);
fscanf (file, "horc_rt %f %f %f \n",
&horc_rt.x, &horc_rt.y, &horc_rt.z);
fscanf (file, "lkP %f %f %f \n",
&lkP.x , &lkP.y, &lkP.z);
fscanf (file, "upP %f %f %f \n",
&upP.x, &upP.y, &upP.z);
fscanf (file, "horP %f %f %f \n",
&horP.x, &horP.y, &horP.z);
fscanf (file, "meye %f %f %f \n",
&meye.x , &meye.y, &meye.z);
fscanf (file, "MEM_POINT %f %f %f \n",
&MEM_POINT.x, &MEM_POINT.y, &MEM_POINT.z);
fscanf (file, "pos_light0 %f %f %f \n",
&pos_light0.x, &pos_light0.y, &pos_light0.z);
fscanf (file, "pos_light1 %f %f %f \n",
&pos_light1.x, &pos_light1.y, &pos_light1.z);
fscanf (file, "z %lf teta %lf phi %lf teta2 %lf cam_angle %lf",
&z, &teta, &phi, &teta2, &cam_angle);
fscanf (file, "viewport %d FLAG_TOP_VIEW %d FLAG_SELECTED_MIRROR %d FLAG_TOGGLE_MIRROR[0] %d",
&viewport , &FLAG_TOP_VIEW , &FLAG_SELECTED_MIRROR , &FLAG_TOGGLE_MIRROR[0]);
fscanf (file, "FLAG_TOGGLE_MIRROR[1] %d %d %d %d %d %d \n",
&FLAG_TOGGLE_MIRROR[0] , &FLAG_TOGGLE_MIRROR[1], &FLAG_TOGGLE_MIRROR[2], &FLAG_TOGGLE_MIRROR[3],
&FLAG_TOGGLE_MIRROR[4] , &FLAG_TOGGLE_MIRROR[5]);
fscanf (file, "FLAG_FRONT_VIEW %d FLAG_TOGGLE_MENU1 %d FLAG_TOGGLE_TEXTURE_MAP %d \n",
&FLAG_FRONT_VIEW , &FLAG_TOGGLE_MENU1 , &FLAG_TOGGLE_TEXTURE_MAP);
fscanf (file, "FLAG_DROP_MENU %d TRANSLATE_TO_GRAVITY %d TRANSLATE_TO_MIDDLE %d \n",
&FLAG_DROP_MENU , &TRANSLATE_TO_GRAVITY , &TRANSLATE_TO_MIDDLE);
fscanf (file, "Draw_relative_axe %d Draw_light_position %d spinning %d expand_carre1 %d\n",
&Draw_relative_axe , &Draw_light_position , &spinning , &expand_carre1);
fscanf (file, "expand_carre2 %d expand_carre3 %d APPLY_MOUSE_MOTION %d FLAG_ORTHO_PERSP %d \n",
&expand_carre2 , &expand_carre3 , &APPLY_MOUSE_MOTION , &FLAG_ORTHO_PERSP);
fscanf (file, "FLAG_FIX_MIRROR %d FLAG_HORIZ %d SHOW_LOCATION_DIRECTION_OF_LIGHTS %d \n",
&FLAG_FIX_MIRROR , &FLAG_HORIZ , &SHOW_LOCATION_DIRECTION_OF_LIGHTS);
fscanf (file, "LIGHTS_FIX_WITH_CAMERA %d",
&LIGHTS_FIX_WITH_CAMERA);
fscanf (file, "Center_Of_Rot_Of_Lights %f %f %f \n",
&Center_Of_Rot_Of_Lights.x, &Center_Of_Rot_Of_Lights.y, &Center_Of_Rot_Of_Lights.z);
fscanf (file, "lightZeroPosition[.] %f %f %f %f \n",
&lightZeroPosition[0], &lightZeroPosition[1], &lightZeroPosition[2], &lightZeroPosition[3]);
fscanf (file, "lightOnePosition[.] %f %f %f %f \n",
&lightOnePosition[0] , &lightOnePosition[1], &lightOnePosition[2] , &lightOnePosition[3]);
fscanf (file, "lightZeroColor[.] %f %f %f %f \n",
&lightZeroColor[0], &lightZeroColor[1], &lightZeroColor[2], &lightZeroColor[3]);
fscanf (file, "lightOneColor[.] %f %f %f %f \n",
&lightOneColor[0], &lightOneColor[1], &lightOneColor[2], &lightOneColor[3]);
fscanf (file, "lightZeroColor_Car[.] %f %f %f %f \n",
&lightZeroColor_Car[0],&lightZeroColor_Car[1],&lightZeroColor_Car[2],&lightZeroColor_Car[3]);
fscanf (file, "lightOneColor_Car[.] %f %f %f %f \n",
&lightOneColor_Car[0], &lightOneColor_Car[1], &lightOneColor_Car[2], &lightOneColor_Car[3] );
fscanf (file, "aspect_ratio %lf \n", &aspect_ratio);
fscanf (file, "FLAG_MOVE_GODS_EYE %d \n", &FLAG_MOVE_GODS_EYE);
fscanf (file, "Geye %f %f %f \n", &Geye.x, &Geye.y, &Geye.z);
fscanf (file, "Gup %f %f %f \n", &Gup.x, &Gup.y, &Gup.z);
fscanf (file, "Ghor %f %f %f \n", &Ghor.x, &Ghor.y, &Ghor.z);
fscanf (file, "Glk %f %f %f \n", &Glk.x, &Glk.y, &Glk.z);
fscanf (file, "Gup_V %f %f %f \n", &Gup_V.x, &Gup_V.y, &Gup_V.z);
fscanf (file, "Geye_V %f %f %f \n", &Geye_V.x, &Geye_V.y, &Geye_V.z);
fscanf (file, "curquat_Geye[.] %lf %lf %lf %lf \n",
&curquat_Geye[0], &curquat_Geye[1], &curquat_Geye[2], &curquat_Geye[3]);
for (i=0;i<9;i++)
fscanf (file, "mz[i] %d \n", &mz[i]);
fclose (file);
}
void
save_configurations(char num){
FILE *file;
char configurationNum [15];
strcpy (configurationNum,"configuration");
strncat (configurationNum, &num, 1);
if ((file = fopen (configurationNum,"w")) == NULL)
printf ("\n pas de chance l'ami ton fichier est corrompu 95478567\n");
fprintf (file, "number_of_mirrors %d \n",
number_of_mirrors);
for (int v=0; v<6;v++){
fprintf (file, "m1[v].cr %f %f %f \n",
m1[v].cr.x, m1[v].cr.y, m1[v].cr.z);
fprintf (file, "m1[v].c1 %f %f %f \n",
m1[v].c1.x, m1[v].c1.y, m1[v].c1.z);
fprintf (file, "m1[v].c2 %f %f %f \n",
m1[v].c2.x, m1[v].c2.y, m1[v].c2.z);
fprintf (file, "m1[v].c3 %f %f %f \n",
m1[v].c3.x, m1[v].c3.y, m1[v].c3.z);
fprintf (file, "m1[v].c4 %f %f %f \n",
m1[v].c4.x, m1[v].c4.y, m1[v].c4.z);
fprintf (file, "m1[v].cc1 %f %f %f \n",
m1[v].cc1.x, m1[v].cc1.y, m1[v].cc1.z);
fprintf (file, "m1[v].cc2 %f %f %f \n",
m1[v].cc2.x, m1[v].cc2.y, m1[v].cc2.z);
fprintf (file, "m1[v].cc3 %f %f %f \n",
m1[v].cc3.x, m1[v].cc3.y, m1[v].cc3.z);
fprintf (file, "m1[v].cc4 %f %f %f \n",
m1[v].cc4.x, m1[v].cc4.y, m1[v].cc4.z);
fprintf (file, "m1[v].nl %f %f %f \n",
m1[v].nl.x , m1[v].nl.y, m1[v].nl.z);
fprintf (file, "m1[v].up %f %f %f \n",
m1[v].up.x , m1[v].up.y, m1[v].up.z);
fprintf (file, "m1[v].side %f %f %f \n",
m1[v].side.x , m1[v].side.y, m1[v].side.z);
fprintf (file, "m1[v].width %f, m1[v].height %f \n \n \n",
m1[v].width , m1[v].height);
}
fprintf (file, "angle %lf \n",
angle);
fprintf (file, "curquat[.] %lf %lf %lf %lf \n",
curquat[0], curquat[1], curquat[2], curquat[3]);
fprintf (file, "curquatc[.] %lf %lf %lf %lf \n",
curquatc[0], curquatc[1], curquatc[2], curquatc[3]);
fprintf (file, "curquat_mirror[.] %lf %lf %lf %lf \n",
curquat_mirror[0], curquat_mirror[1], curquat_mirror[2], curquat_mirror[3]);
fprintf (file, "curquat_top_view[.] %lf %lf %lf %lf \n",
curquat_top_view[0], curquat_top_view[1], curquat_top_view[2], curquat_top_view[3]);
fprintf (file, "curquat_light0[.] %lf %lf %lf %lf \n",
curquat_light0[0], curquat_light0[1], curquat_light0[2], curquat_light0[3]);
fprintf (file, "curquat_light1[.] %lf %lf %lf %lf \n",
curquat_light1[0], curquat_light1[1], curquat_light1[2], curquat_light1[3]);
fprintf (file, "lastquat_top_view[.] %lf %lf %lf %lf \n",
lastquat_top_view[0], lastquat_top_view[1], lastquat_top_view[2], lastquat_top_view[3]);
fprintf (file, "lastquat[.] %lf %lf %lf %lf \n",
lastquat[0], lastquat[1], lastquat[2], lastquat[3]);
fprintf (file, "lastquat_mirror[.] %lf %lf %lf %lf \n",
lastquat_mirror[0], lastquat_mirror[1], lastquat_mirror[2], lastquat_mirror[3]);
fprintf (file, "lastquat_light0[.] %lf %lf %lf %lf \n",
lastquat_light0[0], lastquat_light0[1], lastquat_light0[2], lastquat_light0[3]);
fprintf (file, "lastquat_light1[.] %lf %lf %lf %lf \n",
lastquat_light1[0], lastquat_light1[1], lastquat_light1[2], lastquat_light1[3]);
fprintf (file, "newModel %d scalefactor %lf \n",
newModel, scalefactor);
fprintf (file, "TOP %lf \n BOTTOM %lf \n LEFT %lf \n RIGTH %lf \n TRANSLATE_X %lf \n TRANSLATE_Y %lf \n TRANSLATE_Z %lf \n TRANSLATE_H %lf \n NEAR2 %lf FAR2 %lf \n \n ",
TOP, BOTTOM, LEFT, RIGHT, TRANSLATE_X, TRANSLATE_Y, TRANSLATE_Z, TRANSLATE_H, NEAR2, FAR2);
fprintf (file, "FLAG_MOVE_CAR %d FLAG_MOVE_SCENE %d WALK_SLOWLY %d",
FLAG_MOVE_CAR, FLAG_MOVE_SCENE, WALK_SLOWLY);
fprintf (file ,"DriverPos %f %f %f \n",
DriverPos.x, DriverPos.y, DriverPos.z);
fprintf (file, "eye %f %f %f \n",
eye.x, eye.y, eye.z);
fprintf (file, "eye1 %f %f %f \n",
eye1.x, eye1.y, eye1.z);
fprintf (file, "eye2 %f %f %f \n",
eye2.x, eye2.y, eye2.z);
fprintf (file, "eye_mirror %f %f %f \n",
eye_mirror.x, eye_mirror.y, eye_mirror.z);
fprintf (file ,"eyec %f %f %f \n",
eyec.x, eyec.y, eyec.z);
fprintf (file, "eyeP %f %f %f \n",
eyeP.x, eyeP.y, eyeP.z);
fprintf (file, "lk %f %f %f \n",
lk.x, lk.y, lk.z);
fprintf (file, "up %f %f %f \n",
up.x, up.y, up.z);
fprintf (file, "hor %f %f %f \n",
hor.x, hor.y, hor.z);
fprintf (file, "lk_rt %f %f %f \n",
lk_rt.x, lk_rt.y, lk_rt.z);
fprintf (file, "up_rt %f %f %f \n",
up_rt.x, up_rt.y, up_rt.z);
fprintf (file, "hor_rt %f %f %f \n",
hor_rt.x, hor_rt.y, hor_rt.z);
fprintf (file, "lkc_rt %f %f %f \n",
lkc_rt.x, lkc_rt.y, lkc_rt.z);
fprintf (file, "upc_rt %f %f %f \n",
upc_rt.x, upc_rt.y, upc_rt.z);
fprintf (file, "horc_rt %f %f %f \n",
horc_rt.x, horc_rt.y, horc_rt.z);
fprintf (file, "lkP %f %f %f \n",
lkP.x , lkP.y, lkP.z);
fprintf (file, "upP %f %f %f \n",
upP.x, upP.y, upP.z);
fprintf (file, "horP %f %f %f \n",
horP.x, horP.y, horP.z);
fprintf (file, "meye %f %f %f \n",
meye.x , meye.y, meye.z);
fprintf (file, "MEM_POINT %f %f %f \n",
MEM_POINT.x, MEM_POINT.y, MEM_POINT.z);
fprintf (file, "pos_light0 %f %f %f \n",
pos_light0.x, pos_light0.y, pos_light0.z);
fprintf (file, "pos_light1 %f %f %f \n",
pos_light1.x, pos_light1.y, pos_light1.z);
fprintf (file, "z %lf teta %lf phi %lf teta2 %lf cam_angle %lf",
z, teta, phi, teta2, cam_angle);
fprintf (file, "viewport %d FLAG_TOP_VIEW %d FLAG_SELECTED_MIRROR %d FLAG_TOGGLE_MIRROR[0] %d",
viewport , FLAG_TOP_VIEW , FLAG_SELECTED_MIRROR , FLAG_TOGGLE_MIRROR[0]);
fprintf (file, "FLAG_TOGGLE_MIRROR[1] %d %d %d %d %d %d \n",
FLAG_TOGGLE_MIRROR[0] , FLAG_TOGGLE_MIRROR[1], FLAG_TOGGLE_MIRROR[2], FLAG_TOGGLE_MIRROR[3],
FLAG_TOGGLE_MIRROR[4] , FLAG_TOGGLE_MIRROR[5]);
fprintf (file, "FLAG_FRONT_VIEW %d FLAG_TOGGLE_MENU1 %d FLAG_TOGGLE_TEXTURE_MAP %d \n",
FLAG_FRONT_VIEW , FLAG_TOGGLE_MENU1 , FLAG_TOGGLE_TEXTURE_MAP);
fprintf (file, "FLAG_DROP_MENU %d TRANSLATE_TO_GRAVITY %d TRANSLATE_TO_MIDDLE %d \n",
FLAG_DROP_MENU , TRANSLATE_TO_GRAVITY , TRANSLATE_TO_MIDDLE);
fprintf (file, "Draw_relative_axe %d Draw_light_position %d spinning %d expand_carre1 %d\n",
Draw_relative_axe , Draw_light_position , spinning , expand_carre1);
fprintf (file, "expand_carre2 %d expand_carre3 %d APPLY_MOUSE_MOTION %d FLAG_ORTHO_PERSP %d \n",
expand_carre2 , expand_carre3 , APPLY_MOUSE_MOTION , FLAG_ORTHO_PERSP);
fprintf (file, "FLAG_FIX_MIRROR %d FLAG_HORIZ %d SHOW_LOCATION_DIRECTION_OF_LIGHTS %d \n",
FLAG_FIX_MIRROR , FLAG_HORIZ , SHOW_LOCATION_DIRECTION_OF_LIGHTS);
fprintf (file, "LIGHTS_FIX_WITH_CAMERA %d",
LIGHTS_FIX_WITH_CAMERA);
fprintf (file, "Center_Of_Rot_Of_Lights %f %f %f \n",
Center_Of_Rot_Of_Lights.x, Center_Of_Rot_Of_Lights.y, Center_Of_Rot_Of_Lights.z);
fprintf (file, "lightZeroPosition[.] %f %f %f %f \n",
lightZeroPosition[0], lightZeroPosition[1], lightZeroPosition[2], lightZeroPosition[3]);
fprintf (file, "lightOnePosition[.] %f %f %f %f \n",
lightOnePosition[0] , lightOnePosition[1], lightOnePosition[2] , lightOnePosition[3]);
fprintf (file, "lightZeroColor[.] %f %f %f %f \n",
lightZeroColor[0], lightZeroColor[1], lightZeroColor[2], lightZeroColor[3]);
fprintf (file, "lightOneColor[.] %f %f %f %f \n",
lightOneColor[0], lightOneColor[1], lightOneColor[2], lightOneColor[3]);
fprintf (file, "lightZeroColor_Car[.] %f %f %f %f \n",
lightZeroColor_Car[0],lightZeroColor_Car[1],lightZeroColor_Car[2],lightZeroColor_Car[3]);
fprintf (file, "lightOneColor_Car[.] %f %f %f %f \n",
lightOneColor_Car[0], lightOneColor_Car[1], lightOneColor_Car[2], lightOneColor_Car[3] );
fprintf (file, "aspect_ratio %lf \n", aspect_ratio);
fprintf (file, "FLAG_MOVE_GODS_EYE %d \n", FLAG_MOVE_GODS_EYE);
fprintf (file, "Geye %f %f %f \n", Geye.x, Geye.y, Geye.z);
fprintf (file, "Gup %f %f %f \n", Gup.x, Gup.y, Gup.z);
fprintf (file, "Ghor %f %f %f \n", Ghor.x, Ghor.y, Ghor.z);
fprintf (file, "Glk %f %f %f \n", Glk.x, Glk.y, Glk.z);
fprintf (file, "Gup_V %f %f %f \n", Gup_V.x, Gup_V.y, Gup_V.z);
fprintf (file, "Geye_V %f %f %f \n", Geye_V.x, Geye_V.y, Geye_V.z);
fprintf (file, "curquat_Geye[.] %lf %lf %lf %lf \n",
curquat_Geye[0], curquat_Geye[1], curquat_Geye[2], curquat_Geye[3]);
for (i=0;i<9;i++)
fprintf (file, "mz[i] %d \n", mz[i]);
fclose (file);
}
void
fog()
{
glEnable(GL_DEPTH_TEST);
GLfloat fogColor[4] = {0, 0,0 , 1.0};
glEnable (GL_FOG);
glFogi (GL_FOG_MODE, GL_EXP);
glFogf (GL_FOG_DENSITY, fogDensity);
glFogfv(GL_FOG_COLOR, fogColor);
// glHint (GL_FOG_HINT, GL_NICEST);
//glFogf (GL_FOG_START, 0);
//glFogf (GL_FOG_END, abs(zmin) + abs(zmax));
}
void
extrudeSolidFromPolygon(GLdouble data[][2], unsigned int dataSize,
GLdouble thickness, GLuint side, GLuint edge, GLuint whole)
{
static GLUtriangulatorObj *tobj = NULL;
GLdouble vertex[3], dx, dy, len;
int i;
int count = dataSize / (2 * sizeof(GLfloat));
if (tobj == NULL) {
tobj = gluNewTess(); /* create and initialize a GLU
polygon * * tesselation object */
// gluTessCallback(tobj, GLU_BEGIN, glBegin);
// gluTessCallback(tobj, GLU_VERTEX, glVertex2fv); // semi-tricky
gluTessCallback(tobj, GLU_END, glEnd);
}
glNewList(side, GL_COMPILE);
glShadeModel(GL_SMOOTH); /* smooth minimizes seeing
tessellation */
gluBeginPolygon(tobj);
for (i = 0; i < count; i++) {
vertex[0] = data[i][0];
vertex[1] = data[i][1];
vertex[2] = 0;
gluTessVertex(tobj, vertex, data[i]);
}
gluEndPolygon(tobj);
glEndList();
glNewList(edge, GL_COMPILE);
glShadeModel(GL_FLAT); /* flat shade keeps angular hands
from being * * "smoothed" */
glBegin(GL_QUAD_STRIP);
for (i = 0; i <= count; i++) {
/* mod function handles closing the edge */
glVertex3f(data[i % count][0], data[i % count][1], 0.0);
glVertex3f(data[i % count][0], data[i % count][1], thickness);
/* Calculate a unit normal by dividing by Euclidean
distance. We * could be lazy and use
glEnable(GL_NORMALIZE) so we could pass in * arbitrary
normals for a very slight performance hit. */
dx = data[(i + 1) % count][1] - data[i % count][1];
dy = data[i % count][0] - data[(i + 1) % count][0];
len = sqrt(dx * dx + dy * dy);
glNormal3f(dx / len, dy / len, 0.0);
}
glEnd();
glEndList();
glNewList(whole, GL_COMPILE);
glFrontFace(GL_CW);
glCallList(edge);
glNormal3f(0.0, 0.0, -1.0); /* constant normal for side */
glCallList(side);
glPushMatrix();
glTranslatef(0.0, 0.0, thickness);
glFrontFace(GL_CCW);
glNormal3f(0.0, 0.0, 1.0); /* opposite normal for other side
*/
glCallList(side);
glPopMatrix();
glEndList();
}
void
redraw2(void)
{
if (newModel)
recalcModelView();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glCallList(DINOSAUR);
// showMessage(2, 7.1, 4.1, "Habib.");
glutSwapBuffers();
}
void
myReshape(int w, int h)
{
glViewport(0, 0, w, h);
W = w;
H = h;
TOP_V_Y= H- TOP_H;
}
void
myReshape2(int w, int h)
{
glViewport(0, 0, w, h);
W2 = w;
H2 = h;
}
void
animate(void)
{
glutPostRedisplay();
}
void
vis(int visible)
{
if (visible == GLUT_VISIBLE) {
if (spinning)
glutIdleFunc(animate);
}
else {
if (spinning)
glutIdleFunc(NULL);
}
}
void initialize_a_mirror(int i)
{
extern void calc_corners_of_mirror(int i);
mz[0] = mz[1] = mz[2] = mz[3] = mz[4] = mz[5] = mz[6] = mz[7] = mz[8] = mz[9] = 0;
// m1[i] is the mirror link---> struct mirror
m1[i].cr.x= eye.x+2*lk_rt.x; //mirror.center.x (m1[i] is mirror) (cr is center)
m1[i].cr.y= eye.y+2*lk_rt.y;
m1[i].cr.z= eye.z+2*lk_rt.z;
m1[i].nl.x =0; //mirror.normal.dx (m1[i] is mirror) (nl is normal)
m1[i].nl.y =0;
m1[i].nl.z =1;
m1[i].up.x = 0; // mirror.up.x (m1[i] is mirror) (up is the vector up).
m1[i].up.y = 1;
m1[i].up.z = 0;
m1[i].side = vectoriel (m1[i].up,m1[i].nl);
m1[i].width = 1; // this is the width / 2
m1[i].height = 1;// this is the height / 2.
calc_corners_of_mirror(i);
}
//finitialize_some_var
void initialize_some_var()
{
int i;
sensors_V[0].x = -8.103f;
sensors_V[0].y = 0.0f;
sensors_V[0].z = 3.642f;
sensors_V[1].x = -7.978f;
sensors_V[1].y = 0.0f;
sensors_V[1].z = -1.915f;
sensors_V[2].x = -5.595f;
sensors_V[2].y = 0.0f;
sensors_V[2].z = -7.096f;
sensors_V[3].x = -1.749f;
sensors_V[3].y = 0.0f;
sensors_V[3].z = -9.728f;
sensors_V[4].x = 2.892f;
sensors_V[4].y = 0.0f;
sensors_V[4].z = -9.477f;
sensors_V[5].x = 8.535f;
sensors_V[5].y = 0.0f;
sensors_V[5].z = -1.037f;
sensors_V[6].x = 7.365f;
sensors_V[6].y = 0.0f;
sensors_V[6].z = -6.176f;
sensors_V[7].x = 8.159f;
sensors_V[7].y = 0.0f;
sensors_V[7].z = 4.227f;
// For rotating the car...
axisup[0] = 0;
axisup[1] = 1;
axisup[2] = 0;
// When recording the path of some cars, we
// need those variables.
for (i=0;i<10;i++)
RouteNum[i] = 0; // This says that none of the 10 cars is running nor loaded
// in the environment.
RecRouteNum =999; // The RecRouteNum is the Route Number that is being Recorde.
// If RecRouteNum == 999 => we are not recording any route...
for (i=0;i<10;i++){
IndexCarLocRec[i] = 0;
RECORD_CAR_MVMT = 0; // Flag Oh Stupid, you don't need to have it inside here!!
CarLocAllocated[i] = 100; // How many are allocated in *CarLocationRec[#]
}
for (i=0;i<10;i++)
if ((CarLocationRec[i] = (struct car_location*) malloc (CarLocAllocated[i]*sizeof(struct car_location))) == NULL)
printf ("Error in malloc CarLocationRec \n");
// render all mirror toggled on!
for (i =0; i<100;i++)
FLAG_TOGGLE_MIRROR[i] = 1;
// initialize the quaternions.
trackball(curquat, 0.0, 0.0, 0.0, 0.0);
trackball(curquatc, 0.0, 0.0, 0.0, 0.0);
trackball(curquat_mirror, 0.0, 0.0, 0.0, 0.0);
trackball(curquat_top_view, 0.0, 0.0, 0.0, 0.0);
trackball(curquat_light0, 0.0, 0.0, 0.0, 0.0);
trackball(curquat_light1, 0.0, 0.0, 0.0, 0.0);
trackball(curquat_Geye, 0.0, 0.0, 0.0, 0.0);
//trackball(curquat_top_view, 0.20877532719535, 0.85882181074556, 0.3624872845568, -0.29570412353706);
// fix vectors used for the mirror rotation.
vz.x = 0;
vz.y = 0;
vz.z = 1;
// fix vectors used for the mirror rotation.
vy.x = 0;
vy.y = 1;
vy.z = 0;
// fix vectors used for the mirror rotation.
vx.x = 1;
vx.y = 0;
vx.z = 0;
// puts the center of rot of lights at (0,0,0).
Center_Of_Rot_Of_Lights.x = 0;
Center_Of_Rot_Of_Lights.y = 0;
Center_Of_Rot_Of_Lights.z = 0;
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glGenTextures(4,texName);
for (i=0;i<4;i++) {
glBindTexture(GL_TEXTURE_2D, texName[i]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); //GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); //GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexImage2D(GL_TEXTURE_2D, // target
0, // level
GL_RGB, // internal format
TEX_WIDTH, TEX_HEIGHT, //
//im_width[0], im_height[0],
0, // border
GL_RGB, // format
GL_UNSIGNED_BYTE, // type
TEX_BUF[i][0][0]
//image
); // GLvoid *pixels
}
// glEnable(GL_TEXTURE_2D);
html // glteximage2d */
add_to_the_menus_a_mirror(0);
add_to_the_menus_a_mirror(1);
add_to_the_menus_a_mirror(2);
add_to_the_menus_a_mirror(3);
}
void init(void)
{
// glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, 1);
// Light 0
glEnable(GL_LIGHTING);
glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
glLightfv(GL_LIGHT0, GL_AMBIENT, ambi);
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor);
//glLightfv (GL_LIGHT0, GL_AMBIENT, ambi);
//glLightf (GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.5);
//glLightf (GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.5);
//glLighti (GL_LIGHT0, GL_SPOT_EXPONENT, 75);
//glLighti (GL_LIGHT0, GL_SPOT_CUTOFF, 100.0);
glEnable (GL_LIGHT0);
// Light 1
glLightfv(GL_LIGHT1, GL_POSITION, lightOnePosition);
glLightfv(GL_LIGHT1, GL_DIFFUSE, lightOneColor);
glLightfv (GL_LIGHT1, GL_AMBIENT, ambi);
glEnable (GL_LIGHT1);
// glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambi);
glLightfv(GL_LIGHT2, GL_POSITION, light2Position);
glLightfv(GL_LIGHT2, GL_DIFFUSE, lightOneColor);
glLightfv (GL_LIGHT2, GL_AMBIENT, ambi);
glEnable (GL_LIGHT2);
glLightfv(GL_LIGHT3, GL_POSITION, light3Position);
glLightfv(GL_LIGHT3, GL_DIFFUSE, lightOneColor);
glLightfv (GL_LIGHT3, GL_AMBIENT, ambi);
glEnable (GL_LIGHT3);
glLineWidth(2.0);
}
int
main(int argc, char **argv)
{
vrml_city_filename = argv[1];
vrml_vehicle_filename = argv[2];
int i,j,k;
//image = read_JPEG_file ("D:\\Arch98_Class\\Edtown15\\230409e.jpg", image, im_width, im_height);
//Allocating the TEX_BUF.
/* for (k=0;k<4;k++)
TEX_BUF[k] = (unsigned char *) calloc (TEX_HEIGHT*TEX_WIDTH*3, sizeof (unsigned char)); */
if (argc == 1) {
cout << "hello... " << endl;
vrml_city_filename = new char[170];
vrml_vehicle_filename = new char[170];
vrml_sensors_filename = new char[170];
//strcpy (vrml_city_filename,"D:\\VRML\\habibtest.wrl");
//strcpy (vrml_city_filename,"D:\\VRML\\HabibTestEdmond2.wrl");
//strcpy (vrml_city_filename,"D:\\VRML\\stuff\\jeep22.wrl");
//strcpy (vrml_city_filename, "D:\\Arch98_Class\\EDTOWN14\\zobroad.wrl");
//strcpy (vrml_city_filename, "D:\\Arch98_Class\\EDTOWN14\\Edtown14spaced.wrl");
//strcpy (vrml_city_filename, "D:\\Arch98_Class\\EDTOWN14\\Edtown14spacedSmall.wrl"); // WinUnix
//strcpy (vrml_city_filename, "D:\\C\\LilysCars\\RedCar04.wrl");
//strcpy (vrml_city_filename, "D:\\C\\vrml2_viewer\\Debug\\Edtown14spaced.wrl");
//strcpy (vrml_city_filename, "D:\\C\\vrml2_viewer\\roads.wrl");
//strcpy (vrml_city_filename, "D:\\C\\vrml2_viewer\\toto.wrl");
//strcpy (vrml_city_filename, "D:\\C\\Vrml2_Viewer\\Debug\\Jeep22.wrl");
strcpy (vrml_city_filename, "D:\\VRML\\Cars\\pickupS.wrl");
//strcpy (vrml_city_filename, "D:\\Arch98_Class\\VirtCity\\vc02.wrl");
//strcpy (vrml_city_filename, "D:\\Arch98_Class\\VirtCity\\VirtCityNew.wrl");
//strcpy (vrml_city_filename, "D:\\Arch98_Class\\VirtCity\\test01.wrl");
//strcpy (vrml_city_filename, "D:\\C\\vrml2_viewer\\Debug\\VirtCity\\VirtCity.wrl"); // WinUnix
strcpy (vrml_vehicle_filename, "D:\\C\\vrml2_viewer\\Debug\\VirtCity\\RedCar03.wrl"); // WinUnix
strcpy (vrml_sensors_filename, "D:\\C\\vrml2_viewer\\Debug\\VirtCity\\RedCar04.wrl"); // WinUnix
//strcpy (vrml_city_filename, "D:\\C\\Vrml2_Viewer\\Debug\\Jeep22.wrl");
}
cout << "argv[0]=" << argv[0] << endl ;
// cout << "argv[1]=" << argv[1] << endl ;
cout << "vrml_city_filename = " << vrml_city_filename << endl;
// Reads the Vrml File + Compiles the list 9.
// glClearColor (.3f,0.7f,0.8f,0.5f);
GLenum type;
flag_motion = rotating;
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH | GLUT_MULTISAMPLE); // | GLUT_STEREO);
win = glutCreateWindow("Mirror Demo");
glutDisplayFunc(redraw);
glutReshapeFunc(myReshape);
glutVisibilityFunc(vis);
glutMouseFunc(mouse);
glutMotionFunc(motion);
glutPassiveMotionFunc(passive_motion);
cout << "hihi... " << NaN << endl;
CNV = Read_Vrml_File(vrml_vehicle_filename);
CNSe = Read_Vrml_File(vrml_sensors_filename);
CNC = Read_Vrml_File(vrml_city_filename);
create_menus();
initialize_some_var();
glShadeModel(GL_SMOOTH);
//glCullFace (GL_FRONT_AND_BACK);
//glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glEnable(GL_POLYGON_SMOOTH);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_POINT_SMOOTH);
glHint(GL_LINE_SMOOTH_HINT, GL_DONT_CARE);
glMatrixMode(GL_PROJECTION);
NEAR2 = -10000;
FAR2 = 10000;
glMatrixMode(GL_MODELVIEW);
transX = 0;
transY = 0;
transZ = 0;
eyec.x = eye.x = 25; //-baseline;
eye.y = 70;
eyec.z = eye.z = 10;
eyec.y = 80;
CRot.x = CRot.y = CRot.z = 0; // Center of rotation of an object.
lkc_rt.x = lk_rt.x = lk.x = 0;
lkc_rt.y = lk_rt.y = lk.y = 0;
lkc_rt.z = lk_rt.z = lk.z = 1;
upc_rt.x = up_rt.x = up.x = 0;
upc_rt.y = up_rt.y = up.y = 1;
upc_rt.z = up_rt.z = up.z = 0;
horc_rt.x = hor_rt.x = hor.x=1;
horc_rt.y = hor_rt.y = hor.y=0;
horc_rt.z = hor_rt.z = hor.z=0;
glPushMatrix(); /* dummy push so we can pop on model
recalc */
init();
glutKeyboardFunc(Key);
glutIdleFunc (SpaceOrb); //WinUnix
glutSpecialFunc(SpecialKey);
glutMainLoop();
return 0; /* ANSI C requires main to return int. */
}