Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/bsp_model/src/lib/graphics/importer/bsp_file.h @ 8030

Last change on this file since 8030 was 8030, checked in by bottac, 18 years ago

bsp_manager now knows the normals of the planes into which an obj collided.

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