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