Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/water/src/lib/graphics/importer/bsp_file.h @ 8314

Last change on this file since 8314 was 8186, checked in by bensch, 19 years ago

trunk: merged the branche bsp_model back here

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