aboutsummaryrefslogtreecommitdiff
path: root/tool_src/BspLib/BSPNode.h
blob: 0dba2efde9ba01271ed72761f2ab010298ffa244 (plain)
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
//-----------------------------------------------------------------------------
//	BSPLIB HEADER: BSPNode.h
//
//  Copyright (c) 1996-1998 by Markus Hadwiger
//  All Rights Reserved.
//-----------------------------------------------------------------------------

#ifndef _BSPNODE_H_
#define _BSPNODE_H_

// bsplib header files
#include "BspLibDefs.h"
#include "PolygonList.h"
#include "Plane.h"


BSPLIB_NAMESPACE_BEGIN


class BoundingBox;
class BspObject;


// node of bsp tree -----------------------------------------------------------
//
class BSPNode {

public:

	// output formats
	enum {
		OUTPUT_OLD_STYLE,
		OUTPUT_KEY_VALUE_STYLE
	};

public:
	BSPNode( BSPNode *front = NULL, BSPNode *back = NULL,
			 Polygon *poly = NULL, Polygon *backpoly = NULL,
			 Plane *sep = NULL, BoundingBox *box = NULL, int num = -1 );
	~BSPNode();

public:
	void		NumberBSPNodes( int& curno );
	void		SumVertexNums( int& vtxnum );
	void		CorrectPolygonBases( BspObject *newbaseobj, int vertexindxbase, int faceidbase, int polygonidbase );
	void		CorrectPolygonBasesByTable( BspObject *newbaseobj, int *vtxindxmap, int faceidbase, int polygonidbase );
	void		WriteBSPTree( FILE *fp );
	void		CheckEdges();
	void		FetchFacePolygons( int facno, PolygonList& facepolylist );
	Polygon*	FetchBSPPolygon( int polyno );
	void		CalcBoundingBoxes();
	void		CalcSeparatorPlanes();

	int			getNodeNumber() const { return nodenumber; }
	Polygon*	getPolygon() { return polygon; }
	Polygon*	getBackPolygon() { return backpolygon; }
	BSPNode*	getFrontSubtree() const { return frontsubtree; }
	BSPNode*	getBackSubtree() const { return backsubtree; }

	Plane*		getSeparatorPlane() { return separatorplane; }
	void		setSeparatorPlane( Plane *sep ) { separatorplane = sep; }

	BoundingBox*getBoundingBox() { return boundingbox; }
	void		setBoundingBox( BoundingBox *box ) { boundingbox = box; }

private:
	void		GrowBoundingBox( BSPNode *othernode );

public:
	static int	getOutputFormat() { return outputformat; }
	static void	setOutputFormat( int format ) { outputformat = format; }

private:
	static int	outputformat;	// format used to write bsp nodes to files

private:
	int			nodenumber;		// node id
	Polygon*	polygon;		// list of frontfacing polygons in splitting plane
	Polygon*	backpolygon;	// list of backfacing polygons in splitting plane
	Plane*		separatorplane;	// plane if node is only separator (no polygons!)
	BoundingBox*boundingbox;	// bounding box containing node and all children
	BSPNode*	frontsubtree;	// tree partitioning front halfspace
	BSPNode*	backsubtree;	// tree partitioning back halfspace
};


// node of flat bsp tree ------------------------------------------------------
//
class BSPNodeFlat {

public:
	BSPNodeFlat( int front = 0, int back = 0,
				 Polygon *poly = NULL, int clist = 0, int blist = 0,
				 Plane *sep = NULL, BoundingBox *box = NULL, int num = -1 );
	~BSPNodeFlat() { /* don't delete polygon, separatorplane, and boundingbox!! */ }

public:
	void		InitNode( int front, int back, Polygon *poly, int clist, int blist,
						  Plane *sep = NULL, BoundingBox *box = NULL, int num = -1 );

	void		ApplyScaleFactor( double sfac );

	int			getNodeNumber() const { return nodenumber; }
	Polygon*	getPolygon() { return polygon; }
	int			getContainedList() const { return containedlistindx; }
	int			getBackList() const { return backlistindx; }
	int			getFrontSubTree() const { return frontsubtreeindx; }
	int			getBackSubTree() const { return backsubtreeindx; }

	Plane*		getSeparatorPlane() { return separatorplane; }
	void		setSeparatorPlane( Plane *sep ) { separatorplane = sep; }

	BoundingBox*getBoundingBox() { return boundingbox; }
	void		setBoundingBox( BoundingBox *box ) { boundingbox = box; }

private:
	int			nodenumber;			// node id (may be different than array index!!)
	Polygon*	polygon;			// this node's polygon
	Plane*		separatorplane;		// plane if node is only separator (no polygons!)
	BoundingBox*boundingbox;		// bounding box containing node and all children
	int			containedlistindx;	// contained frontfacing polygons
	int			backlistindx;		// contained backfacing polygons
	int			frontsubtreeindx;	// front subtree
	int			backsubtreeindx;	// back subtree
};


BSPLIB_NAMESPACE_END


#endif // _BSPNODE_H_