1 | /*! |
---|
2 | * @file bv_tree.h |
---|
3 | * Definition of a bounding volume tree |
---|
4 | |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef _OBB_TREE_NODE_H |
---|
8 | #define _OBB_TREE_NODE_H |
---|
9 | |
---|
10 | #include "glincl.h" |
---|
11 | #include "bv_tree_node.h" |
---|
12 | |
---|
13 | |
---|
14 | |
---|
15 | // FORWARD DECLARATION |
---|
16 | class BoundingVolume; |
---|
17 | class OBB; |
---|
18 | class OBBTree; |
---|
19 | class Plane; |
---|
20 | class PNode; |
---|
21 | //struct sVec3D; |
---|
22 | |
---|
23 | //! A class that represents a bounding volume tree |
---|
24 | class OBBTreeNode : public BVTreeNode { |
---|
25 | |
---|
26 | |
---|
27 | public: |
---|
28 | OBBTreeNode(); |
---|
29 | virtual ~OBBTreeNode(); |
---|
30 | |
---|
31 | virtual void spawnBVTree(const int depth, sVec3D *verticesList, const int length); |
---|
32 | |
---|
33 | BoundingVolume* getBV(int index) const { return (BoundingVolume*)this->bvElement; } |
---|
34 | inline const int getIndex() { return this->treeIndex; } |
---|
35 | inline void setTreeRef(OBBTree* tree) { this->obbTree = tree;} |
---|
36 | |
---|
37 | virtual void collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB); |
---|
38 | |
---|
39 | virtual void drawBV(int depth, int drawMode); |
---|
40 | |
---|
41 | void debug() const; |
---|
42 | |
---|
43 | private: |
---|
44 | void calculateBoxCovariance(OBB* box, sVec3D* verticesList, int length); |
---|
45 | void calculateBoxEigenvectors(OBB* box, sVec3D* verticesList, int length); |
---|
46 | void calculateBoxAxis(OBB* box, sVec3D* verticesList, int length); |
---|
47 | void forkBox(OBB* box); |
---|
48 | |
---|
49 | bool overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB); |
---|
50 | |
---|
51 | protected: |
---|
52 | OBB* bvElement; //!< the obb element |
---|
53 | OBBTreeNode* nodeLeft; //!< ref to the left tree node |
---|
54 | OBBTreeNode* nodeRight; //!< ref to the right tree node |
---|
55 | |
---|
56 | private: |
---|
57 | unsigned int treeIndex; //!< Index number of the BV in the tree |
---|
58 | sVec3D* vertices; //!< pointer to the vertices data |
---|
59 | int numOfVertices; //!< number of vertices in vertices data |
---|
60 | int depth; //!< the depth of the node in the tree |
---|
61 | static OBBTree* obbTree; //!< reference to the obb tree |
---|
62 | Plane* separationPlane; //!< the separation plane of the obb |
---|
63 | sVec3D* sepPlaneCenter; //!< only needed to draw plane @todo: separationPlane drawing |
---|
64 | int longestAxisIndex; //!< only needed to draw plane |
---|
65 | |
---|
66 | /* tmp saving place for obb variables */ |
---|
67 | sVec3D* tmpVert1; //!< pointer to the vert data of obbox1 |
---|
68 | sVec3D* tmpVert2; //!< pointer to the vert data of obbox1 |
---|
69 | int tmpLen1; //!< len vert data obbox1 |
---|
70 | int tmpLen2; //!< len vert data obbox2 |
---|
71 | |
---|
72 | static float** coMat; //!< temp covariance matrice save place - consumes less mem |
---|
73 | static float** eigvMat; //!< temp eigenvector matrice save place |
---|
74 | static float* eigvlMat; //!< temp eigenvalue vector save place |
---|
75 | static int* rotCount; //!< temp rotations count save place: how many givens-rotations where needed to transform the matrix :) |
---|
76 | |
---|
77 | GLUquadricObj* sphereObj; |
---|
78 | }; |
---|
79 | |
---|
80 | #endif /* _OBB_TREE_NODE_H */ |
---|