[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 | { |
---|
| 23 | float x; |
---|
| 24 | float y; |
---|
| 25 | float z; |
---|
[7385] | 26 | float d; |
---|
| 27 | } |
---|
| 28 | plane; |
---|
[7353] | 29 | |
---|
| 30 | typedef struct |
---|
| 31 | { |
---|
[7385] | 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; // |
---|
| 38 | } |
---|
| 39 | model; |
---|
[7353] | 40 | |
---|
| 41 | typedef struct |
---|
| 42 | { |
---|
[7385] | 43 | int plane; //Plane index. |
---|
| 44 | int left; //Children indices. Negative numbers are leaf indices: -(leaf+1). |
---|
| 45 | int right; |
---|
| 46 | int mins[ 3 ]; //Integer bounding box min coord. |
---|
| 47 | int maxs[ 3 ]; //Integer bounding box max coord. |
---|
| 48 | } |
---|
| 49 | node; |
---|
[7353] | 50 | |
---|
| 51 | typedef struct |
---|
| 52 | { |
---|
[7385] | 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. |
---|
| 61 | } |
---|
| 62 | leaf; |
---|
[7353] | 63 | |
---|
| 64 | typedef struct |
---|
| 65 | { |
---|
[7385] | 66 | int brushside; //First brushside for brush. |
---|
| 67 | int n_brushsides; //Number of brushsides for brush. |
---|
| 68 | int texture; //Texture index. |
---|
| 69 | } |
---|
| 70 | brush; |
---|
[7353] | 71 | |
---|
| 72 | typedef struct |
---|
| 73 | { |
---|
[7385] | 74 | int plane; //Plane index. |
---|
| 75 | int texture; //Texture index. |
---|
| 76 | } |
---|
| 77 | brushside; |
---|
[7353] | 78 | |
---|
[7385] | 79 | struct face |
---|
[7353] | 80 | { |
---|
[7385] | 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. |
---|
| 90 | int lm_size[ 2 ]; // Size of this face's lightmap image in lightmap. |
---|
| 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 | { |
---|
[7385] | 99 | float position[ 3 ]; // Vertex position. |
---|
| 100 | float texcoord[ 2 ][ 2 ]; // Vertex texture coordinates. 0=surface, 1=lightmap. |
---|
| 101 | float normal[ 3 ]; // Vertex normal. |
---|
| 102 | unsigned char color [ 4 ]; // Vertex color. RGBA. |
---|
| 103 | } |
---|
| 104 | BspVertex; |
---|
[7353] | 105 | |
---|
| 106 | typedef struct |
---|
| 107 | { |
---|
[7385] | 108 | int offset; |
---|
| 109 | } |
---|
| 110 | meshvert; |
---|
[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; |
---|
| 121 | bool alpha; |
---|
| 122 | } |
---|
| 123 | AMat; |
---|
[7353] | 124 | |
---|
[7385] | 125 | class BspFile |
---|
| 126 | { |
---|
| 127 | friend class BspManager; |
---|
[7353] | 128 | |
---|
[7385] | 129 | public: |
---|
| 130 | BspFile(); |
---|
| 131 | int read( char* name ); |
---|
| 132 | void build_tree(); |
---|
| 133 | void load_textures(); |
---|
| 134 | void tesselate( int iface ); |
---|
| 135 | BspTreeNode* get_root(); |
---|
| 136 | AMat loadMat( char* mat ); |
---|
[7353] | 137 | |
---|
| 138 | |
---|
[7385] | 139 | private: |
---|
| 140 | BspTreeNode* root; |
---|
| 141 | char header [ 280 ]; //!< Buffer for header of BSP-File |
---|
| 142 | char* nodes; //!< Buffer to store BSP-Tree-Nodes |
---|
| 143 | char* leaves; //!< Buffer to store BSP-Tree-Leaves |
---|
| 144 | char* planes; //!< Buffer to store planes separateing the space |
---|
| 145 | char* bspModels; //!< Buffer to store BSP-Model-List |
---|
| 146 | char* leafFaces; //!< Buffer to store leafFaces |
---|
| 147 | char* faces; //!< |
---|
| 148 | char* leafBrushes; //!< Buffer to store brush indice |
---|
| 149 | char* brushes; //!< Buffer to store brushes |
---|
| 150 | char* brushSides; //!< |
---|
| 151 | char* vertice; //!< |
---|
| 152 | char* meshverts; //!< |
---|
| 153 | char* visData; //!< |
---|
| 154 | char* textures; //!< |
---|
[7353] | 155 | |
---|
[7385] | 156 | |
---|
| 157 | char* patchVertice; |
---|
| 158 | char* patchIndexes; |
---|
| 159 | char* patchTrianglesPerRow; |
---|
| 160 | int** patchRowIndexes; |
---|
| 161 | VertexArrayModel** VertexArrayModels; |
---|
| 162 | int patchOffset; |
---|
| 163 | |
---|
| 164 | int numNodes; |
---|
| 165 | int numLeafs; |
---|
| 166 | int numVertex; |
---|
| 167 | int numPlanes; |
---|
| 168 | int numBspModels; |
---|
| 169 | int numLeafFaces; |
---|
| 170 | int numFaces; |
---|
| 171 | int numLeafBrushes; |
---|
| 172 | int numTextures; |
---|
| 173 | int numPatches; |
---|
| 174 | int numBrushSides; |
---|
| 175 | |
---|
| 176 | BspTreeNode* build_tree_rec( int i ); |
---|
| 177 | AMat* Materials; |
---|
| 178 | SDL_Surface* testSurf; |
---|
| 179 | |
---|
[7353] | 180 | }; |
---|
| 181 | |
---|