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 "bv_tree_node.h" |
---|
11 | |
---|
12 | |
---|
13 | |
---|
14 | // FORWARD DECLARATION |
---|
15 | class BoundingVolume; |
---|
16 | class OBB; |
---|
17 | class OBBTree; |
---|
18 | class Plane; |
---|
19 | class PNode; |
---|
20 | //struct sVec3D; |
---|
21 | |
---|
22 | //! A class that represents a bounding volume tree |
---|
23 | class OBBTreeNode : public BVTreeNode { |
---|
24 | |
---|
25 | |
---|
26 | public: |
---|
27 | OBBTreeNode(const OBBTree& tree, unsigned int depth); |
---|
28 | virtual ~OBBTreeNode(); |
---|
29 | |
---|
30 | /* this function returns the bounding volume of this tree node @return: returns the BV */ |
---|
31 | virtual inline const BoundingVolume* getBV() const { return (BoundingVolume*)this->bvElement; } |
---|
32 | |
---|
33 | virtual void spawnBVTree(const sVec3D *verticesList, unsigned int length); |
---|
34 | virtual void spawnBVTree(const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); |
---|
35 | |
---|
36 | virtual void collideWith(const BVTreeNode& treeNode, const WorldEntity& nodeA, const WorldEntity& nodeB) const; |
---|
37 | virtual void drawBV(int depth, int drawMode, const Vector& color = Vector(1,0,0), bool top = true) const; |
---|
38 | void debug() const; |
---|
39 | |
---|
40 | |
---|
41 | private: |
---|
42 | void calculateBoxEigenvectors(OBB& box, const sVec3D* verticesList, unsigned int length); |
---|
43 | void calculateBoxAxis(OBB& box, const sVec3D* verticesList, unsigned int length); |
---|
44 | |
---|
45 | void calculateBoxCovariance(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); |
---|
46 | void calculateBoxEigenvectors(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); |
---|
47 | void calculateBoxAxis(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); |
---|
48 | void forkBox(OBB& box); |
---|
49 | |
---|
50 | bool overlapTest(const OBB& boxA, const OBB& boxB, const WorldEntity& nodeA, const WorldEntity& nodeB) const; |
---|
51 | |
---|
52 | |
---|
53 | protected: |
---|
54 | OBB* bvElement; //!< the obb element |
---|
55 | OBBTreeNode* nodeLeft; //!< ref to the left tree node |
---|
56 | OBBTreeNode* nodeRight; //!< ref to the right tree node |
---|
57 | |
---|
58 | |
---|
59 | private: |
---|
60 | unsigned int treeIndex; //!< Index number of the BV in the tree |
---|
61 | int depth; //!< the depth of the node in the tree |
---|
62 | const OBBTree* obbTree; //!< reference to the obb tree |
---|
63 | |
---|
64 | const sVec3D* vertices; //!< pointer to the vertices data |
---|
65 | int numOfVertices; //!< number of vertices in vertices data |
---|
66 | Plane separationPlane; //!< the separation plane of the obb |
---|
67 | const sVec3D* sepPlaneCenter; //!< only needed to draw plane |
---|
68 | int longestAxisIndex; //!< only needed to draw plane |
---|
69 | |
---|
70 | /* tmp saving place for obb variables */ |
---|
71 | sVec3D* tmpVert1; //!< pointer to the vert data of obbox1 |
---|
72 | sVec3D* tmpVert2; //!< pointer to the vert data of obbox1 |
---|
73 | int tmpLen1; //!< len vert data obbox1 |
---|
74 | int tmpLen2; //!< len vert data obbox2 |
---|
75 | |
---|
76 | static float** coMat; |
---|
77 | static float** eigvMat; |
---|
78 | static float* eigvlMat; |
---|
79 | static int* rotCount; |
---|
80 | |
---|
81 | }; |
---|
82 | |
---|
83 | #endif /* _OBB_TREE_NODE_H */ |
---|