[7353] | 1 | /* |
---|
[7385] | 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2006 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: bottac@ee.ethz.ch |
---|
[8081] | 13 | |
---|
| 14 | Inspired by: |
---|
| 15 | Rendering Q3 Maps by Morgan McGuire http://graphics.cs.brown.edu/games/quake/quake3.html |
---|
| 16 | Unofficial Quake 3 Map Specs by Kekoa Proudfoot http://graphics.stanford.edu/~kekoa/q3/ |
---|
| 17 | Quake 3 Collision Detection by Nathan Ostgard http://www.devmaster.net/articles/quake3collision/ |
---|
[7353] | 18 | */ |
---|
| 19 | |
---|
[8490] | 20 | #include <vector> |
---|
[9919] | 21 | #include <ode/ode.h> |
---|
| 22 | |
---|
[7385] | 23 | class SDL_Surface; |
---|
[7353] | 24 | class BspTreeNode; |
---|
| 25 | class Vector; |
---|
| 26 | class Material; |
---|
[7801] | 27 | class MoviePlayer; |
---|
[7353] | 28 | class VertexArrayModel; |
---|
| 29 | |
---|
[7801] | 30 | |
---|
[8030] | 31 | struct plane |
---|
[7353] | 32 | { |
---|
[7395] | 33 | float x; //!< 1st component of the plane's normal |
---|
| 34 | float y; //!< 2nd component of the plane's normal |
---|
| 35 | float z; //!< 3rd component of the plane's normal |
---|
| 36 | float d; //!< distance of the plane to the origin |
---|
[8030] | 37 | }; |
---|
[7353] | 38 | |
---|
| 39 | typedef struct |
---|
| 40 | { |
---|
[7395] | 41 | float mins [ 3 ]; //!< Bounding box min coord. |
---|
| 42 | float maxs [ 3 ]; //!< Bounding box max coord. |
---|
| 43 | int face; //!< First face for model. |
---|
| 44 | int n_faces; //!< Number of faces for model. |
---|
| 45 | int brush; //!< First brush for model. |
---|
| 46 | int n_brushes; //!< Number of brushes |
---|
[7385] | 47 | } |
---|
| 48 | model; |
---|
[7353] | 49 | |
---|
| 50 | typedef struct |
---|
| 51 | { |
---|
[7395] | 52 | int plane; //!< Plane index. |
---|
| 53 | int left; //!< 1st Child index. Negative numbers are leaf indices: -(leaf+1). |
---|
| 54 | int right; //!< 2nd Child index. Negative numbers are leaf indices: -(leaf+1). |
---|
| 55 | int mins[ 3 ]; //!< Integer bounding box min coord. |
---|
| 56 | int maxs[ 3 ]; //!< Integer bounding box max coord. |
---|
[7385] | 57 | } |
---|
| 58 | node; |
---|
[7353] | 59 | |
---|
| 60 | typedef struct |
---|
| 61 | { |
---|
[7395] | 62 | int cluster; //!< Visdata cluster index. |
---|
| 63 | int area; //!< Areaportal area. |
---|
| 64 | int mins[ 3 ]; //!< Integer bounding box min coord. |
---|
| 65 | int maxs[ 3 ]; //!< Integer bounding box max coord. |
---|
| 66 | int leafface; //!< First leafface for leaf. |
---|
| 67 | int n_leaffaces; //!< Number of leaffaces for leaf. |
---|
| 68 | int leafbrush_first; //!< leafbrush for leaf. |
---|
| 69 | int n_leafbrushes; //!< Number of leafbrushes for leaf. |
---|
[7385] | 70 | } |
---|
| 71 | leaf; |
---|
[7353] | 72 | |
---|
[7563] | 73 | struct brush |
---|
[7353] | 74 | { |
---|
[7395] | 75 | int brushside; //!< First brushside for brush. |
---|
| 76 | int n_brushsides; //!< Number of brushsides for brush. |
---|
| 77 | int texture; //!< Texture index. |
---|
[7563] | 78 | }; |
---|
[7353] | 79 | |
---|
| 80 | typedef struct |
---|
| 81 | { |
---|
[7395] | 82 | int plane; //!< Plane index. |
---|
| 83 | int texture; //!< Texture index. |
---|
[7385] | 84 | } |
---|
| 85 | brushside; |
---|
[7353] | 86 | |
---|
[7385] | 87 | struct face |
---|
[7353] | 88 | { |
---|
[7395] | 89 | int texture; //!< Texture index. |
---|
[9919] | 90 | int effect; //!< Index into lump #include <ode/ode.h>12 (Effects), or -1. |
---|
[7395] | 91 | int type; //!< Face type. 1=polygon, 2=patch, 3=mesh, 4=billboard |
---|
| 92 | int vertex; //!< Index of first vertex. |
---|
| 93 | int n_vertexes; //!< Number of vertices. |
---|
| 94 | int meshvert; //!< Index of first meshvert. |
---|
| 95 | int n_meshverts; //!< Number of meshverts. |
---|
| 96 | int lm_index; //!< Lightmap index. |
---|
| 97 | int lm_start [ 2 ]; //!< Corner of this face's lightmap image in lightmap. |
---|
[7465] | 98 | int lm_size [ 2 ]; //!< Size of this face's lightmap image in lightmap. |
---|
[7395] | 99 | float lm_origin [ 3 ] ; //!< World space origin of lightmap. |
---|
| 100 | float lm_vecs [ 2 ][ 3 ]; //!< World space lightmap s and t unit vectors. |
---|
| 101 | float normal[ 3 ]; //!< Surface normal. |
---|
| 102 | int size [ 2 ] ; //!< Patch dimensions. |
---|
[7353] | 103 | } ; |
---|
| 104 | |
---|
| 105 | typedef struct |
---|
| 106 | { |
---|
[7395] | 107 | float position[ 3 ]; //!< Vertex position. |
---|
| 108 | float texcoord[ 2 ][ 2 ]; //!< Vertex texture coordinates. [0][x]=surface, [1][x]=lightmap. |
---|
| 109 | float normal[ 3 ]; //!< Vertex normal. |
---|
| 110 | unsigned char color [ 4 ]; //!< Vertex color. RGBA. |
---|
[7385] | 111 | } |
---|
| 112 | BspVertex; |
---|
[7353] | 113 | |
---|
| 114 | typedef struct |
---|
| 115 | { |
---|
[7385] | 116 | int offset; |
---|
| 117 | } |
---|
[7395] | 118 | meshvert; //!< Integer offset to mesh vertex |
---|
[7353] | 119 | |
---|
[7385] | 120 | typedef struct |
---|
[7353] | 121 | { |
---|
[7385] | 122 | float position [ 3 ]; |
---|
| 123 | } |
---|
| 124 | BspVec; |
---|
[7353] | 125 | |
---|
[7385] | 126 | typedef struct |
---|
[7353] | 127 | { |
---|
[7385] | 128 | Material* mat; |
---|
[7801] | 129 | MoviePlayer* aviMat; |
---|
[7385] | 130 | bool alpha; |
---|
[7801] | 131 | bool animated; |
---|
[7385] | 132 | } |
---|
| 133 | AMat; |
---|
[7353] | 134 | |
---|
[7465] | 135 | typedef struct |
---|
| 136 | { |
---|
| 137 | unsigned char map [128][128][3]; |
---|
| 138 | } |
---|
| 139 | lightmap; |
---|
| 140 | |
---|
[7563] | 141 | typedef struct |
---|
| 142 | { |
---|
| 143 | char name[64]; |
---|
| 144 | int flags; |
---|
| 145 | int contents; |
---|
| 146 | } |
---|
| 147 | BspTexture; |
---|
| 148 | |
---|
[7385] | 149 | class BspFile |
---|
| 150 | { |
---|
| 151 | friend class BspManager; |
---|
[7353] | 152 | |
---|
[7385] | 153 | public: |
---|
| 154 | BspFile(); |
---|
[9003] | 155 | ~BspFile(); |
---|
[7596] | 156 | int read(const char* name ); |
---|
[7385] | 157 | void build_tree(); |
---|
| 158 | void load_textures(); |
---|
| 159 | void tesselate( int iface ); |
---|
| 160 | BspTreeNode* get_root(); |
---|
| 161 | AMat loadMat( char* mat ); |
---|
[7801] | 162 | AMat loadAVI(char * mat); |
---|
[9919] | 163 | dTriMeshDataID* getODE_Geometry(void) {return this->ODE_Geometry;} |
---|
[7801] | 164 | |
---|
[7353] | 165 | |
---|
[7385] | 166 | private: |
---|
| 167 | BspTreeNode* root; |
---|
| 168 | char header [ 280 ]; //!< Buffer for header of BSP-File |
---|
[7395] | 169 | node* nodes; //!< Buffer to store BSP-Tree-Nodes |
---|
| 170 | leaf* leaves; //!< Buffer to store BSP-Tree-Leaves |
---|
| 171 | plane* planes; //!< Buffer to store planes separateing the space |
---|
| 172 | model* bspModels; //!< Buffer to store BSP-Model-List |
---|
[7385] | 173 | char* leafFaces; //!< Buffer to store leafFaces |
---|
[7395] | 174 | face* faces; //!< |
---|
[7385] | 175 | char* leafBrushes; //!< Buffer to store brush indice |
---|
[7410] | 176 | brush* brushes; //!< Buffer to store brushes |
---|
[7507] | 177 | brushside* brushSides; //!< |
---|
[7385] | 178 | char* vertice; //!< |
---|
[7511] | 179 | meshvert* meshverts; //!< Buffer to store meshverice |
---|
| 180 | char* visData; //!< Buffer to store visibility data |
---|
| 181 | char* textures; //!< Holds all the texture filename strings |
---|
[7465] | 182 | char* patchVertice; //!< |
---|
[7385] | 183 | char* patchIndexes; |
---|
| 184 | char* patchTrianglesPerRow; |
---|
[7465] | 185 | lightmap* lightMaps; //!< Buffer to store lightmap-images |
---|
| 186 | |
---|
| 187 | |
---|
[7385] | 188 | int** patchRowIndexes; |
---|
[9003] | 189 | VertexArrayModel** VertexArrayModels; |
---|
[7385] | 190 | int patchOffset; |
---|
| 191 | |
---|
| 192 | int numNodes; |
---|
| 193 | int numLeafs; |
---|
| 194 | int numVertex; |
---|
| 195 | int numPlanes; |
---|
| 196 | int numBspModels; |
---|
| 197 | int numLeafFaces; |
---|
| 198 | int numFaces; |
---|
| 199 | int numLeafBrushes; |
---|
| 200 | int numTextures; |
---|
| 201 | int numPatches; |
---|
| 202 | int numBrushSides; |
---|
[7465] | 203 | int numLightMaps; |
---|
[8030] | 204 | |
---|
| 205 | float scale; |
---|
[7385] | 206 | |
---|
| 207 | BspTreeNode* build_tree_rec( int i ); |
---|
[7465] | 208 | unsigned int loadLightMapToGL(lightmap&); |
---|
[7385] | 209 | AMat* Materials; |
---|
[7465] | 210 | unsigned int* glLightMapTextures; |
---|
| 211 | unsigned int whiteLightMap; |
---|
| 212 | unsigned char whiteTexture[3]; |
---|
[7801] | 213 | void swapAllBspCoordinates(); |
---|
| 214 | void swapCoords(int * array); |
---|
| 215 | void swapCoords(float * array); |
---|
[7385] | 216 | SDL_Surface* testSurf; |
---|
| 217 | |
---|
[7801] | 218 | |
---|
[8490] | 219 | ::std::vector<MoviePlayer* > MovieMaterials; //!< Movieplayer Materials |
---|
[9919] | 220 | |
---|
| 221 | dTriMeshDataID* ODE_Geometry; //!< ODE Geometry Data for patches |
---|
| 222 | dGeomID* ODE_Geom_IDs; //!< IDs of ODE Geometry Data |
---|
[7353] | 223 | }; |
---|
| 224 | |
---|