include/objects.h

Go to the documentation of this file.
00001 #ifndef _OBJECTS_H
00002 
00003 #include <stdio.h>                      // Header File For Standard Input/Output
00004 #include <GL/gl.h>
00005 #include <GL/glu.h>
00006 #include <SDL/SDL.h>
00007 #ifdef __APPLE__
00008 #include <SDL_image/SDL_image.h>
00009 #else
00010 #include <SDL/SDL_image.h>
00011 #endif
00012 #include <string>
00013 #include <iostream>
00014 #include <fstream>
00015 #include <cmath>
00016 #include <cassert>
00017 
00018 #include <list>
00019 #include <map>
00020 
00021 //#include "terrain.h"
00022 #include "utility.h"
00023 #include "quat.h"
00024 #include "camera.h"
00025 #include "model.h"
00026 #include "joepack.h"
00027 
00028 #include "globals.h"
00029 
00030 #define TRIANGLES_PER_BBOX 1
00031 
00032 #define COLLIDE_AND_DRIVE_TOGETHER true
00033 
00034 class OBJECTTRI
00035 {
00036 public:
00037         VERTEX v1;
00038         VERTEX v2;
00039         VERTEX v3;
00040 };
00041 
00042 class OBJECTMODEL
00043 {
00044 public:
00045         JOEMODEL jmodel;
00046         string name;
00047         OBJECTMODEL * next;
00048         bool fullbright;
00049         bool skybox;
00050         bool blend;
00051 };
00052 
00053 class OBJECTNODE
00054 {
00055 public:
00056         VERTEX pos;
00057         bool driveable;
00058         bool cancollide;
00059         OBJECTNODE * next;
00060         QUATERNION dir;
00061         OBJECTMODEL * model;
00062         string texture; //used to group and draw objects based on texture (for speed)
00063         float friction1; //the friction coefficient for non-treaded tires
00064         float friction2; //the friction coefficient for treaded tires
00065         float bumplength;
00066         float bumpmag;
00067         float rolling_resistance_factor;
00068         float rolling_drag;
00069 
00070         OBJECTNODE();
00071 };
00072 
00073 class OBJCOLNODE
00074 {
00075 public:
00076         OBJCOLNODE();
00077         OBJCOLNODE(const OBJCOLNODE & other);
00078         OBJCOLNODE& operator= (const OBJCOLNODE &other);
00079         bool operator==(const OBJCOLNODE & other);
00080         bool operator<(const OBJCOLNODE & other);
00081         void SortVerts();
00082         bool EqualGeom(const OBJCOLNODE & other);
00083         
00084 //private:
00085         OBJECTNODE * object;
00086         short vertexIndex[3];
00087 };
00088 
00089 class OBJCOLBRANCH
00090 {
00091 public:
00092         OBJCOLBRANCH();
00093         void DeleteChildren();
00094         AABB bbox;
00095         OBJCOLBRANCH * left;
00096         OBJCOLBRANCH * right;
00097         list <OBJCOLNODE *> leaves;
00098 };
00099 
00100 class OBJECTCOLLISION
00101 {
00102 public:
00103         ~OBJECTCOLLISION();
00104         
00105         void AddColNode(OBJECTNODE * newobject, short * newvi);
00106         //bool Collide(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest, VERTEX & normal);
00107         bool CollideDriveable(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest, VERTEX & normal);
00108         bool CollideAABB(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest, VERTEX & normal, float seglen, OBJECTNODE * &colnode);
00109         bool CollideAABB_double(VERTEXD origin, VERTEXD direction, VERTEXD &outtri, bool closest, VERTEXD & normal, double seglen);
00110         bool CollideModelAABB(VERTEX * modelverts, int numfaces, AABB modelbbox, VERTEX & outtri, bool closest, VERTEX & normal, float & depth);
00111         void GenerateCollisionTree();
00112         void Clear();
00113         void GetTrisInBBox(AABB bbox, list <OBJECTTRI> & trilist);
00114 
00115 private:
00116         list <OBJCOLNODE> colnodes;
00117         list <OBJCOLNODE> drvnodes;
00118 
00119         OBJCOLBRANCH coltree;
00120         void GenerateBranches(OBJCOLBRANCH * branch);
00121         bool CollideBranch(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest, OBJCOLBRANCH * branch, VERTEX & normal, float seglen, int & testcount, OBJECTNODE * &colnode);
00122         bool CollideBranch_double(VERTEXD origin, VERTEXD direction, VERTEXD &outtri, bool closest, OBJCOLBRANCH * branch, VERTEXD & normal, double seglen);
00123         bool CollideBranchModel(VERTEX * modelverts, int numfaces, AABB & modelbbox, VERTEX & outtri, bool closest, OBJCOLBRANCH * branch, VERTEX & normal, float & depth, int & testcount);
00124         bool CollideBranchGetTrisInBBox(AABB bbox, list <OBJECTTRI> & trilist, OBJCOLBRANCH * branch);
00125 };
00126 
00127 class OBJECTS
00128 {
00129 private:
00130         float lod_far;
00131         int display_x, display_y;
00132         ofstream error_log;
00133         OBJECTMODEL * model_list;
00134         void delmodel();
00135 
00136         OBJECTNODE * object_list;
00137         void delobject();
00138 
00139         void DrawObject(OBJECTNODE * object);
00140 
00141         OBJECTMODEL * AddModel(string modelname, string texname, bool mip, bool fullbright, bool skybox, bool blend, JOEPACK * pack);
00142 
00143         string path;
00144 
00145         OBJECTCOLLISION collision;
00146 
00147         map <string, TEXTURE_HANDLE> texture_db;
00148 
00149         void GroupObjectListByTexture();
00150 
00151         TEXTURE_HANDLE sphere_reflection;
00152         bool sphere_reflection_loaded;
00153         
00154 public:
00155         OBJECTS();
00156         ~OBJECTS();
00157         void Draw(bool cull);
00158         void UpdateSettings();
00159         OBJECTNODE * Add(VERTEX pos, float rotation, string modelname, string texname, bool mip, bool fullbright, bool skybox, bool drv, bool col, bool blend, JOEPACK * pack, float f1, float f2, float bl, float bm, float rr, float rd);
00160         void DeleteAll();
00161 
00162         bool Collide(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest, VERTEX & normal, float seglen, OBJECTNODE * &colnode);
00163         bool CollideD(VERTEXD origin, VERTEXD direction, VERTEXD &outtri, bool closest, VERTEXD & normal, double seglen);
00164         bool CollideDriveable(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest, VERTEX & normal);
00165         //bool Collide(VERTEX origin, VERTEX direction, VERTEX &outtri, bool closest, OBJECTNODE * &collideobject);
00166 
00167         bool CollideModel(VERTEX * modelverts, int numfaces, AABB bbox, VERTEX & outtri, bool closest, VERTEX & normal, float & depth);
00168 
00169         void LoadObjectsFromFolder(string objectpath);
00170         bool GetCollideAndDriveTogether() {return COLLIDE_AND_DRIVE_TOGETHER;}
00171         
00172         void GetTrisInBBox(AABB bbox, list <OBJECTTRI> & trilist);
00173 };
00174 
00175 #define _OBJECTS_H
00176 #endif

Generated on Thu Oct 19 04:05:47 2006 by  doxygen 1.4.6