1 | /* |
---|
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 |
---|
13 | */ |
---|
14 | |
---|
15 | class SDL_Surface; |
---|
16 | class BspTreeNode; |
---|
17 | class Vector; |
---|
18 | class Material; |
---|
19 | class VertexArrayModel; |
---|
20 | |
---|
21 | typedef struct |
---|
22 | { |
---|
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 |
---|
27 | } |
---|
28 | plane; |
---|
29 | |
---|
30 | typedef struct |
---|
31 | { |
---|
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 |
---|
38 | } |
---|
39 | model; |
---|
40 | |
---|
41 | typedef struct |
---|
42 | { |
---|
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. |
---|
48 | } |
---|
49 | node; |
---|
50 | |
---|
51 | typedef struct |
---|
52 | { |
---|
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; |
---|
63 | |
---|
64 | struct brush |
---|
65 | { |
---|
66 | int brushside; //!< First brushside for brush. |
---|
67 | int n_brushsides; //!< Number of brushsides for brush. |
---|
68 | int texture; //!< Texture index. |
---|
69 | }; |
---|
70 | |
---|
71 | typedef struct |
---|
72 | { |
---|
73 | int plane; //!< Plane index. |
---|
74 | int texture; //!< Texture index. |
---|
75 | } |
---|
76 | brushside; |
---|
77 | |
---|
78 | struct face |
---|
79 | { |
---|
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. |
---|
89 | int lm_size [ 2 ]; //!< Size of this face's lightmap image in lightmap. |
---|
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. |
---|
94 | } ; |
---|
95 | |
---|
96 | typedef struct |
---|
97 | { |
---|
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. |
---|
102 | } |
---|
103 | BspVertex; |
---|
104 | |
---|
105 | typedef struct |
---|
106 | { |
---|
107 | int offset; |
---|
108 | } |
---|
109 | meshvert; //!< Integer offset to mesh vertex |
---|
110 | |
---|
111 | typedef struct |
---|
112 | { |
---|
113 | float position [ 3 ]; |
---|
114 | } |
---|
115 | BspVec; |
---|
116 | |
---|
117 | typedef struct |
---|
118 | { |
---|
119 | Material* mat; |
---|
120 | bool alpha; |
---|
121 | } |
---|
122 | AMat; |
---|
123 | |
---|
124 | typedef struct |
---|
125 | { |
---|
126 | unsigned char map [128][128][3]; |
---|
127 | } |
---|
128 | lightmap; |
---|
129 | |
---|
130 | typedef struct |
---|
131 | { |
---|
132 | char name[64]; |
---|
133 | int flags; |
---|
134 | int contents; |
---|
135 | } |
---|
136 | BspTexture; |
---|
137 | |
---|
138 | class BspFile |
---|
139 | { |
---|
140 | friend class BspManager; |
---|
141 | |
---|
142 | public: |
---|
143 | BspFile(); |
---|
144 | int read(const char* name ); |
---|
145 | void build_tree(); |
---|
146 | void load_textures(); |
---|
147 | void tesselate( int iface ); |
---|
148 | BspTreeNode* get_root(); |
---|
149 | AMat loadMat( char* mat ); |
---|
150 | |
---|
151 | |
---|
152 | private: |
---|
153 | BspTreeNode* root; |
---|
154 | char header [ 280 ]; //!< Buffer for header of BSP-File |
---|
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 |
---|
159 | char* leafFaces; //!< Buffer to store leafFaces |
---|
160 | face* faces; //!< |
---|
161 | char* leafBrushes; //!< Buffer to store brush indice |
---|
162 | brush* brushes; //!< Buffer to store brushes |
---|
163 | brushside* brushSides; //!< |
---|
164 | char* vertice; //!< |
---|
165 | meshvert* meshverts; //!< Buffer to store meshverice |
---|
166 | char* visData; //!< Buffer to store visibility data |
---|
167 | char* textures; //!< Holds all the texture filename strings |
---|
168 | char* patchVertice; //!< |
---|
169 | char* patchIndexes; |
---|
170 | char* patchTrianglesPerRow; |
---|
171 | lightmap* lightMaps; //!< Buffer to store lightmap-images |
---|
172 | |
---|
173 | |
---|
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; |
---|
189 | int numLightMaps; |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | BspTreeNode* build_tree_rec( int i ); |
---|
194 | unsigned int loadLightMapToGL(lightmap&); |
---|
195 | AMat* Materials; |
---|
196 | unsigned int* glLightMapTextures; |
---|
197 | unsigned int whiteLightMap; |
---|
198 | unsigned char whiteTexture[3]; |
---|
199 | SDL_Surface* testSurf; |
---|
200 | |
---|
201 | }; |
---|
202 | |
---|