[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 |
---|
[7353] | 13 | */ |
---|
| 14 | |
---|
[7385] | 15 | class SDL_Surface; |
---|
[7353] | 16 | class BspTreeNode; |
---|
| 17 | class Vector; |
---|
| 18 | class Material; |
---|
| 19 | class VertexArrayModel; |
---|
| 20 | |
---|
[7385] | 21 | typedef struct |
---|
[7353] | 22 | { |
---|
[7395] | 23 | float x; //!< 1st component of the plane's normal |
---|
| 24 | float y; //!< 2nd component of the plane's normal |
---|
| 25 | float z; //!< 3rd component of the plane's normal |
---|
| 26 | float d; //!< distance of the plane to the origin |
---|
[7385] | 27 | } |
---|
| 28 | plane; |
---|
[7353] | 29 | |
---|
| 30 | typedef struct |
---|
| 31 | { |
---|
[7395] | 32 | float mins [ 3 ]; //!< Bounding box min coord. |
---|
| 33 | float maxs [ 3 ]; //!< Bounding box max coord. |
---|
| 34 | int face; //!< First face for model. |
---|
| 35 | int n_faces; //!< Number of faces for model. |
---|
| 36 | int brush; //!< First brush for model. |
---|
| 37 | int n_brushes; //!< Number of brushes |
---|
[7385] | 38 | } |
---|
| 39 | model; |
---|
[7353] | 40 | |
---|
| 41 | typedef struct |
---|
| 42 | { |
---|
[7395] | 43 | int plane; //!< Plane index. |
---|
| 44 | int left; //!< 1st Child index. Negative numbers are leaf indices: -(leaf+1). |
---|
| 45 | int right; //!< 2nd Child index. Negative numbers are leaf indices: -(leaf+1). |
---|
| 46 | int mins[ 3 ]; //!< Integer bounding box min coord. |
---|
| 47 | int maxs[ 3 ]; //!< Integer bounding box max coord. |
---|
[7385] | 48 | } |
---|
| 49 | node; |
---|
[7353] | 50 | |
---|
| 51 | typedef struct |
---|
| 52 | { |
---|
[7395] | 53 | int cluster; //!< Visdata cluster index. |
---|
| 54 | int area; //!< Areaportal area. |
---|
| 55 | int mins[ 3 ]; //!< Integer bounding box min coord. |
---|
| 56 | int maxs[ 3 ]; //!< Integer bounding box max coord. |
---|
| 57 | int leafface; //!< First leafface for leaf. |
---|
| 58 | int n_leaffaces; //!< Number of leaffaces for leaf. |
---|
| 59 | int leafbrush_first; //!< leafbrush for leaf. |
---|
| 60 | int n_leafbrushes; //!< Number of leafbrushes for leaf. |
---|
[7385] | 61 | } |
---|
| 62 | leaf; |
---|
[7353] | 63 | |
---|
[7563] | 64 | struct brush |
---|
[7353] | 65 | { |
---|
[7395] | 66 | int brushside; //!< First brushside for brush. |
---|
| 67 | int n_brushsides; //!< Number of brushsides for brush. |
---|
| 68 | int texture; //!< Texture index. |
---|
[7563] | 69 | }; |
---|
[7353] | 70 | |
---|
| 71 | typedef struct |
---|
| 72 | { |
---|
[7395] | 73 | int plane; //!< Plane index. |
---|
| 74 | int texture; //!< Texture index. |
---|
[7385] | 75 | } |
---|
| 76 | brushside; |
---|
[7353] | 77 | |
---|
[7385] | 78 | struct face |
---|
[7353] | 79 | { |
---|
[7395] | 80 | int texture; //!< Texture index. |
---|
| 81 | int effect; //!< Index into lump 12 (Effects), or -1. |
---|
| 82 | int type; //!< Face type. 1=polygon, 2=patch, 3=mesh, 4=billboard |
---|
| 83 | int vertex; //!< Index of first vertex. |
---|
| 84 | int n_vertexes; //!< Number of vertices. |
---|
| 85 | int meshvert; //!< Index of first meshvert. |
---|
| 86 | int n_meshverts; //!< Number of meshverts. |
---|
| 87 | int lm_index; //!< Lightmap index. |
---|
| 88 | int lm_start [ 2 ]; //!< Corner of this face's lightmap image in lightmap. |
---|
[7465] | 89 | int lm_size [ 2 ]; //!< Size of this face's lightmap image in lightmap. |
---|
[7395] | 90 | float lm_origin [ 3 ] ; //!< World space origin of lightmap. |
---|
| 91 | float lm_vecs [ 2 ][ 3 ]; //!< World space lightmap s and t unit vectors. |
---|
| 92 | float normal[ 3 ]; //!< Surface normal. |
---|
| 93 | int size [ 2 ] ; //!< Patch dimensions. |
---|
[7353] | 94 | } ; |
---|
| 95 | |
---|
| 96 | typedef struct |
---|
| 97 | { |
---|
[7395] | 98 | float position[ 3 ]; //!< Vertex position. |
---|
| 99 | float texcoord[ 2 ][ 2 ]; //!< Vertex texture coordinates. [0][x]=surface, [1][x]=lightmap. |
---|
| 100 | float normal[ 3 ]; //!< Vertex normal. |
---|
| 101 | unsigned char color [ 4 ]; //!< Vertex color. RGBA. |
---|
[7385] | 102 | } |
---|
| 103 | BspVertex; |
---|
[7353] | 104 | |
---|
| 105 | typedef struct |
---|
| 106 | { |
---|
[7385] | 107 | int offset; |
---|
| 108 | } |
---|
[7395] | 109 | meshvert; //!< Integer offset to mesh vertex |
---|
[7353] | 110 | |
---|
[7385] | 111 | typedef struct |
---|
[7353] | 112 | { |
---|
[7385] | 113 | float position [ 3 ]; |
---|
| 114 | } |
---|
| 115 | BspVec; |
---|
[7353] | 116 | |
---|
[7385] | 117 | typedef struct |
---|
[7353] | 118 | { |
---|
[7385] | 119 | Material* mat; |
---|
| 120 | bool alpha; |
---|
| 121 | } |
---|
| 122 | AMat; |
---|
[7353] | 123 | |
---|
[7465] | 124 | typedef struct |
---|
| 125 | { |
---|
| 126 | unsigned char map [128][128][3]; |
---|
| 127 | } |
---|
| 128 | lightmap; |
---|
| 129 | |
---|
[7563] | 130 | typedef struct |
---|
| 131 | { |
---|
| 132 | char name[64]; |
---|
| 133 | int flags; |
---|
| 134 | int contents; |
---|
| 135 | } |
---|
| 136 | BspTexture; |
---|
| 137 | |
---|
[7385] | 138 | class BspFile |
---|
| 139 | { |
---|
| 140 | friend class BspManager; |
---|
[7353] | 141 | |
---|
[7385] | 142 | public: |
---|
| 143 | BspFile(); |
---|
[7596] | 144 | int read(const char* name ); |
---|
[7385] | 145 | void build_tree(); |
---|
| 146 | void load_textures(); |
---|
| 147 | void tesselate( int iface ); |
---|
| 148 | BspTreeNode* get_root(); |
---|
| 149 | AMat loadMat( char* mat ); |
---|
[7353] | 150 | |
---|
| 151 | |
---|
[7385] | 152 | private: |
---|
| 153 | BspTreeNode* root; |
---|
| 154 | char header [ 280 ]; //!< Buffer for header of BSP-File |
---|
[7395] | 155 | node* nodes; //!< Buffer to store BSP-Tree-Nodes |
---|
| 156 | leaf* leaves; //!< Buffer to store BSP-Tree-Leaves |
---|
| 157 | plane* planes; //!< Buffer to store planes separateing the space |
---|
| 158 | model* bspModels; //!< Buffer to store BSP-Model-List |
---|
[7385] | 159 | char* leafFaces; //!< Buffer to store leafFaces |
---|
[7395] | 160 | face* faces; //!< |
---|
[7385] | 161 | char* leafBrushes; //!< Buffer to store brush indice |
---|
[7410] | 162 | brush* brushes; //!< Buffer to store brushes |
---|
[7507] | 163 | brushside* brushSides; //!< |
---|
[7385] | 164 | char* vertice; //!< |
---|
[7511] | 165 | meshvert* meshverts; //!< Buffer to store meshverice |
---|
| 166 | char* visData; //!< Buffer to store visibility data |
---|
| 167 | char* textures; //!< Holds all the texture filename strings |
---|
[7465] | 168 | char* patchVertice; //!< |
---|
[7385] | 169 | char* patchIndexes; |
---|
| 170 | char* patchTrianglesPerRow; |
---|
[7465] | 171 | lightmap* lightMaps; //!< Buffer to store lightmap-images |
---|
| 172 | |
---|
| 173 | |
---|
[7385] | 174 | int** patchRowIndexes; |
---|
| 175 | VertexArrayModel** VertexArrayModels; |
---|
| 176 | int patchOffset; |
---|
| 177 | |
---|
| 178 | int numNodes; |
---|
| 179 | int numLeafs; |
---|
| 180 | int numVertex; |
---|
| 181 | int numPlanes; |
---|
| 182 | int numBspModels; |
---|
| 183 | int numLeafFaces; |
---|
| 184 | int numFaces; |
---|
| 185 | int numLeafBrushes; |
---|
| 186 | int numTextures; |
---|
| 187 | int numPatches; |
---|
| 188 | int numBrushSides; |
---|
[7465] | 189 | int numLightMaps; |
---|
[7385] | 190 | |
---|
[7563] | 191 | |
---|
| 192 | |
---|
[7385] | 193 | BspTreeNode* build_tree_rec( int i ); |
---|
[7465] | 194 | unsigned int loadLightMapToGL(lightmap&); |
---|
[7385] | 195 | AMat* Materials; |
---|
[7465] | 196 | unsigned int* glLightMapTextures; |
---|
| 197 | unsigned int whiteLightMap; |
---|
| 198 | unsigned char whiteTexture[3]; |
---|
[7385] | 199 | SDL_Surface* testSurf; |
---|
| 200 | |
---|
[7353] | 201 | }; |
---|
| 202 | |
---|