Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 10643 was 10033, checked in by patrick, 17 years ago

moved some of the importer sources, probably will need to rebuild the project

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  ~BspFile();
154  int read(const char* name );
155  void build_tree();
156  void load_textures();
157  void tesselate( int iface );
158  BspTreeNode* get_root();
159  AMat loadMat( char* mat );
160  AMat loadAVI(char * mat);
161 
162
163private:
164  BspTreeNode* root;
165  char header [ 280 ];       //!< Buffer for header of BSP-File
166  node* nodes;               //!< Buffer to store BSP-Tree-Nodes
167  leaf* leaves;              //!< Buffer to store BSP-Tree-Leaves
168  plane* planes;             //!< Buffer to store planes separateing the space
169  model* bspModels;          //!< Buffer to store BSP-Model-List
170  char* leafFaces;           //!< Buffer to store leafFaces
171  face* faces;               //!<
172  char* leafBrushes;         //!< Buffer to store brush indice
173  brush* brushes;            //!< Buffer to store  brushes
174  brushside* brushSides;     //!<
175  char* vertice;             //!<
176  meshvert* meshverts;       //!< Buffer to store meshverice
177  char* visData;             //!< Buffer to store visibility data
178  char* textures;            //!< Holds all the texture filename strings
179  char* patchVertice;        //!<
180  char* patchIndexes;
181  char* patchTrianglesPerRow;
182  lightmap* lightMaps;       //!< Buffer to store lightmap-images
183
184
185  int** patchRowIndexes;
186  VertexArrayModel** VertexArrayModels; 
187  int patchOffset;
188
189  int numNodes;
190  int numLeafs;
191  int numVertex;
192  int numPlanes;
193  int numBspModels;
194  int numLeafFaces;
195  int numFaces;
196  int numLeafBrushes;
197  int numTextures;
198  int numPatches;
199  int numBrushSides;
200  int numLightMaps;
201 
202  float  scale;
203
204  BspTreeNode* build_tree_rec( int i );
205  unsigned int loadLightMapToGL(lightmap&);
206  AMat* Materials;
207  unsigned int* glLightMapTextures;
208  unsigned int whiteLightMap;
209  unsigned char whiteTexture[3];
210  void swapAllBspCoordinates();
211  void swapCoords(int * array);
212  void swapCoords(float * array);
213  SDL_Surface* testSurf;
214
215 
216  ::std::vector<MoviePlayer* > MovieMaterials; //!< Movieplayer Materials
217};
218
Note: See TracBrowser for help on using the repository browser.