home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.hitl.washington.edu
/
ftp.hitl.washington.edu.tar
/
ftp.hitl.washington.edu
/
pub
/
people
/
habib
/
kodak
/
Draw_Vrml_new.cc~
< prev
next >
Wrap
Text File
|
2000-04-18
|
61KB
|
1,848 lines
/*===========================================================================*/
/* Includes. */
/*===========================================================================*/
// #include <windows.h> //WinUnix
#include <GL/gl.h>
#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
#include <math.h>
#include "trackball.h"
static unsigned int test[10];
struct point {float x,y,z;};
#include "f-gen.h"
#define PI 3.14159265
int Counter_Id=0;
// Flags
int ADJUST_TO_ZERO = 0; // Flattenes out the city to zero
float TransX, TransY, TransZ; // Global Transformation.
// #include <malloc.h>
#define DimX 400 // Change them in interface.h.
#define DimY 150
#define DimZ 400
double curquat_vrml[4];
double lastquat_vrml[4];
double m_vrml[4][4];
struct Virtual_Espace{
char FULL;
//struct point *N;
} espace[DimX][DimY][DimZ];
float VoxelX,VoxelY, VoxelZ; //It's the dimension of a voxel in real space.
struct espace_indice{
float Xmin, Xmax, Ymin, Ymax, Zmin, Zmax;
int Imin, Imax, Jmin, Jmax, Kmin, Kmax;
} EI;
typedef enum { p_Transform, p_children, p_Material, p_ImageTexture, p_IndexedFaceSet, p_Coordinate, p_point,
p_TextureCoordinate, p_coordIndex, p_TimeSensor, p_texCoordIndex, p_Appearance,p_texCoord,p_Shape,
p_nothing}
Type_AccTag;
Type_AccTag AccTag;
struct Type_Pipe { int pipe[1000];
int indice; } Acc; // Keeps track of which accolade has just been closed when going into the vrml structure.
#define SFNode struct
#define SFBool char
extern "C" unsigned char * read_JPEG_file (char *, char *, unsigned char *, int *, int *);
typedef enum { EmptyDracula,machi, Top_Scene ,n_rotation, n_Transform, n_Shape, n_AccO, n_AccF, n_translation, n_scale,
n_children, n_Appearance, n_Material, n_shininess, n_transparency, n_diffuseColor, n_specularColor,
n_geometry, n_point, n_coordIndex, f_solid, f_colorIndex, f_color, f_texCoordIndex,
f_TextureCoordinate, f_texCoord, f_Coordinate, f_texture, nothing, n_material,nappearance,f_coord,
n_USE, n_DEF, n_IndexedFaceSet, nccw, n_solid, n_TRUE, n_FALSE,n_CroO, n_CroF, n_appearance,n_ccw,
n_TimeSensor, n_normal, n_nonexist} Node_type;
Node_type node_type, previous_node_type;
FILE *file;
int nbr_vertex = 0;
// Everything in those defenition is conform to the VRML2 notation aside :
// 1 Hab_...
// 2 _ins which stands for instance
// 3 SFNode have been abolished.
double XmaxVrmlCity, YmaxVrmlCity, ZmaxVrmlCity;
double XminVrmlCity, YminVrmlCity, ZminVrmlCity;
typedef GLfloat SFFloat;
typedef int SFInt32 ;
typedef struct
{
SFFloat *pElements;
int NumElements;
} MFFloat;
typedef struct
{
SFInt32 *pElements;
int num_el;
} MFInt32;
#define SFVec3f struct point
typedef struct Hab_MFVec3f { SFVec3f *pt;
int num_el;
} MFVec3f;
typedef struct TypeRotation { float x;
float y;
float z;
float teta;
} Type_Rotation;
typedef struct Hab_SFColor { float r;
float g;
float b;
} SFColor;
typedef struct Hab_MFColor {SFColor *pt;
int col_el;
} MFColor;
typedef struct TypeMaterial {
/*exposedField*/ SFFloat ambientIntensity; //0.2 // #á[0,1]
/*exposedField*/ SFColor diffuseColor; //0.8 0.8 0.8 #á[0,1]
/*exposedField*/ SFColor emissiveColor; //0 0 0 #á[0,1]
/*exposedField*/ float shininess; //0.2 #á[0,1]
/*exposedField*/ SFColor specularColor; //0 0 0 #á[0,1]
/*exposedField*/ SFFloat transparency; //0 #á[0,1]
} Material;
typedef struct TypeTexture {
unsigned char *image;
int im_width[1];
int im_height[1];
unsigned int tex_name[10];
char tex_blk[40];
} Type_Texture;
typedef struct TypeAppearance { Material material;
//TextrueTransform textureTransform;
} Type_Appearance;
typedef struct Hab_Pixel {
float x,y;
} Pixel;
typedef struct TypeIndexedFaceSet {
/*exposedField*/ MFColor color;
/*eventIn*/ MFInt32 colorIndex;
/*exposedField*/ MFVec3f coord; //NULL
/*eventIn*/ MFInt32 coordIndex;
/*exposedField*/ Pixel *texCoord; //NULL
/*eventIn*/ MFInt32 texCoordIndex;
MFVec3f normal;
MFInt32 normalIndex;
/*field*/ SFBool ccw; //TRUE
/*field*/ SFBool solid; //TRUE
int num_el;
} Type_IndexedFaceSet;
typedef struct TypeGeometry {
Type_IndexedFaceSet IndexedFaceSet;
} Type_Geometry;
typedef struct TypeShape {
//Type_Transform *FatherTransform;
Type_Appearance Appearance;
Type_Texture Texture;
Type_Geometry Geometry;
int Acc;
int Cro;
int Id;
} Type_Shape;
Type_Shape *CNS;
typedef struct TypeTransform {
SFVec3f translation;
SFVec3f scale;
int FlagScale; // says if we have a scale or not.
Type_Rotation rotation;
struct TypeTransform *FatherTransform;
struct TypeTransform **ChildrenTransform;
int numChildTrans; // this is the total number of sons.
int indChildTrans; // this is the actual indice of sons.
Type_Shape **ChildrenShape;
int numChildShape; // this is the total number of sons.
int indChildShape; // this is the actual indice of sons.
int FlagChildren;
Type_Shape *Shape;
int ShapeLeave; // To say if This node has a Shape Leave or not.
Node_type node_type;
int Acc;
int Cro;
} Type_Transform;
Type_Transform *CN, *old_node, *CNV, *CNC, *CNSe, *CNVo[6][6],*CNSphere;
// CNC is for the city CNV is for the Vehicle. CN is Current Node.
// CNSe for the green Sensors.
struct point ScaleNormals;
struct USE_DEF_HASH_TAB
{
char blk_name[100];
char tex_blk_name[100];
MFVec3f coord;
Pixel *texCoord;
int index;
int texIndex;
} UseDef[5000],iz;
inline void wordd_to_node(char *wordd)
{
node_type = nothing;
if (strcmp (wordd ,"Transform") ==0) node_type = n_Transform ; else
if (strcmp (wordd , "Shape") ==0) node_type = n_Shape ; else
if (strcmp (wordd , "{")==0) node_type = n_AccO ; else
if (strcmp (wordd , "}")==0) node_type = n_AccF ; else
if (strcmp (wordd , "[")==0) node_type = n_CroO ; else
if (strcmp (wordd , "]")==0) node_type = n_CroF ; else
if (strcmp (wordd , "translation")==0) node_type = n_translation ; else
if (strcmp (wordd , "scale")==0) node_type = n_scale ; else
if (strcmp (wordd , "children")==0) node_type = n_children ; else
if (strcmp (wordd , "Appearance")==0) node_type = n_Appearance ; else
if (strcmp (wordd , "appearance")==0) node_type = n_appearance ; else
if (strcmp (wordd , "Material" )==0) node_type = n_Material ; else
if (strcmp (wordd , "material" )==0) node_type = n_material ; else
if (strcmp (wordd , "shininess" )==0) node_type = n_shininess ; else
if (strcmp (wordd , "transparency" )==0) node_type = n_transparency ; else
if (strcmp (wordd , "diffuseColor" )==0) node_type = n_diffuseColor ; else
if (strcmp (wordd , "specularColor" )==0) node_type = n_specularColor ; else
if (strcmp (wordd , "geometry" )==0) node_type = n_geometry ; else
if (strcmp (wordd , "point" ) ==0) node_type = n_point ; else
if (strcmp (wordd , "normal" ) ==0) node_type = n_normal ; else
if (strcmp (wordd , "coordIndex" )==0) node_type = n_coordIndex ; else
if (strcmp (wordd , "texCoordIndex" )==0) node_type = f_texCoordIndex ; else
if (strcmp (wordd , "solid" )==0) node_type = f_solid ; else
if (strcmp (wordd , "colorIndex" )==0) node_type = f_colorIndex ; else
if (strcmp (wordd , "color" )==0) node_type = f_color ; else
if (strcmp (wordd , "Coordinate" )==0) node_type = f_Coordinate ; else
if (strcmp (wordd , "coord" )==0) node_type = f_coord ; else
if (strcmp (wordd , "TimeSensor" )==0) node_type = n_TimeSensor ; else
if (strcmp (wordd , "texCoord" )==0) node_type = f_texCoord ; else
if (strcmp (wordd , "texture" )==0) node_type = f_texture ; else
if (strcmp (wordd , "rotation" )==0) node_type =n_rotation ; else
if (strcmp (wordd , "TextureCoordinate" )==0) node_type = f_TextureCoordinate; else
if (strcmp (wordd , "USE" )==0) node_type = n_USE; else
if (strcmp (wordd , "DEF" )==0) node_type = n_DEF; else
if (strcmp (wordd , "USE" )==0) node_type = n_USE; else
if (strcmp (wordd , "IndexedFaceSet" )==0) node_type = n_IndexedFaceSet; else
if (strcmp (wordd , "ccw" )==0) node_type = n_ccw; else
if (strcmp (wordd , "solid" )==0) node_type = n_solid; else
if (strcmp (wordd , "TRUE" )==0) node_type = n_TRUE; else
if (strcmp (wordd , "FALSE" )==0) node_type = n_FALSE;
}
// reads next float from wrl Ascii file
float LisFlWrl()
{
float f;
fscanf (file,"%f",&f);
return f;
}
// reads next int from wrl Ascii file
int LisIntWrl()
{
int f;
fscanf (file,"%d",&f);
return f;
}
void initialize_Transform_node()
{
CN->node_type = n_Transform;
//CN->node_type = n_Transform;
CN->translation.x = 0;
CN->translation.y = 0;
CN->translation.z = 0;
CN->rotation.x = 0;
CN->rotation.y = 0;
CN->rotation.z = 1;
CN->rotation.teta = 0;
CN->numChildTrans = 0;
CN->indChildTrans = 0;
CN->numChildShape = 0;
CN->indChildShape = 0;
CN->ShapeLeave = 0;
CN->Acc = 0;
CN->Cro = 0;
CN->FlagChildren = 0;
CN->FlagScale = 0;
}
static counter3 = 0;
inline void Create_Child_Transform_Node()
{
//cout << "CN->numChildTrans = " << CN->numChildTrans << endl;
// construct Son
CN->numChildTrans++;
int numChildTrans = CN->numChildTrans;
counter3++;
// If this is the first son do a malloc for the Node ** CN->Son else do a realloc.
if (CN->numChildTrans == 1){
if ( (CN->ChildrenTransform = (Type_Transform**)
malloc (sizeof (Type_Transform*)) ) ==NULL)
cout << "malloc error 1 " << endl;
} else
if ( (CN->ChildrenTransform = (Type_Transform**) realloc (CN->ChildrenTransform,numChildTrans*sizeof (Type_Transform*)) ) ==NULL)
cout << "realloc error 11 " << endl;
// allocate the Son itself
if ( (CN->ChildrenTransform[CN->numChildTrans-1] = (Type_Transform*) malloc (sizeof (Type_Transform )) ) ==NULL)
cout << "malloc error 2 " << endl;
// Set current Type_Transform to son.
old_node = CN;
CN = CN->ChildrenTransform[CN->numChildTrans-1];
CN->FatherTransform = new Type_Transform;
CN->FatherTransform = old_node;
CN->numChildTrans = 0;
CN->indChildTrans = 0;
CN->numChildShape = 0;
CN->indChildShape = 0;
}
inline
void Create_Child_Shape_Node()
{
// construct Son
CN->numChildShape++;
int numChildShape = CN->numChildShape;
// If this is the first son do a malloc for the Node ** CN->Son else do a realloc.
if (CN->numChildShape == 1){
if ( (CN->ChildrenShape = (Type_Shape**) malloc (sizeof (Type_Shape*)) ) ==NULL)
cout << "malloc error 1df " << endl;
} else
if ( (CN->ChildrenShape = (Type_Shape**) realloc (CN->ChildrenShape,numChildShape*sizeof (Type_Shape*)) ) ==NULL)
cout << "realloc error 1341 " << endl;
// allocate the Son itself
if ( (CN->ChildrenShape[CN->numChildShape-1] = (Type_Shape*) malloc (sizeof (Type_Shape )) ) ==NULL)
cout << "malloc error 2443 " << endl;
// Put CNS
CNS = CN->ChildrenShape[CN->numChildShape-1];
}
void
Create_One_Shape_Node()
{
// construct Son
CN->ShapeLeave =1;
if ( (CN->Shape = (Type_Shape*) malloc (sizeof (Type_Shape )) ) ==NULL)
cout << "malloc error 2443 " << endl;
CNS = CN->Shape;
}
void
InitializeChildrenShape()
{
CNS->Acc = 0;
CNS->Cro = 0;
CNS->Texture.tex_name[0] = 99999;
CNS->Appearance.material.transparency = 0;
//cout << "Initializing Counter_Id Number " << Counter_Id <<endl;
CNS->Id = Counter_Id;
Counter_Id++;
CNS->Geometry.IndexedFaceSet.color.col_el = 0;
CNS->Geometry.IndexedFaceSet.colorIndex.num_el = 0;
CNS->Geometry.IndexedFaceSet.coord.num_el=0; // to verify that each Geom has a coord field.
CNS->Geometry.IndexedFaceSet.coordIndex.num_el=0;
CNS->Geometry.IndexedFaceSet.texCoordIndex.num_el=0;
CNS->Geometry.IndexedFaceSet.num_el = 0;
}
void Saffir_the_ys()
{
MFVec3f &pt = CNS->Geometry.IndexedFaceSet.coord; //by reference
for (int i = 0 ; i<pt.num_el; i++)
pt.pt[i].y = 0;
}
// Adjusts the buildings to the zero level.
void adjust_to_zero()
{
MFVec3f &pt = CNS->Geometry.IndexedFaceSet.coord; //by reference
float lowesty = 999999;
for (int i = 0 ; i<pt.num_el; i++)
if (pt.pt[i].y < lowesty) lowesty = pt.pt[i].y;
for (i = 0 ; i<pt.num_el; i++)
pt.pt[i].y = pt.pt[i].y - lowesty;
}
void read_all_points_into_this_node()
{
char wordd[90];
fscanf (file,"%s", &wordd); // reads the [
if (strcmp (wordd,"[") !=0) {
cout << "mistakdke! a [ expected in here!!" << endl;
exit (0);
}
MFVec3f &pt = CNS->Geometry.IndexedFaceSet.coord; // by reference
pt.num_el = 1;
// malloc for the first element read
if ( (pt.pt = (SFVec3f *) malloc (pt.num_el * sizeof ( SFVec3f)) ) ==NULL)
cout << "malloc error 1236187 " << endl;
fscanf (file,"%f %f %f",&pt.pt[pt.num_el-1].x,
&pt.pt[pt.num_el-1].y,
&pt.pt[pt.num_el-1].z);
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid;
else goto end;
// realloc for the rest of the elements
eid:
// look for , ]
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,"]") ==0) goto end;
pt.num_el++;
if ( (pt.pt =
(SFVec3f *) realloc (pt.pt, pt.num_el * sizeof ( SFVec3f)) ) ==NULL)
cout << "realloc error 1234187 " << endl;
pt.pt[pt.num_el-1].x = atof(wordd);
fscanf (file,"%f %f ",
&pt.pt[pt.num_el-1].y,
&pt.pt[pt.num_el-1].z);
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid;
end:
//cout << "I read" << pt.num_el << " points!!" << endl;
return;
}
void read_all_normal_vectors_into_this_node()
{
char wordd[90];
fscanf (file,"%s", &wordd); // reads the [
if (strcmp (wordd,"[") !=0) {
cout << "mistake! a [ expected in here!!" << endl;
exit (0);
}
MFVec3f &pt = CNS->Geometry.IndexedFaceSet.normal; // by reference
pt.num_el = 1;
// malloc for the first element read
if ( (pt.pt = (SFVec3f *) malloc (pt.num_el * sizeof ( SFVec3f)) ) ==NULL)
cout << "malloc error 1236187 " << endl;
fscanf (file,"%f %f %f",&pt.pt[pt.num_el-1].x,
&pt.pt[pt.num_el-1].y,
&pt.pt[pt.num_el-1].z);
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid12;
else goto end12;
// realloc for the rest of the elements
eid12:
// look for , ]
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,"]") ==0) goto end12;
pt.num_el++;
if ( (pt.pt =
(SFVec3f *) realloc (pt.pt, pt.num_el * sizeof ( SFVec3f)) ) ==NULL)
cout << "realloc error 1234187 " << endl;
pt.pt[pt.num_el-1].x = atof(wordd);
fscanf (file,"%f %f ",
&pt.pt[pt.num_el-1].y,
&pt.pt[pt.num_el-1].z);
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid12;
end12:
//cout << "I read" << pt.num_el << " points!!" << endl;
return;
}
void read_all_texture_points_into_this_node()
{
char wordd[90];
fscanf (file,"%s", &wordd); // reads the [
if (strcmp (wordd,"[") !=0) {
cout << "mistake!! a [ expected in here!!" << endl;
exit (0);
}
Type_IndexedFaceSet &pt = CNS->Geometry.IndexedFaceSet; // by reference
// malloc for the first element read
if ( (pt.texCoord = (Pixel *) malloc (sizeof ( Pixel)) ) ==NULL)
cout << "malloc error 1236187 " << endl;
pt.num_el = 1;
fscanf (file,"%f %f ",&pt.texCoord[pt.num_el-1].x,
&pt.texCoord[pt.num_el-1].y );
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid11;
else goto end11;
// realloc for the rest of the elements
eid11:
// look for , ]
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,"]") ==0) goto end11;
pt.num_el++;
if ( (pt.texCoord =
(Pixel *) realloc (pt.texCoord, pt.num_el * sizeof ( Pixel)) ) ==NULL)
cout << "realloc error 1234187 " << endl;
pt.texCoord[pt.num_el-1].x = atof(wordd);
fscanf (file,"%f ",
&pt.texCoord[pt.num_el-1].y );
fscanf (file,"%s", &wordd);
if (wordd[0] == '#') fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid11;
end11:
//cout << "I read" << pt.num_el << " points!!" << endl;
return;
}
void read_all_texCoordIndex_into_CN()
{
char wordd[90];
MFInt32 &pt = CNS->Geometry.IndexedFaceSet.texCoordIndex; // by reference
fscanf (file,"%s", &wordd); // reads the [
if (strcmp (wordd,"[") !=0) {
cout << "mistake!!! a [ expected in here!!" << endl;
exit (0);
}
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,"]") ==0) {
pt.num_el = 0;
goto end2tex;
}
pt.num_el = 1;
// malloc the first el.
if ( (pt.pElements = (SFInt32 *) malloc (pt.num_el * sizeof ( SFInt32)) ) ==NULL)
cout << "malloc error 1964187tex " << endl;
pt.pElements[pt.num_el-1] = atoi(wordd);
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid2tex;
else goto end2tex;
// realloc the rest el.
eid2tex:
// look for , ]
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,"]") ==0) goto end2tex;
pt.num_el++;
if ( (pt.pElements =
(SFInt32 *) realloc (pt.pElements, pt.num_el * sizeof ( SFInt32)) ) ==NULL)
cout << "realloc error 1444187 " << endl;
pt.pElements[pt.num_el-1] = atoi(wordd);
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid2tex;
end2tex:
//cout << "texture pt.num_el=" << pt.num_el << endl;
return;
}
void read_all_coordIndex_into_CN()
{
char wordd[90];
MFInt32 &pt = CNS->Geometry.IndexedFaceSet.coordIndex; // by reference
fscanf (file,"%s", &wordd); // reads the [
if (strcmp (wordd,"[") !=0) {
cout << "mistake!!!! a [ expected in here!!" << endl;
exit (0);
}
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,"]") ==0) {
pt.num_el = 0;
goto end2;
}
pt.num_el = 1;
// malloc the first el.
if ( (pt.pElements = (SFInt32 *) malloc (pt.num_el * sizeof ( SFInt32)) ) ==NULL)
cout << "malloc error 1964187 " << endl;
pt.pElements[pt.num_el-1] = atoi(wordd);
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid2;
else goto end2;
// realloc the rest el.
eid2:
// look for , ]
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,"]") ==0) goto end2;
pt.num_el++;
if ( (pt.pElements =
(SFInt32 *) realloc (pt.pElements, pt.num_el * sizeof ( SFInt32)) ) ==NULL)
cout << "realloc error 1444187 " << endl;
pt.pElements[pt.num_el-1] = atoi(wordd);
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid2;
end2:
if (pt.num_el == 1) {
cout <<endl;
}
//cout << "pt.num_el=" << pt.num_el << endl;
// cout << "I read" << pt.num_el << " Indexpoints!!" << endl;
return;
}
void read_all_colorIndex_into_CN()
{
char wordd[90];
fscanf (file,"%s", &wordd); // reads the [
if (strcmp (wordd,"[") !=0) {
cout << "mistakeeee! a [ expected in here!!" << endl;
exit (0);
}
MFInt32 &pt = CNS->Geometry.IndexedFaceSet.colorIndex; // by reference
pt.num_el = 1;
// malloc the first el.
if ( (pt.pElements = (SFInt32 *) malloc (pt.num_el * sizeof ( SFInt32)) ) ==NULL)
cout << "malloc error 1764187 " << endl;
fscanf (file,"%d" , &pt.pElements[pt.num_el-1]);
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid3;
else goto end3;
// realloc the rest el.
eid3:
// look for , ]
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,"]") ==0) goto end3;
pt.num_el++;
if ( (pt.pElements =
(SFInt32 *) realloc (pt.pElements, pt.num_el * sizeof ( SFInt32)) ) ==NULL)
cout << "realloc error 14443287 " << endl;
pt.pElements[pt.num_el-1] = atoi(wordd);
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid3;
end3:
//cout << "I read" << pt.num_el << " ColorIndexpoints!!" << endl;
return;
}
void read_color_values()
{
char wordd[90];
MFColor &pt = CNS->Geometry.IndexedFaceSet.color; // by reference
pt.col_el = 1;
// malloc the first el.
if ( (pt.pt = (SFColor *) malloc( sizeof (SFColor)) ) == NULL)
cout << " malloc error 1221122" << endl;
fscanf (file, "%f %f %f", &pt.pt[0].r,
&pt.pt[0].g,
&pt.pt[0].b);
fscanf (file,"%s", &wordd);
if (strcmp(wordd, ",")==0) goto eid4;
else goto end4;
eid4:
// look for , ]
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,"]") ==0) goto end4;
pt.col_el++;
if ( (pt.pt = (SFColor *) realloc (pt.pt, pt.col_el * sizeof(SFColor)) ) == NULL)
cout << "realloc error 199834992" << endl;
pt.pt[pt.col_el-1].r = atof(wordd);
fscanf (file, "%f %f ",
&pt.pt[pt.col_el-1].g,
&pt.pt[pt.col_el-1].b);
fscanf (file,"%s", &wordd);
if (strcmp (wordd ,",") ==0) goto eid4;
end4:
//cout << "I read" << pt.col_el << " Color_ppoints!!" << endl;
return;
}
int Pass_To_Next_Trans()
{
recom:
//cout << "numChild " << CN->numChildTrans << "indChild "<<CN->indChildTrans << endl;
//cout << "Node_type in Transform" << CN->node_type << endl;
if (CN->numChildTrans > CN->indChildTrans){
CN->indChildTrans++;
CN = CN->ChildrenTransform[CN->indChildTrans-1];
if (ADJUST_TO_ZERO)
glTranslatef (CN->translation.x, 0, CN->translation.z);
else {
glTranslatef (CN->translation.x, CN->translation.y, CN->translation.z);
glRotatef (CN->rotation.teta*180.0/PI, CN->rotation.x, CN->rotation.y, CN->rotation.z);
if (CN->FlagScale){
glScalef (CN->scale.x, CN->scale.y, CN->scale.z);
ScaleNormals.x = CN->scale.x * ScaleNormals.x;
ScaleNormals.y = CN->scale.y * ScaleNormals.y;
ScaleNormals.z = CN->scale.z * ScaleNormals.z;
}
// I didn't do the above Translatef / Rotatef in order to calculate
// correctly the ?maxVrmlCity and do the espace calculation
// correctly as well.
/* TransX = TransX + CN->translation.x;
TransY = TransY + CN->translation.y;
TransZ = TransZ + CN->translation.z;
lastquat_vrml[3] = cos(CN->rotation.teta/2.0);
lastquat_vrml[0] = CN->rotation.x*sin(CN->rotation.teta/2.0);
lastquat_vrml[1] = CN->rotation.y*sin(CN->rotation.teta/2.0);
lastquat_vrml[2] = CN->rotation.z*sin(CN->rotation.teta/2.0);
add_quats(lastquat_vrml, curquat_vrml, curquat_vrml);
build_rotmatrix(m_vrml, curquat_vrml); */
}
return 1;
}else { // if going up the tree.
CN->indChildTrans = 0; // initializing for another evantual pass
if (ADJUST_TO_ZERO)
glTranslatef (-CN->translation.x,0 , -CN->translation.z);
else{
if (CN->FlagScale){
glScalef (1/CN->scale.x, 1/CN->scale.y, 1/CN->scale.z);
ScaleNormals.x = ScaleNormals.x / CN->scale.x ;
ScaleNormals.y = ScaleNormals.y / CN->scale.y ;
ScaleNormals.z = ScaleNormals.z / CN->scale.z ;
}
glRotatef (-CN->rotation.teta*180.0/PI, CN->rotation.x, CN->rotation.y, CN->rotation.z);
glTranslatef (-CN->translation.x, -CN->translation.y, -CN->translation.z);
/*
lastquat_vrml[3] = cos(CN->rotation.teta/2.0);
lastquat_vrml[0] = -CN->rotation.x*sin(CN->rotation.teta/2.0);
lastquat_vrml[1] = -CN->rotation.y*sin(CN->rotation.teta/2.0);
lastquat_vrml[2] = -CN->rotation.z*sin(CN->rotation.teta/2.0);
add_quats(lastquat_vrml, curquat_vrml, curquat_vrml);
build_rotmatrix(m_vrml, curquat_vrml);
TransX = TransX - CN->translation.x;
TransY = TransY - CN->translation.y;
TransZ = TransZ - CN->translation.z; */
}
CN = CN->FatherTransform;
if ((CN->node_type == Top_Scene)&&(CN->indChildTrans==CN->numChildTrans)){
CN->indChildTrans = 0;
//cout << "Node_type in returning 0" << CN->node_type << endl;
//cout << " I am returning 0 to the calling function " << endl;
return 0;
}
}
goto recom;
}
void
Fill_Virtual_Espace_With_Voxels(){
// The idea is to calculate the intersection of all the triangles
// with the voxels in the 3D space, and put the normal value in the
// corresponding voxel.
//Geometry
MFInt32 *ind = &CNS->Geometry.IndexedFaceSet.coordIndex;
MFInt32 *indtex = &CNS->Geometry.IndexedFaceSet.texCoordIndex;
MFVec3f *pt = &CNS->Geometry.IndexedFaceSet.coord;
MFColor &col = CNS->Geometry.IndexedFaceSet.color;
MFInt32 &col_ind= CNS->Geometry.IndexedFaceSet.colorIndex;
SFInt32 j,j0,j1,j2, t, t0, t1, t2,k,ii;
int c=0;
for (int i = 0;i<ind->num_el; i++) {
// count the number of vertex.
int num_vertx = 0;
while (ind->pElements[i+num_vertx]!= -1) {
num_vertx++; // q now is the number of vertices.
}
// Calculate the normal to the face
j0=ind->pElements[i ];
j1=ind->pElements[i+1];
j2=ind->pElements[i+2];
SFVec3f norm, vect0, vect1, vect2, vect3, ScanPt1, Pas, FPt;
vect1 = sous_vect_from_vect (pt->pt[j1], pt->pt[j0]);
vect2 = sous_vect_from_vect (pt->pt[j1], pt->pt[j2]);
norm = vectoriel (vect1 , vect2);
unitaire (norm); // makes it 1 => norm.x norm.y norm.z
// glNormal3f(norm.x, norm.y, norm.z);
// if 3 vertex
if (num_vertx==3) {
float pas , pas1, pas2; // vect subdivision
int pasi1, pasi2;
pas = VoxelX; // dimension of one voxel.
if (pas > VoxelY) pas = VoxelY;
if (pas > VoxelZ) pas = VoxelZ;
pas = pas /3.0;
pasi2 = longueurv(vect2) / pas;
vect2 = div_vect_par_nbr (vect2, pasi2);
// remplit espace (voxel) en scannant chaque triangle.
for (int zik=0;zik<pasi2;zik++){
struct point pt0, pt1, pt2;
pt0.x = pt->pt[j0].x + TransX;
pt0.y = pt->pt[j0].y + TransY;
pt0.z = pt->pt[j0].z + TransZ;
pt1.x = pt->pt[j1].x + TransX;
pt1.y = pt->pt[j1].y + TransY;
pt1.z = pt->pt[j1].z + TransZ;
pt2.x = pt->pt[j2].x + TransX;
pt2.y = pt->pt[j2].y + TransY;
pt2.z = pt->pt[j2].z + TransZ;
ScanPt1 = add_vect_to_pt (pt2, mul_vect_par_nbr(vect2,zik));
vect0 = sous_vect_from_vect(ScanPt1,pt0);
pasi1 = longueurv (vect0) / pas;
Pas = div_vect_par_nbr (vect0 ,pasi1);
for (int ayr=0;ayr<pasi1;ayr++){
FPt = add_vect_to_pt(mul_vect_par_nbr(Pas,ayr), pt0);
ii = (FPt.x - XminVrmlCity) * DimX / (XmaxVrmlCity - XminVrmlCity);
j = (FPt.y - YminVrmlCity) * DimY / (YmaxVrmlCity - YminVrmlCity);
k = (FPt.z - ZminVrmlCity) * DimZ / (ZmaxVrmlCity - ZminVrmlCity);
if (espace[ii][j][k].FULL !=1){
espace[ii][j][k].FULL = 1;
/*if ( (espace[ii][j][k].N = (struct point*) malloc (sizeof (struct point)) ) ==NULL)
cout << "malloc error espace " << endl;
espace[ii][j][k].N[0].x = norm.x;
espace[ii][j][k].N[0].y = norm.y;
espace[ii][j][k].N[0].z = norm.z; */
}
}
}
i=i+3;
} // if (num_vertx==3
if (num_vertx==4) {
for (int marra = 0; marra<num_vertx; marra++) {
j=ind->pElements[i];
glVertex3f (pt->pt[j].x,
pt->pt[j].y,
pt->pt[j].z);
i++;
}
glEnd();
} // if (num_vertx>4
if (num_vertx>4) {
glBegin (GL_POLYGON);
for (int marra = 0; marra<num_vertx; marra++) {
j=ind->pElements[i];
glVertex3f (pt->pt[j].x,
pt->pt[j].y,
pt->pt[j].z);
i++;
}
} // if (num_vertx>4
// i++ to skip the -1 and position on the next valid input. ( no not necessary since i++ in for...)
c++;
} // for (int i = 0; i<ind->num_el; i++)
}
//Places point in the espace, for collision detection, This function works even if the
// espace is empty (no pts yet).
inline
void
Virtual_Espace() {
TransX= TransY= TransZ=0; // Global Transformation.
VoxelX = (XmaxVrmlCity - XminVrmlCity)/DimX;
VoxelY = (YmaxVrmlCity - YminVrmlCity)/DimY;
VoxelZ = (ZmaxVrmlCity - ZminVrmlCity)/DimZ;
cout << "VoxelX = " << VoxelX << " - VoxelY = " << VoxelY << " - VoxelZ = " << VoxelZ << endl;
int i,j,k,toto1,toto2;
toto1 = toto2 = 0;
//Initialize the freeken space.
for ( i= 0; i<DimX; i++)
for ( j=0; j<DimY; j++)
for ( k=0; k<DimZ; k++)
espace[i][j][k].FULL = 0;
/* Calculate the intersection with the surfaces with the city.
while (CN->node_type != Top_Scene)
CN = CN->FatherTransform;
while (Pass_To_Next_Trans()){
if (CN->ShapeLeave) {
CNS = CN->Shape;
Fill_Virtual_Espace_With_Voxels();
}
else for (CN->indChildShape=0; CN->indChildShape<CN->numChildShape; CN->indChildShape++) {
CNS = CN->ChildrenShape[CN->indChildShape];
Fill_Virtual_Espace_With_Voxels();
}
}// while
// writing espace to file.
FILE *file_espace;
if ((file_espace = fopen ("espace","wb")) == NULL)
printf ("\n pas de chance l'ami ton fichier est corrompu \n");
for (i=0;i<DimX;i++)
for (j=0;j<DimY;j++)
for (k=0;k<DimZ;k++){
fwrite (&espace[i][j][k].FULL, sizeof(char),1,file_espace);
//if (espace[i][j][k].FULL==1){
// toto1++;
// fwrite (&espace[i][j][k].N[0].x, sizeof(float), 1, file_espace);
// fwrite (&espace[i][j][k].N[0].y, sizeof(float), 1, file_espace);
// fwrite (&espace[i][j][k].N[0].z, sizeof(float), 1, file_espace);
//}
} */
// reading espace to file.
FILE *file_espace;
if ((file_espace = fopen ("espace","rb")) == NULL)
printf ("\n pas de chance l'ami ton fichier est corrompu 185739945\n");
for (i=0;i<DimX;i++)
for (j=0;j<DimY;j++)
for (k=0;k<DimZ;k++){
fread (&espace[i][j][k].FULL, sizeof(char),1,file_espace);
//if (espace[i][j][k].FULL==1){
// toto2++;
// if ( (espace[i][j][k].N = (struct point*) malloc (sizeof (struct point)) ) ==NULL)
// cout << "malloc error espaceeee " << endl;
// fread (&espace[i][j][k].N[0].x, sizeof(float), 1, file_espace);
// fread (&espace[i][j][k].N[0].y, sizeof(float), 1, file_espace);
// fread (&espace[i][j][k].N[0].z, sizeof(float), 1, file_espace);
//}
}
// close the file, flush the buffer.
fclose (file_espace);
// Fill the empty bottom...
for ( i= 0; i<DimX; i++)
for ( k=0; k<DimZ; k++)
for ( j=0; j<DimY; j++)
if (espace[i][j][k].FULL == 1){
for (int jj = 0; jj<=j+3; jj++){//The j+3 is due to the fact that I want the earth to be located 3 voxels above the real earth.
espace[i][jj][k].FULL = j-jj+1+3; //The +3 is due to the fact that I want the earth to be located 3 voxels above the real earth.
//espace[i][jj][k].N = espace[i][j][k].N;
}
j=DimY;
}
extern float HauteurEye;
HauteurEye = 2*VoxelY;
cout << "HauteurEye = " << HauteurEye << endl;
}
inline
void
Draw_Shape_Node(int listnum){
extern double TOP, BOTTOM, LEFT, RIGHT;
GLfloat v[4],v1[4];
v[0] = CNS->Appearance.material.diffuseColor.r;
v[1] = CNS->Appearance.material.diffuseColor.g;
v[2] = CNS->Appearance.material.diffuseColor.b;
v[3] = CNS->Appearance.material.transparency;
//cout << v[0] << " vs " << v[1] << endl;
//cout << v[2] << " vs " << v[3] << endl;
v1[0] = CNS->Appearance.material.specularColor.r;
v1[1] = CNS->Appearance.material.specularColor.g;
v1[2] = CNS->Appearance.material.specularColor.b;
v1[3] = CNS->Appearance.material.transparency;
//cout << v[0] << " " << v[1] << " " << v[2] << " " << v[3] << endl;
//glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE);
//glMateriali (GL_FRONT, GL_SHININESS,CNS->Appearance.material.shininess);
//glColorMaterial (GL_FRONT, GL_SPECULAR);
if (CNS->Geometry.IndexedFaceSet.color.col_el == 0)
glDisable (GL_COLOR_MATERIAL);
else
glEnable (GL_COLOR_MATERIAL);
glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE,v);
glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR,v1);
//glMaterialfv (GL_BACK , GL_DIFFUSE,v1);
//Geometry
MFInt32 *ind = &CNS->Geometry.IndexedFaceSet.coordIndex;
MFInt32 *indtex = &CNS->Geometry.IndexedFaceSet.texCoordIndex;
MFVec3f *pt = &CNS->Geometry.IndexedFaceSet.coord;
MFColor &col = CNS->Geometry.IndexedFaceSet.color;
MFInt32 &col_ind= CNS->Geometry.IndexedFaceSet.colorIndex;
SFInt32 j,j0,j1,j2, t, t0, t1, t2;
int c=0;
//cout << "ind->num_el " << ind->num_el << " Of Counter_Id " << CNS->Id << endl;
for (int i = 0;i<ind->num_el; i++) {
// count the number of vertex.
int num_vertx = 0;
while (ind->pElements[i+num_vertx]!= -1) {
//cout << "ind->pElements[" << i+num_vertx << "]="<< ind->pElements[i+num_vertx] << endl;
num_vertx++; // q now is the number of vertices.
}
// Sets the normal for light calculation (see journals Dec 9th 1998).
j0=ind->pElements[i ];
//cout << "j0=" << j0;
j1=ind->pElements[i+1];
//cout << "j0=" << j1;
j2=ind->pElements[i+2];
//cout << "j0=" << j2;
SFVec3f norm, vect1, vect2;
vect1 = sous_vect_from_vect (pt->pt[j1], pt->pt[j0]);
vect2 = sous_vect_from_vect (pt->pt[j1], pt->pt[j2]);
norm = vectoriel (vect1 , vect2);
//if (norm.y == 0) norm.y = 0.01; // For collision detection.
unitaire (norm); // makes it normal.
// I mult with ScaleNormals to correct for the light calculations.
glNormal3f( ScaleNormals.x * norm.x, ScaleNormals.y * norm.y, ScaleNormals.z * norm.z);
// Binds the texture if one exists
if (CNS->Texture.tex_name[0] !=99999) {
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, CNS->Texture.tex_name[0]);
}else
glDisable(GL_TEXTURE_2D);
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
// if 3 vertex
if (num_vertx==3) {
glPointSize (3);
glBegin (GL_TRIANGLES);
if (CNS->Geometry.IndexedFaceSet.solid == GL_FALSE) {
//glPolygonMode(GL_FRONT,GL_LINE);
//glFrontFace(GL_CCW);
glCullFace (GL_FRONT);// The culling must be within the glBegin
glEnable(GL_CULL_FACE);// if we want a triangle rendered when outside
} // of window boundary.
for (int marra = 0; marra<num_vertx; marra++) {
struct point mempt;
j=ind->pElements[i];
mempt.x = pt->pt[j].x;
mempt.y = pt->pt[j].y;
mempt.z = pt->pt[j].z;
//cout << "mempt.xyz = " << mempt.x << " " << mempt.y << " " <<mempt.z << endl;
// pt->pt[j] = mult_matrix_vector (m_vrml, pt->pt[j]); // Rotate.
//pt->pt[j].x = pt->pt[j].x + TransX; // I did this instead of Translatef
//pt->pt[j].y = pt->pt[j].y + TransY; // In order to calculate ?maxVrmlCity
//pt->pt[j].z = pt->pt[j].z + TransZ; // correctly and do the espace thing.
if (col_ind.num_el > c)
glColor3f (col.pt[col_ind.pElements[c]].r,
col.pt[col_ind.pElements[c]].g,
col.pt[col_ind.pElements[c]].b);
//if there is a texture, and if the indexed 3Dpoint has a correspondant 2D texture pt.
if ((CNS->Texture.tex_name[0] !=99999) && (i<indtex->num_el) ) {
//glBindTexture(GL_TEXTURE_2D, CNB->Geometry_ins.texture.tex_name[0]);
t=indtex->pElements[i];
glTexCoord2f(CNS->Geometry.IndexedFaceSet.texCoord[t].x , CNS->Geometry.IndexedFaceSet.texCoord[t].y);
}
glVertex3f (pt->pt[j].x,
pt->pt[j].y,
pt->pt[j].z);
nbr_vertex++;
if (listnum == 9) if (TOP < pt->pt[j].y) TOP = pt->pt[j].y;
if (listnum == 9) if (BOTTOM > pt->pt[j].y) BOTTOM = pt->pt[j].y;
if (listnum == 9) if (RIGHT < pt->pt[j].x) RIGHT = pt->pt[j].x;
if (listnum == 9) if (LEFT > pt->pt[j].x) LEFT = pt->pt[j].x;
if (listnum == 9) if (ZmaxVrmlCity < pt->pt[j].z) ZmaxVrmlCity = pt->pt[j].z;
if (listnum == 9) if (ZminVrmlCity > pt->pt[j].z) ZminVrmlCity = pt->pt[j].z;
pt->pt[j].x = mempt.x; // For an eventual second pass.
pt->pt[j].y = mempt.y;
pt->pt[j].z = mempt.z;
i++;
}
glEnd();
} // if (num_vertx==4
if (num_vertx==4) {
glBegin (GL_QUADS);
if (CNS->Geometry.IndexedFaceSet.solid == GL_FALSE) {
glCullFace (GL_FRONT_AND_BACK);// The culling must be within the glBegin
glEnable(GL_CULL_FACE);// if we want a triangle rendered when outside
} // of window boundary.
for (int marra = 0; marra<num_vertx; marra++) {
j=ind->pElements[i];
pt->pt[j].x = pt->pt[j].x + TransX;
pt->pt[j].y = pt->pt[j].y + TransY;
pt->pt[j].z = pt->pt[j].z + TransZ;
if (col_ind.num_el > c)
glColor3f (col.pt[col_ind.pElements[c]].r,
col.pt[col_ind.pElements[c]].g,
col.pt[col_ind.pElements[c]].b);
if (CNS->Texture.tex_name[0] !=99999) {
t=indtex->pElements[i];
//glBindTexture(GL_TEXTURE_2D, CNB->Geometry_ins.texture.tex_name[0]);
glTexCoord2f(CNS->Geometry.IndexedFaceSet.texCoord[t].x , CNS->Geometry.IndexedFaceSet.texCoord[t].y);
}
glVertex3f (pt->pt[j].x,
pt->pt[j].y,
pt->pt[j].z);
if (listnum == 9) if (TOP < pt->pt[j].y) TOP = pt->pt[j].y;
if (listnum == 9) if (BOTTOM > pt->pt[j].y) BOTTOM = pt->pt[j].y;
if (listnum == 9) if (RIGHT < pt->pt[j].x) RIGHT = pt->pt[j].x;
if (listnum == 9) if (LEFT > pt->pt[j].x) LEFT = pt->pt[j].x;
if (listnum == 9) if (ZmaxVrmlCity < pt->pt[j].z) ZmaxVrmlCity = pt->pt[j].z;
if (listnum == 9) if (ZminVrmlCity > pt->pt[j].z) ZminVrmlCity = pt->pt[j].z;
i++;
}
glEnd();
} // if (num_vertx>4
if (num_vertx>4) {
glBegin (GL_POLYGON);
if (CNS->Geometry.IndexedFaceSet.solid == GL_FALSE) {
glCullFace (GL_FRONT_AND_BACK);// The culling must be within the glBegin
glEnable(GL_CULL_FACE);// if we want a triangle rendered when outside
} // of window boundary.
for (int marra = 0; marra<num_vertx; marra++) {
j=ind->pElements[i];
pt->pt[j].x = pt->pt[j].x + TransX;
pt->pt[j].y = pt->pt[j].y + TransY;
pt->pt[j].z = pt->pt[j].z + TransZ;
if (col_ind.num_el > c)
glColor3f (col.pt[col_ind.pElements[c]].r,
col.pt[col_ind.pElements[c]].g,
col.pt[col_ind.pElements[c]].b);
if (CNS->Texture.tex_name[0] !=99999) {
t=indtex->pElements[i];
//glBindTexture(GL_TEXTURE_2D, CNB->Geometry_ins.texture.tex_name[0]);
glTexCoord2f(CNS->Geometry.IndexedFaceSet.texCoord[t].x , CNS->Geometry.IndexedFaceSet.texCoord[t].y);
}
glVertex3f (pt->pt[j].x,
pt->pt[j].y,
pt->pt[j].z);
if (listnum == 9) if (TOP < pt->pt[j].y) TOP = pt->pt[j].y;
if (listnum == 9) if (BOTTOM > pt->pt[j].y) BOTTOM = pt->pt[j].y;
if (listnum == 9) if (RIGHT < pt->pt[j].x) RIGHT = pt->pt[j].x;
if (listnum == 9) if (LEFT > pt->pt[j].x) LEFT = pt->pt[j].x;
if (listnum == 9) if (ZmaxVrmlCity < pt->pt[j].z) ZmaxVrmlCity = pt->pt[j].z;
if (listnum == 9) if (ZminVrmlCity > pt->pt[j].z) ZminVrmlCity = pt->pt[j].z;
i++;
}
glEnd();
} // if (num_vertx==3
// i++ to skip the -1 and position on the next valid input. ( no not necessary since i++ in for...)
c++;
} // for (int i = 0; i<ind->num_el; i++)
}
void Draw_Vrml(Type_Transform *CNlocal, int listnum) // CNlocal is either CNC or CNV or...
{
extern double TOP, BOTTOM, LEFT, RIGHT;
CN = CNlocal;
// calculate the correct Bounding box
if (listnum == 9) TOP = -9999999;
if (listnum == 9) BOTTOM = 9999999;
if (listnum == 9) LEFT = 9999999;
if (listnum == 9) RIGHT =-9999999;
if (listnum == 9) ZmaxVrmlCity = -9999999;
if (listnum == 9) ZminVrmlCity = 9999999;
TransX= TransY= TransZ=0; // Global Transformation.
trackball(curquat_vrml, 0.0, 0.0, 0.0,0.0);
nbr_vertex = 0;
glEnable (GL_TEXTURE_2D);
// find beginning of nodes
int counter = 0;
while (CN->node_type != Top_Scene)
CN = CN->FatherTransform;
// compile the list.
glNewList(listnum, GL_COMPILE_AND_EXECUTE);
while (Pass_To_Next_Trans()){
counter ++;
if (CN->ShapeLeave) {
CNS = CN->Shape;
Draw_Shape_Node(listnum);
}
else for (CN->indChildShape=0; CN->indChildShape<CN->numChildShape; CN->indChildShape++) {
CNS = CN->ChildrenShape[CN->indChildShape];
Draw_Shape_Node(listnum);
}
}// while
//cout << "number of Transform nodes" << counter << endl;
glDisable(GL_TEXTURE_2D);
glEndList();
cout << "nbr_vertex = " << nbr_vertex << endl;
cout << "top=" << TOP << " bottom=" << BOTTOM << "RIGHT=" << RIGHT <<" LEFT=" << LEFT << endl;
if (listnum == 9) XmaxVrmlCity = RIGHT;
if (listnum == 9) YmaxVrmlCity = TOP;
if (listnum == 9) XminVrmlCity = LEFT;
if (listnum == 9) YminVrmlCity = BOTTOM;
//if (listnum == 9) Virtual_Espace();
}
/* void Draw_Vrml_Vehicle()
{
CN = CNV;
//Draw_Vrml(19);
glNewList(19, GL_COMPILE_AND_EXECUTE);
glBegin(GL_TRIANGLES);
glVertex3f (0,0,0);
glVertex3f (0.1,0.1,0.1);
glVertex3f (0.1, 0, 0.2);
glEnd();
glEndList();
}
void Draw_Vrml_City()
{
CN = CNC;
Draw_Vrml(9);
CN = CNC;
Virtual_Espace();
} */
Test_For_Coord_In_Geometry_node()
{ /*if ((CN->node_type == n_geometry) &&
(CN->Geometry_ins.IndexedFaceSet_Ins.coord.point.num_el == 0))
CN->Geometry.IndexedFaceSet.coord = CN->Father->Geometry_ins.IndexedFaceSet_Ins.coord;*/
//cout << "forget me" << endl;
}
void
inline
OuvreAccolade()
{
CN->Acc++; // Not necessary yet.
AccTag = p_nothing; // Keeps track of the Accolades
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
Acc.indice = Acc.indice +1;
}
void
inline
OuvreCrochet()
{
CN->Cro++; // not necessary yet
AccTag = p_nothing; // Keeps track of the Accolades
Acc.indice = Acc.indice +1;
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
}
void
inline
FermeCrochet()
{
CN->Cro--; // not necessary yet
Acc.indice = Acc.indice -1;
if (Acc.indice <0) {
cout << "Acc.indice < 0 search for me..." << endl;
getchar();
exit(1);
}
}
void
inline
read_RAW_file (char *directory, unsigned char *image, int *im_width, int *im_height)
{
FILE * raw;
im_width [0] = 8;
im_height[0] = 8;
if ((raw = fopen (directory, "rb"))==NULL){
cout << "Error reading the raw file" << endl;
cout << "width = " << im_width[0] << " height=" << im_height[0]<< endl;
// But still allocates a 64 byte image, just so that the program doesn't crash...
if ((CNS->Texture.image = (unsigned char *)malloc (im_width[0]*im_height[0]*3) ) == NULL){
cout << "Malloc error here 938488uf74" << endl;
exit (1);
}
// fclose (raw);
return ;
}
fread (im_width , sizeof(int), 1,raw);
fread (im_height, sizeof(int), 1,raw);
//cout << "width = " << im_width[0] << " height=" << im_height[0]<< endl;
if ((CNS->Texture.image = (unsigned char *)malloc (im_width[0]*im_height[0]*3) ) == NULL){
cout << "Malloc error here 938488uf74" << endl;
exit (1);
}
fread (CNS->Texture.image, sizeof(unsigned char), im_width[0]*im_height[0]*3,raw);
//cout << "image read " << endl;
fclose (raw); /*
if ((CNS->Texture.image = (unsigned char *)malloc (128*256*3) ) == NULL){
cout << "Malloc error here 9384793874" << endl;
exit (1);
}
for (int muk = 0 ; muk <64*64*3; muk++)
CNS->Texture.image[muk] = 230;
CNS->Texture.im_width[0]= 128; CNS->Texture.im_height[0]=256; */
}
Type_Transform *
Read_Vrml_File(char *vrml_filename)
{
extern char *texture_directory;
// Initialize ScaleNormals to 1.
ScaleNormals.x = 1;
ScaleNormals.y = 1;
ScaleNormals.z = 1;
int size,i;
char wordd[90];
Acc.indice = 0;
iz.index = -1;
iz.texIndex = -1;
//glGenTextures(10,test);
// Open vrml file for reading
if ((file = fopen (vrml_filename,"r")) == NULL)
printf ("\n pas de chance l'ami ton fichier est corrompu 89472229099\n");
//cout << vrml_filename << endl;
// initialising the node top_scene.
CN = new Type_Transform;
initialize_Transform_node();
CN->node_type = Top_Scene;
previous_node_type = Top_Scene;
int counter2 = 0;
while (fscanf (file,"%s",&wordd) != EOF) {
// cout << wordd << endl;
wordd_to_node(wordd); // result in node
switch (node_type) {
case n_CroO:
OuvreCrochet();
break;
case n_CroF:
FermeCrochet();
break;
case n_AccO:
OuvreAccolade();
break;
case n_AccF:
CN->Acc--; // Not necessary yet.
Acc.indice = Acc.indice -1;
if (Acc.indice >=1000){
cout << "Change your indice, exit 38959988477683" << endl;
exit(1);
}
if (Acc.pipe[Acc.indice] == p_Transform)
CN = CN->FatherTransform;
if (Acc.indice <0) {
cout << "Acc.indice < 0 search for meeeee 135335..." << endl;
getchar();
exit(1);
}
break;
case n_IndexedFaceSet:
AccTag = p_IndexedFaceSet; // Keeps track of the Accolades
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
if (Acc.indice >=1000){
cout << "Change your indice, exit 38959988477683" << endl;
exit(1);
}
Acc.indice++;
fscanf (file,"%s",&wordd);
if (wordd[0] != '{') {
cout << "GetChar: An '{' is expected here!!! look for me 159395" << endl;
getchar();
}
break;
case n_Transform :
//Test_For_Coord_In_Geometry_node();
//cout << "Create_Child_Transform_Node" << endl;
Create_Child_Transform_Node();
initialize_Transform_node();
//cout << "CN-> " << CN->node_type << endl;
AccTag = p_Transform; // Keeps track of the Accolades
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
if (Acc.indice >=1000){
cout << "Change your indice, exit 38959988477683" << endl;
exit(1);
}
Acc.indice++;
counter2 ++;
fscanf (file,"%s",&wordd);
if (wordd[0] != '{') {
cout << "GetChar: An '{' is expected here!!! look for me 159395" << endl;
getchar();
}
node_type = nothing;
break;
case n_Appearance:
//Test_For_Coord_In_Geometry_node();
//Create_Son_Node();
//CN->node_type = n_Appearance;
//previous_node_type = n_Appearance;
//CN->Geometry_ins.texture.tex_name[0] = 99999;
AccTag = p_Appearance; // Keeps track of the Accolades
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
if (Acc.indice >=1000){
cout << "Change your indice, exit 38959988477683" << endl;
exit(1);
}
Acc.indice++;
fscanf (file,"%s",&wordd);
if (wordd[0] != '{') {
cout << "GetChar: An '{' is expected here!!! look for me 159395" << endl;
getchar();
}
node_type = nothing;
break;
case n_geometry:
//if (previous_node_type == n_Appearance)
// Create_Brother_Node();
//else Create_Son_Node();
//CN->node_type = n_geometry;
// strcpy (CN->Geometry_ins.texture.tex_blk , "nothing");
previous_node_type = n_geometry;
node_type = nothing;
break;
case n_children:
CN->FlagChildren = 1;
AccTag = p_children; // Keeps track of the Accolades
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
if (Acc.indice >=1000){
cout << "Change your indice, exit 378838789583" << endl;
exit(1);
}
Acc.indice++;
fscanf (file,"%s",&wordd);
if (wordd[0] != '[') {
cout << "GetChar: An '[' is expected here!!! look for me 193843" << endl;
getchar();
}
break;
case n_Shape:
if (CN->FlagChildren){
Create_Child_Shape_Node();
InitializeChildrenShape();
} else {
Create_One_Shape_Node();
InitializeChildrenShape();
}
AccTag = p_Shape; // Keeps track of the Accolades
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
if (Acc.indice >=1000){
cout << "Change your indice, exit 879384733" << endl;
exit(1);
}
Acc.indice++;
fscanf (file,"%s",&wordd);
if (wordd[0] != '{') {
cout << "GetChar: An '{' is expected here!!! look for me 9593962" << endl;
getchar();
}
node_type = nothing;
break;
case n_Material:
//Create_Son_node();
//CN->node_type = n_Material;
AccTag = p_Material; // Keeps track of the Accolades
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
if (Acc.indice >=1000){
cout << "Change your indice, exit 98374983" << endl;
exit(1);
}
Acc.indice++;
fscanf (file,"%s",&wordd);
if (wordd[0] != '{') {
cout << "GetChar: An '{' is expected here!!! look for me 991995922" << endl;
getchar();
}
break;
case n_translation:
// the CN is a Transform.
CN->translation.x = LisFlWrl();
CN->translation.y = LisFlWrl();
CN->translation.z = LisFlWrl();
node_type = nothing;
break;
case n_scale:
// the CN is a Transform.
CN->FlagScale = 1;
CN->scale.x = LisFlWrl();
CN->scale.y = LisFlWrl();
CN->scale.z = LisFlWrl();
node_type = nothing;
break;
case n_rotation:
// the CN is a Transform.
CN->rotation.x = LisFlWrl();
CN->rotation.y = LisFlWrl();
CN->rotation.z = LisFlWrl();
CN->rotation.teta = LisFlWrl();
node_type = nothing;
break;
case n_diffuseColor:
CNS->Appearance.material.diffuseColor.r = LisFlWrl();
CNS->Appearance.material.diffuseColor.g = LisFlWrl();
CNS->Appearance.material.diffuseColor.b = LisFlWrl();
node_type = nothing;
break;
case n_specularColor:
CNS->Appearance.material.specularColor.r = LisFlWrl();
CNS->Appearance.material.specularColor.g = LisFlWrl();
CNS->Appearance.material.specularColor.b = LisFlWrl();
node_type = nothing;
break;
case n_shininess:
CNS->Appearance.material.shininess = LisFlWrl();
node_type = nothing;
break;
case n_transparency:
CNS->Appearance.material.transparency = LisFlWrl();
node_type = nothing;
break;
case f_solid:
fscanf (file,"%s",&wordd);
if ((strcmp (wordd,"FALSE"))==0)
CNS->Geometry.IndexedFaceSet.solid = GL_FALSE;
else
CNS->Geometry.IndexedFaceSet.solid = GL_TRUE;
break;
case n_TimeSensor:
AccTag = p_TimeSensor; // Keeps track of the Accolades
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
if (Acc.indice >=1000){
cout << "Change your indice, exit 3398439899903" << endl;
exit(1);
}
Acc.indice++;
fscanf (file,"%s",&wordd);
if (wordd[0] != '{') {
cout << "GetChar: An '{' is expected here!!! look for me 159383395" << endl;
getchar();
}
break;
case f_coord:
fscanf (file,"%s",&wordd);
if (strcmp(wordd,"DEF") == 0){
// Put Blk_name in hash table
iz.index++;
fscanf (file, "%s", &UseDef[iz.index].blk_name);
//UseDef[iz.index].coord = CNS->Geometry.IndexedFaceSet.coord; after reading the pts bozzo!!
// Reads p_Coordinate
fscanf (file,"%s",&wordd);
fscanf (file,"%s",&wordd);
if (wordd[0] != '{') {
cout << "GetChar: An '{' is expected here!!! look for me 159395" << endl;
getchar();
}
AccTag = p_Coordinate; // Keeps track of the Accolades
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
if (Acc.indice >=1000){
cout << "Change your indice, exit 3899932878897213" << endl;
exit(1);
}
Acc.indice++;
fscanf (file,"%s",&wordd);
wordd_to_node(wordd);
if (node_type == n_point)
read_all_points_into_this_node();
if (ADJUST_TO_ZERO) {
adjust_to_zero();
if ((UseDef[iz.index].blk_name[2] == 'R') && (UseDef[iz.index].blk_name[3] == 'O') &&
(UseDef[iz.index].blk_name[4] == 'A') && (UseDef[iz.index].blk_name[5] == 'D') )
Saffir_the_ys();
if ((UseDef[iz.index].blk_name[2] == 'C') && (UseDef[iz.index].blk_name[3] == 'U') &&
(UseDef[iz.index].blk_name[4] == 'R') && (UseDef[iz.index].blk_name[5] == 'B') )
Saffir_the_ys();
if ((UseDef[iz.index].blk_name[2] == 'T') && (UseDef[iz.index].blk_name[3] == 'O') &&
(UseDef[iz.index].blk_name[4] == 'P') && (UseDef[iz.index].blk_name[5] == 'O') )
Saffir_the_ys();
}
UseDef[iz.index].coord = CNS->Geometry.IndexedFaceSet.coord;
node_type = nothing;
}
// If Use coord of another blk, just put it in!!
if (strcmp(wordd,"USE") == 0) {
fscanf (file, "%s", &wordd);
for (int ozi=0;ozi<=iz.index; ozi++)
if (strcmp(wordd,UseDef[ozi].blk_name) == 0)
CNS->Geometry.IndexedFaceSet.coord = UseDef[ozi].coord;
}
break;
case n_normal:
fscanf (file, "%s", &wordd); //reads Normal
if (strcmp (wordd, "Normal") != 0) {
cout << "What could be in front of normal else then Normal?? " << endl;
exit (0);
getchar();
}
fscanf (file, "%s", &wordd); //reads {
if (strcmp (wordd, "{") != 0) {
cout << "What could be in front of normal Normal else then {?? " << endl;
exit (0);
getchar();
}
else
OuvreAccolade();
fscanf (file, "%s", &wordd); //reads vector
if (strcmp (wordd, "vector") != 0) {
cout << "What could be in front of normal Normal { else then vector?? " << endl;
exit (0);
getchar();
}
read_all_normal_vectors_into_this_node();
break;
#if 1
case f_texture:
fscanf (file,"%s",&wordd); // Reads ImageTexture
fscanf (file,"%s",&wordd); // Reads {
fscanf (file,"%s",&wordd); // Reads url
fscanf (file,"%s",&wordd); // Reads "image.jpg"
char directory [200];
strcpy (directory, texture_directory);
//strcpy (directory, "/home/grof/MRcode/ver.5.1/"); WinUnix
//strcpy (directory, "D:\\Arch98_Class\\VirtCity\\"); // WinUnix
//strcpy (directory, "D:\\Arch98_Class\\VirtCity\\"); // WinUnix
for (i = 1; i<89; i++){
if (wordd[i] == '"') wordd[i] = wordd[i+1];
wordd[i-1] = wordd[i];
}
// cout << wordd ;
strcat (directory, wordd);
/* read_RAW_file (directory,
CNS->Texture.image,
CNS->Texture.im_width,
CNS->Texture.im_height); */
CNS->Texture.image=
read_JPEG_file (wordd, directory,
CNS->Texture.image,
CNS->Texture.im_width,
CNS->Texture.im_height);
// cout << CNS->Texture.im_width[0] << " " << CNS->Texture.im_height[0] << endl;
/* if ((CNS->Texture.image = (unsigned char *)malloc (128*256*3) ) == NULL){
cout << "Malloc error here 9384793874" << endl;
exit (1);
}
for (int muk = 0 ; muk <64*64*3; muk++)
CNS->Texture.image[muk] = 230;
CNS->Texture.im_width[0]= 128; CNS->Texture.im_height[0]=256; */
//cout << wordd << endl;
//cout << CNS->Texture.im_width[0] << " " << CNS->Texture.im_height[0] << endl;
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glGenTextures(1,CNS->Texture.tex_name);
glBindTexture(GL_TEXTURE_2D, CNS->Texture.tex_name[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); //GL_CLAMP); //GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); //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
CNS->Texture.im_width[0], CNS->Texture.im_height[0],
0, // border
GL_RGB, // format
GL_UNSIGNED_BYTE, // type
CNS->Texture.image);
fscanf (file,"%s",&wordd); // Reads }
if (wordd[0] != '}') { cout << "error reading }..!! getchar()" << endl;
getchar();
}
break;
case f_texCoord:
fscanf (file, "%s", &wordd);
if (strcmp (wordd, "DEF") == 0) {
iz.texIndex++;
fscanf (file, "%s", &UseDef[iz.texIndex].tex_blk_name);
strcpy(CNS->Texture.tex_blk,UseDef[iz.texIndex].tex_blk_name);
fscanf (file, "%s", &wordd);
if (strcmp (wordd, "TextureCoordinate") !=0){
cout << "Getchar! Que peut il y avoir apres texCoord qui ne soit pas DEF, USE ou TextureCoordinate?" << endl;
getchar();
}
AccTag = p_TextureCoordinate ; // Keeps track of the Accolades
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
if (Acc.indice >=1000){
cout << "Change your indice, exit 9899399399587778" << endl;
exit(1);
}
Acc.indice++;
fscanf (file,"%s",&wordd);
if (wordd[0] != '{') {
cout << "GetChar: An '{' is expected here!!! look for me 159395" << endl;
getchar();
}
fscanf (file,"%s",&wordd);
wordd_to_node(wordd);
if (node_type == n_point)
read_all_texture_points_into_this_node();
else {
cout << "Getchar! Que peut il y avoir ici qui ne soit pas point???" << endl;
getchar();
}
UseDef[iz.texIndex].texCoord = CNS->Geometry.IndexedFaceSet.texCoord;
}else
if (strcmp (wordd, "USE") == 0){
//Type_Transform *CN_UP = CN;
fscanf (file,"%s", &wordd);
for (int ozi=0;ozi<=iz.texIndex; ozi++)
if (strcmp(wordd,UseDef[ozi].tex_blk_name) == 0)
CNS->Geometry.IndexedFaceSet.texCoord = UseDef[ozi].texCoord;
//while (strcmp (CN_UP->Geometry_ins.texture.tex_blk , wordd) != 0)
// CN_UP = CN_UP->Father;
//CN->Geometry_ins.IndexedFaceSet_Ins.texCoord = CN_UP->Geometry_ins.IndexedFaceSet_Ins.texCoord;
}else
if (strcmp (wordd, "TextureCoordinate") == 0) {
fscanf (file,"%s",&wordd);
if (wordd[0] != '{') {
cout << "GetChar: An '{' is expected here!!! look for me 159395" << endl;
getchar();
}
AccTag = p_TextureCoordinate ; // Keeps track of the Accolades
Acc.pipe[Acc.indice] = AccTag; // Keeps track of the Accolades
if (Acc.indice >=1000){
cout << "Change your indice, exit 99887763325621" << endl;
exit(1);
}
Acc.indice++;
fscanf (file,"%s",&wordd);
wordd_to_node(wordd);
if (node_type == n_point)
read_all_texture_points_into_this_node();
else {
cout << "Getchar! Que peut il y avoir ici qui ne soit pas point???" << endl;
getchar();
}
}
node_type = nothing;
break;
case f_texCoordIndex:
read_all_texCoordIndex_into_CN();
break;
#endif
case n_coordIndex:
//cout << "reading coordIndex " << endl;
read_all_coordIndex_into_CN();
break;
case f_colorIndex:
read_all_colorIndex_into_CN();
break;
case f_color:
fscanf (file,"%s",&wordd);
if ((strcmp (wordd,"["))==0)
read_color_values();
break;
}
}
// Maybe the last node is a Geometry node and has the coord field not set yet.
//if (CN->node_type == n_geometry) Test_For_Coord_In_Geometry_node();
//cout << "After reading the vrml find there was " << counter2 << "transform nodes" << endl;
//cout << "Number of nodes transform Created" << counter3 << endl;
return (CN);
}
void test_bassit()
{
float xmin = -500;
float xmax = 500;
float ymin = -500;
float ymax = 500;
float zmin = -500;
float zmax = 500;
/* glPopMatrix();
glPushMatrix(); */
glBegin(GL_LINES);
glColor3f (0.45,0.45,0.45);
glVertex3f (xmin,ymax,zmax);
glVertex3f (xmax,ymax,zmax);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45,0.45,0.45);
glVertex3f (xmax,ymax,zmax);
glVertex3f (xmax,ymin,zmax);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45,0.45,0.45);
// glColor3f (0.5,0,0);
glVertex3f (xmax,ymin,zmax);
glVertex3f (xmin,ymin,zmax);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45,0.45,0.45);
// glColor3f (0.0,0.5,0.0);
glVertex3f (xmin,ymin,zmax);
glVertex3f (xmin,ymax,zmax);
glEnd();
/* glBegin(GL_LINES);
glColor3f (0.45,0.45,0.45);
// glColor3f (0,0,0.8);
glVertex3f (xmin,ymax,zmax);
glVertex3f (xmin,ymax,zmin);
glEnd();
glBegin(GL_LINES);
glColor3f (0.45,0.45,0.45);
//glColor3f (0,0,0.8);
glVertex3f (xmax,ymax,zmax);
glVertex3f (xmax,ymax,zmin);
glEnd();
glBegin(GL_LINES);
glColor3f (0,0,0.8);
glVertex3f (xmax,ymin,zmax);
glVertex3f (xmax,ymin,zmin);
glEnd();
glBegin(GL_LINES);
glColor3f (0,0,0.8);
glVertex3f (xmin,ymin,zmax);
glVertex3f (xmin,ymin,zmin);
glEnd();*/
glTranslatef(0.0,0.0,-1000.0);
glBegin(GL_LINES);
glColor3f (0.0,0.5,0.0);
glVertex3f (xmin,ymax,zmax);
glVertex3f (xmin,ymin,zmax);
glEnd();
glBegin(GL_LINES);
glColor3f (0.5,0,0);
glVertex3f (xmin,ymin,zmax);
glVertex3f (xmax,ymin,zmax);
glEnd();
glBegin(GL_LINES);
glColor3f (0.0,0.5,0.0);
glVertex3f (xmax,ymin,zmax);
glVertex3f (xmax,ymax,zmax);
glEnd();
glBegin(GL_LINES);
glColor3f (0.5,0,0);
glVertex3f (xmax,ymax,zmax);
glVertex3f (xmin,ymax,zmax);
glEnd();
}
void ReadBufferSphere(Type_Transform *CNSphere)
{
// must be in this file for some puttain unknown reason!!!
glReadBuffer(GL_BACK);
glReadPixels (0,0, CNSphere->ChildrenTransform[0]->ChildrenShape[0]->Texture.im_width[0],
CNSphere->ChildrenTransform[0]->ChildrenShape[0]->Texture.im_height[0],
GL_RGB, GL_UNSIGNED_BYTE,
CNSphere->ChildrenTransform[0]->ChildrenShape[0]->Texture.image); // image[0][0]);
glBindTexture (GL_TEXTURE_2D, CNSphere->ChildrenTransform[0]->ChildrenShape[0]->Texture.tex_name[0]);
glTexImage2D( GL_TEXTURE_2D, // target
0, // level
//0, 0, // xoffset, yoffset
GL_RGB, // format
CNSphere->ChildrenTransform[0]->ChildrenShape[0]->Texture.im_width[0],
CNSphere->ChildrenTransform[0]->ChildrenShape[0]->Texture.im_height[0], // Width, Height
//im_width[0], im_height[0],
0, // border
GL_RGB, // format
GL_UNSIGNED_BYTE, // type
//image);
CNSphere->ChildrenTransform[0]->ChildrenShape[0]->Texture.image); // GLvoid *pixels */
}