Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/importer/bsp_file.h @ 8697

Last change on this file since 8697 was 8490, checked in by patrick, 19 years ago

merged the bsp branche back to trunk

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