Main Page | Namespace List | Class List | File List | Class Members | File Members

scene.h File Reference

#include <string>

Go to the source code of this file.

Classes

struct  Point3Struct

Typedefs

typedef Point3Struct Point3

Enumerations

enum  MODELS {
  MODEL_GALLOWS = 0, MODEL_GALLOWS_ROPE, MODEL_IRON_MAIDEN, MODEL_CRYPT,
  MODEL_DIABLO, MODEL_CASKET_CLOSED, MODEL_CASKET_OPENED_1, MODEL_CASKET_OPENED_2,
  MODEL_GILJOTINA_1, MODEL_GILJOTINA_2, MODEL_GILJOTINA_3, MODEL_GILJOTINA_4,
  MODEL_GRAVEYARD, MODEL_MANCAGE_1, MODEL_MANCAGE_2, MODEL_PLAYER,
  MODEL_N
}

Functions

Point3Struct operator+ (Point3Struct, Point3Struct)
void drawModel (int, int, double, double, double, double, double, double, double, double, double, double)
void drawFaces (int, double)
void deleteModels ()
int addModel (std::string)

Variables

std::string model_name [MODEL_N]
bool model_in_use [MODEL_N]
unsigned int model_index [MODEL_N]
bool model_use_list [MODEL_N]
int model_handle [MODEL_N]


Typedef Documentation

typedef struct Point3Struct Point3
 

Referenced by addModel(), drawFaces(), and operator+().


Enumeration Type Documentation

enum MODELS
 

Enumeration values:
MODEL_GALLOWS 
MODEL_GALLOWS_ROPE 
MODEL_IRON_MAIDEN 
MODEL_CRYPT 
MODEL_DIABLO 
MODEL_CASKET_CLOSED 
MODEL_CASKET_OPENED_1 
MODEL_CASKET_OPENED_2 
MODEL_GILJOTINA_1 
MODEL_GILJOTINA_2 
MODEL_GILJOTINA_3 
MODEL_GILJOTINA_4 
MODEL_GRAVEYARD 
MODEL_MANCAGE_1 
MODEL_MANCAGE_2 
MODEL_PLAYER 
MODEL_N 

Definition at line 18 of file scene.h.


Function Documentation

int addModel (  std::string   ) 
 

Referenced by initGL().

void deleteModels (   ) 
 

void drawFaces (  int  handle,
double  scale
) 
 

Draw Faces Given the array of vertices and array of faces this function ouputs the vertices of triangle strips or triangles defining these faces Input: handle, scaling factor

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT ); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture(TEX_CHECK));

Definition at line 232 of file scene.cpp.

References Faces, Model_partStruct::ind_faces, ModelStruct::ind_model_parts, Model_partStruct::ind_vertices, Model_parts, Models, Model_partStruct::nfaces, normal, Normals, Point3, and Vertices.

Referenced by drawModel().

00233 {
00234 ModelStruct *model =  ((ModelStruct *)Models + handle);  
00235 Model_partStruct *model_part;
00236 //printf(" model has %d model_parts \n", model -> nmodel_parts);
00237 
00238 Point3 vertex[3];
00239 Point3Struct * vertex_ptr;
00240 Point3 normal;
00241 Point3Struct * normal_ptr;
00242 long face;
00243 long *face_ptr;
00244 
00245 double A, B, C, D;
00246 double cosalpha, cosbeta, cosgamma, mu;
00247 Point3 tex[3];
00248 
00249 double oldbeta;
00250 double alpha, beta, gamma;
00251 
00252 //setDiffuseMaterialColor( colorWhite );
00253 
00254 
00255 
00256 //cout << "start of faces array " << (int) ((long *)Faces) << endl;
00257 
00258 //glPushMatrix();
00259 
00260 
00261 
00262 glDisable( GL_TEXTURE_GEN_S);
00263 glDisable( GL_TEXTURE_GEN_T);
00264 glDisable( GL_TEXTURE_GEN_R);
00265 /*
00266 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
00267 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
00268 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST );
00269 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
00270 */
00278 for (int i=0; i < model -> nmodel_parts; i++)
00279     {//drawing every part as a separate object
00280 //cout << "drawing part " << i << endl;
00281 //cout.flush();
00282 
00283     model_part = ((Model_partStruct *)Model_parts + model->ind_model_parts + i);
00284 
00285 //cout << "start of the face " << (int) ((long *)Faces + model_part->ind_faces) << endl;
00286 //cout << "end   of the face " << (int) ((long *)Faces + model_part->ind_faces + (model_part->nfaces-1)*3 + 2) << endl;
00287 
00288 //glPushMatrix();
00289 
00290     for (int j=0; j < model_part->nfaces; j++ )
00291         {//drawing every face
00292 
00293 //cout << j << ",";
00294 //cout.flush();
00295             normal_ptr = ((Point3 *)Normals + model_part->ind_faces + j);
00296             normal = *normal_ptr;
00297 
00298         for (int k=0; k < 3; k++ )
00299             {
00300             face_ptr = ((long *)Faces + model_part->ind_faces*3 + j*3 + k);
00301             face = *face_ptr;
00302             
00303             vertex_ptr = ((Point3 *)Vertices + model_part->ind_vertices + face);
00304             vertex[k] = *vertex_ptr;
00305 
00306             }//end for k
00307 
00308 /*
00309 //determining the coefficients in plane's equation
00310 A = ( (vertex[1].y - vertex[0].y)*(vertex[2].z - vertex[0].z) ) - ( (vertex[1].z - vertex[0].z)*(vertex[2].y - vertex[0].y) );
00311 B = ( (vertex[1].z - vertex[0].z)*(vertex[2].x - vertex[0].x) ) - ( (vertex[2].z - vertex[0].z)*(vertex[1].x - vertex[0].x) );
00312 C = ( (vertex[1].x - vertex[0].x)*(vertex[2].y - vertex[0].y) ) - ( (vertex[1].y - vertex[0].y)*(vertex[2].x - vertex[0].x) );
00313 D = - ( vertex[0].x*A + vertex[0].y*B + vertex[0].z*C );
00314 
00315 if (D < 0)
00316     {
00317     //normalizing
00318     D = -D;
00319     A = -A;
00320     B = -B;
00321     C = -C;
00322     }
00323 
00324 //computing normalized equation of the plane
00325     //since (D >= 0) we certainly know which root to take for mu
00326 mu = (-1) / sqrt( A*A + B*B + C*C );
00327 
00328 //printf(" mu = %f, A = %f, B = %f, C = %f, D = %f \n", mu, A, B, C, D );
00329 
00330 cosalpha = mu * A;
00331 cosbeta  = mu * B;
00332 cosgamma = mu * C;
00333 
00334 alpha = acos (cosgamma);// - M_PI/2;
00335 beta  = acos (cosbeta)  ;
00336 gamma = acos (cosgamma) ;
00337 
00338 oldbeta = beta;
00339 //alpha += M_PI/2;
00340 
00341 beta  *= cos(alpha );
00342 //beta += M_PI/2;
00343 gamma = gamma*(cos(oldbeta  ) ) ;
00344 gamma = gamma*(sin(alpha));
00345 //gamma += M_PI;
00346 //gamma *=sin(alpha );
00347 
00348 glDisable(GL_TEXTURE_2D);
00349     glMatrixMode ( GL_TEXTURE );
00350     glLoadIdentity ();
00351 
00352     glRotated ( gamma * 180.0f/M_PI , 0, 1, 0);
00353     glRotated ( beta  * 180.0f/M_PI, 0, 0, 1);
00354     glRotated ( alpha * 180.0f/M_PI, 1, 0, 0);
00355 
00356     glMatrixMode (GL_MODELVIEW);
00357 
00358 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
00359 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
00360 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT );
00361 
00362 glEnable(GL_TEXTURE_2D);
00363 glBindTexture(GL_TEXTURE_2D, texture(TEX_CHECK));
00364 
00365 //printf(" cos is  %f, %f, %f \n", cosalpha, cosbeta, cosgamma );
00366 //printf(" acos is %f, %f, %f \n", acos(cosalpha)*180.0f/M_PI, acos(cosbeta)*180/M_PI, acos(cosgamma)*180/M_PI ); 
00367 
00368 //glMatrixMode (GL_MODELVIEW);
00369 
00370 for (int k=0; k<3; k++) 
00371     {
00372     tex[k].x =   vertex[k].x*scale/5;
00373     tex[k].y =   vertex[k].y*scale/5;
00374     tex[k].z =   vertex[k].z*scale/5;
00375     }
00376 
00377   
00378 */
00379 //printf(" x=%f y=%f \n", texture[0].x, texture[0].y);
00380         glBegin(GL_TRIANGLES);
00382                 glNormal3d( normal.x, normal.y, normal.z);
00383                             
00384                 for (int k=0; k<3; k++)
00385                 {
00386 //              glTexCoord3d( tex[k].x, tex[k].y, tex[k].z );
00387                 glVertex3d( vertex[k].x, vertex[k].y, vertex[k].z);
00388                 }//end for k
00389         glEnd();
00390 
00391 //glPopMatrix();
00392         }//end for j
00393 
00394 //glPopMatrix();
00395 
00396     }//end for i
00397 glDisable(GL_TEXTURE_2D);
00398 //glPopMatrix();
00399 
00400 
00401 
00402 
00403 //cout << " all parts are drawn";
00404 //cout.flush();
00405     
00406 /*
00407 glBegin(GL_TRIANGLES);
00408     
00409     glNormal3d( normal.x / len, normal.y / len, normal.z / len );
00410     glVertex3d(vertexa.x, vertexa.y, vertexa.z);
00411 
00412 
00413     glNormal3d( normal.x / len, normal.y / len, normal.z / len );
00414     glVertex3d(vertexb.x, vertexb.y, vertexb.z);
00415 
00416 
00417     glNormal3d( normal.x / len, normal.y / len, normal.z / len );
00418     glVertex3d(vertexc.x, vertexc.y, vertexc.z);
00419     
00420     }
00421 glEnd();
00422 */
00423 }

void drawModel (  int  ,
int  ,
double  ,
double  ,
double  ,
double  ,
double  ,
double  ,
double  ,
double  ,
double  ,
double 
) 
 

Definition at line 426 of file scene.cpp.

References drawFaces(), g_cellsize, g_show_axis, and gethf().

Referenced by __drawModel().

00427 {
00428 
00429 if (handle == -1)
00430     {
00431     printf(" Incorrect model handler. Probably, model was not initialized properly. \n ");
00432     exit(1);
00433     }
00434 
00435 float hf;
00436 
00437 hf = gethf( (int) round(x/g_cellsize), (int) round (y/g_cellsize) );
00438 
00439 //hf *= g_fHeightScale;
00440 
00441 //hf -= g_fHeight;
00442 //we start to output vertices in order, defined by face array
00443 //int n= sizeof(gallows_1_face)/ (sizeof(long)*3);
00444 
00445 
00446 glDisable(GL_AUTO_NORMAL);
00447 glEnable(GL_NORMALIZE);
00448 glDisable(GL_CULL_FACE);
00449 glCullFace(GL_NONE);
00450 glMatrixMode(GL_MODELVIEW);
00451 glPushMatrix();
00452 glTranslated(x, z + hf, y);
00453 glTranslated(-X, -Z, -Y);//, 0);/-Z);//-Y*g_cellsize, -Z);
00454 glRotated(fi,    1, 0, 0);
00455 glRotated(theta, 0, 1, 0);
00456 glRotated(psi,   0, 0, 1);
00457 glScaled(scale, scale, scale);
00458 /*
00459       if ( model_use_list[model] )
00460             {
00461             glCallList ( model_index[model] );
00462             }
00463         else
00464             {
00465 */
00466     drawFaces (handle, scale);
00467 //          }
00468 glPopMatrix();
00469 
00470 glDisable(GL_AUTO_NORMAL);
00471 glDisable(GL_NORMALIZE);
00472 
00473 //setDiffuseMaterialColor( colorWhite );
00474 //coordinate axises for object
00475 if (g_show_axis)
00476     {
00477     glPushMatrix();
00478 glMatrixMode(GL_MODELVIEW);
00479 glTranslated(x*g_cellsize, z + hf, y*g_cellsize);
00480 glTranslated(-X*g_cellsize, -Z, -Y*g_cellsize);//, 0);//-Z);//-Y*g_cellsize, -Z);
00481 
00482 glLineWidth(2);
00483     glBegin(GL_LINES);
00484         glColor3d(1, 0, 0);
00485         glVertex3d(0, 0, 0);
00486         glColor3d(1, 0, 0);
00487         glVertex3d(10, 0, 0);
00488     glEnd();
00489     
00490     glBegin(GL_LINES);
00491         glColor3d(0, 1, 0);
00492         glVertex3d(0, 0, 0);
00493         glColor3d(0, 1, 0);
00494         glVertex3d(0, 12, 0);
00495     glEnd();
00496 
00497     glBegin(GL_LINES);
00498         glColor3d(0, 0, 1);
00499         glVertex3d(0, 0, 0);
00500         glColor3d(0, 0, 1);
00501         glVertex3d(0, 0, 15);
00502     glEnd();
00503 glLineWidth(1);
00504 
00505         glColor3d(1, 1, 1);
00506 
00507     glPopMatrix();
00508     }
00509 
00510 //setDiffuseMaterialColor( colorWhite );
00511     
00512 
00513 //printf("\n X %f, Y %f , Z %f, ", X, Y, Z); 
00514 
00515 
00516 }

Point3Struct operator+ (  Point3Struct  ,
Point3Struct 
) 
 

Definition at line 83 of file scene.cpp.

References Point3, Point3Struct::x, Point3Struct::y, and Point3Struct::z.

00084 {
00085 Point3 pp;
00086 pp.x = p1.x + p2.x;
00087 pp.y = p1.y + p2.y;
00088 pp.z = p1.z + p2.z;
00089 return(pp);
00090 }


Variable Documentation

int model_handle[MODEL_N]
 

Definition at line 46 of file scene.h.

Referenced by __drawModel(), and initGL().

bool model_in_use[MODEL_N]
 

Definition at line 40 of file scene.h.

Referenced by initGL(), and renderScene().

unsigned int model_index[MODEL_N]
 

Definition at line 42 of file scene.h.

Referenced by initGL(), and renderScene().

std::string model_name[MODEL_N]
 

Definition at line 38 of file scene.h.

Referenced by initGL().

bool model_use_list[MODEL_N]
 

Definition at line 44 of file scene.h.

Referenced by initGL(), and renderScene().


Generated on Thu Jan 20 02:46:59 2005 for Main_Demo by doxygen 1.3.6