Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/ODE/src/lib/graphics/importer/bsp_file.h @ 10158

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

CrPhysicsFullWalk on Static Models and BSP Patches almost working. libODE≥0.7 required.
Screenshot: http://people.ee.ethz.ch/~bottac/Collision_ODE/

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