1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
|
//-----------------------------------------------------------------------------
// BSPLIB HEADER: BspObject.h
//
// Copyright (c) 1996-1998 by Markus Hadwiger
// All Rights Reserved.
//-----------------------------------------------------------------------------
#ifndef _BSPOBJECT_H_
#define _BSPOBJECT_H_
// bsplib header files
#include "BspLibDefs.h"
#include "SystemIO.h"
#include "Chunk.h"
#include "Face.h"
#include "Mapping.h"
#include "PolygonList.h"
#include "BSPTree.h"
#include "Texture.h"
#include "Transform3.h"
#include "Vertex.h"
BSPLIB_NAMESPACE_BEGIN
class BoundingBox;
// base class for BspObject providing data members ----------------------------
//
class BspObjectInfo {
friend class BspObject;
private:
BspObjectInfo();
~BspObjectInfo() { }
public:
int getNumVertices() const { return numvertices; }
int getNumPolygons() const { return numpolygons; }
int getNumFaces() const { return numfaces; }
int getInputVertices() const { return numvertices_in; }
int getInputPolygons() const { return numpolygons_in; }
int getInputFaces() const { return numfaces_in; }
int getBspPolygons() const { return numbsppolygons; }
int getPreBspPolygons() const { return numpolygons_before_bsp; }
int getNumTextures() const { return numtextures; }
int getNumMappings() const { return numcorrespondences; }
int getNumNormals() const { return numnormals; }
int getNumTexturedFaces() const { return numtexmappedfaces; }
int getNumTraceVertices() const { return numtracevertices; }
int getNumMultiVertices() const { return nummultvertices; }
int getNumSplitQuads() const { return numsplitquadrilaterals; }
protected:
int numvertices; // number of vertices in vertexlist
int numpolygons; // number of polygons in polygonlist
int numfaces; // number of faces in facelist
int numtextures; // number of textures in texturelist
int numcorrespondences; // number of correspondences in mappinglist
int numnormals; // number of faces with valid normals
int numtexmappedfaces; // number of texture mapped faces
int numvertices_in; // copy of numvertices directly after parse
int numpolygons_in; // copy of numpolygons directly after parse
int numfaces_in; // copy of numfaces directly after parse
int numbsppolygons; // number of polygons contained in bsp tree
int numpolygons_before_bsp; // copy of numpolygons before start of bsp compilation
int numtracevertices; // number of vertices for edge tracing
int nummultvertices; // number of multiply contained vertices
int numsplitquadrilaterals; // number of quadrilaterals split into triangles
};
// class describing a generic 3-D object in BspLib ----------------------------
//
class BspObject : public BspObjectInfo, public virtual SystemIO {
friend class BoundingBox;
friend class BspObjectListRep;
friend class Face;
friend class ObjectBSPNode;
friend class Polygon;
friend class VrmlFile;
public:
BspObject();
~BspObject() { delete objectname; delete next; }
BspObject( const BspObject& copyobj );
BspObject& operator =( const BspObject& copyobj );
// merge another BspObject into this object. this renumbers the other
// object's vertices, faces, polygons, and vertexindexes in polygons
void MergeObjects( BspObject *mergeobj );
void CollapseObjectList(); // collapse entire list into this object
BoundingBox* BuildBoundingBoxList(); // build a list of bounding boxes
BSPNode* BuildBSPTree(); // build bsp tree from polygon list
BSPNode* BuildBSPTreeFromFlat(); // build bsp tree from flat representation
int BspTreeAvailable(); // any bsp tree available?
int BSPTreeAvailable(); // linked bsp tree available?
int BSPTreeFlatAvailable(); // flat bsp tree available?
// processing functions (typically passed through to primitives)
void CalcBoundingBoxes(); // operates on bsp tree only
void CalcSeparatorPlanes(); // operates on bsp tree only
void CheckEdges(); // operates on bsp tree only
void CheckPolygonPlanes(); // operates on polygon list only
void CheckVertices( int verbose ); // scans entire vertex list
void CalcPlaneNormals(); // operates on polygon list only
void CheckParsedData(); // some consistency checks
void UpdateAttributeNumbers(); // calc length of lists
int ConvertColorIndexesToRGB( char *palette, int changemode );
// return bounding box extents for this object
void CalcBoundingBox( Vertex3& minvertex, Vertex3& maxvertex );
// display some object statistics
void DisplayStatistics();
// ASCII output functions that have to be implemented by
// derived ObjectXXXFormat classes.
// must not be pure virtual!
virtual int WriteVertexList( FileAccess& fp ) { return FALSE; }
virtual int WritePolygonList( FileAccess& fp ) { return FALSE; }
virtual int WriteFaceList( FileAccess& fp ) { return FALSE; }
virtual int WriteFaceProperties( FileAccess& fp ) { return FALSE; }
virtual int WriteTextureList( FileAccess& fp ) { return FALSE; }
virtual int WriteMappingList( FileAccess& fp ) { return FALSE; }
virtual int WriteNormals( FileAccess& fp ) { return FALSE; }
virtual int WriteBSPTree( FileAccess& fp ) { return FALSE; }
// return contained objects
VertexChunk& getVertexList() { return vertexlist; }
PolygonList& getPolygonList() { return polygonlist; }
FaceChunk& getFaceList() { return facelist; }
TextureChunk& getTextureList() { return texturelist; }
MappingChunk& getMappingList() { return mappinglist; }
BSPTree& getBSPTree() { return bsptree; }
BSPTreeFlat& getBSPTreeFlat() { return bsptreeflat; }
// get/set object's name-string
char* getObjectName() const { return objectname; }
void setObjectName( char *name );
// get/set object's local transformation
Vertex3 getCenterInWorldSpace() const { return objecttrafo.FetchTranslation(); }
Transform3 getObjectTransformation() const { return objecttrafo; }
void setObjectTransformation( const Transform3& ot ) { objecttrafo = ot; }
// scale entire object (all vertices)
void ApplyScale( double scalefac );
// apply translation to all coordinates and set center to (0,0,0)
void ApplyCenter();
// apply transformation matrix and set to identity afterwards
void ApplyTransformation();
// return next object in list
BspObject* getNext() const { return next; }
private:
void InconsistencyError( const char *err );
public:
static int getEliminateDoubletsOnMergeFlag() { return check_vertex_doublets_on_merge; }
static void setEliminateDoubletsOnMergeFlag( int flag ) { check_vertex_doublets_on_merge = flag; }
private:
static int check_vertex_doublets_on_merge;
protected:
// contained objects
VertexChunk vertexlist; // list of vertices
PolygonList polygonlist; // list of polygons
FaceChunk facelist; // list of faces
TextureChunk texturelist; // list of textures
MappingChunk mappinglist; // list of mappings
BSPTree bsptree; // linked bsp tree
BSPTreeFlat bsptreeflat; // flat bsp tree
Transform3 objecttrafo; // attached transformation
// object's name if any defined
char* objectname;
// pointer to next object in list
BspObject* next;
};
// copy constructor -----------------------------------------------------------
inline BspObject::BspObject( const BspObject& copyobj ) :
BspObjectInfo( copyobj ),
vertexlist( copyobj.vertexlist ),
polygonlist( copyobj.polygonlist ),
facelist( copyobj.facelist ),
texturelist( copyobj.texturelist ),
mappinglist( copyobj.mappinglist ),
bsptree( copyobj.bsptree ),
bsptreeflat( copyobj.bsptreeflat ),
objecttrafo( copyobj.objecttrafo )
{
// copy object's name
objectname = NULL;
setObjectName( copyobj.objectname );
// unlink tail of list
next = NULL;
}
// assignment operator --------------------------------------------------------
inline BspObject& BspObject::operator =( const BspObject& copyobj )
{
if ( ©obj != this ) {
// copy info part
*(BspObjectInfo *)this = copyobj;
// copy contained objects
vertexlist = copyobj.vertexlist;
polygonlist = copyobj.polygonlist;
facelist = copyobj.facelist;
texturelist = copyobj.texturelist;
mappinglist = copyobj.mappinglist;
bsptree = copyobj.bsptree;
bsptreeflat = copyobj.bsptreeflat;
objecttrafo = copyobj.objecttrafo;
// copy object's name
setObjectName( copyobj.objectname );
// unlink tail of list
next = NULL;
}
return *this;
}
BSPLIB_NAMESPACE_END
#endif // _BSPOBJECT_H_
|