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 | // forward declarations |
---|
14 | class BoundingVolume; |
---|
15 | class OBB; |
---|
16 | class OBBTree; |
---|
17 | class Plane; |
---|
18 | class PNode; |
---|
19 | |
---|
20 | |
---|
21 | //! A class that represents a bounding volume tree |
---|
22 | class OBBTreeNode : public BVTreeNode |
---|
23 | { |
---|
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 modelInfo& modelInf, const int* triangleIndexes, unsigned int length); |
---|
34 | |
---|
35 | virtual void collideWith(const BVTreeNode& treeNode, const WorldEntity& nodeA, const WorldEntity& nodeB) const; |
---|
36 | virtual void drawBV(int depth, int drawMode, const Vector& color = Vector(1,0,0), bool top = true) const; |
---|
37 | void debug() const; |
---|
38 | |
---|
39 | |
---|
40 | private: |
---|
41 | void calculateBoxAxis(OBB& box, const sVec3D* verticesList, unsigned int length); |
---|
42 | |
---|
43 | void calculateBoxCovariance(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); |
---|
44 | void calculateBoxEigenvectors(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); |
---|
45 | void calculateBoxAxis(OBB& box, const modelInfo& modelInf, const int* triangleIndexes, unsigned int length); |
---|
46 | void forkBox(OBB& box); |
---|
47 | |
---|
48 | bool overlapTest(const OBB& boxA, const OBB& boxB, const WorldEntity& nodeA, const WorldEntity& nodeB) const; |
---|
49 | |
---|
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 | |
---|
57 | private: |
---|
58 | unsigned int treeIndex; //!< Index number of the BV in the tree |
---|
59 | int depth; //!< the depth of the node in the tree |
---|
60 | const OBBTree* obbTree; //!< reference to the obb tree |
---|
61 | |
---|
62 | const modelInfo* modelInf; //!< pointer to the models modelInfo object |
---|
63 | const int* triangleIndexes; //!< indexes to the used model triangles |
---|
64 | |
---|
65 | Plane separationPlane; //!< the separation plane of the obb |
---|
66 | sVec3D sepPlaneCenter; //!< only needed to draw plane |
---|
67 | int longestAxisIndex; //!< only needed to draw plane |
---|
68 | |
---|
69 | /* tmp saving place for obb variables */ |
---|
70 | int* triangleIndexList1; //!< pointer to the vert data of obbox1 |
---|
71 | int* triangleIndexList2; //!< pointer to the vert data of obbox1 |
---|
72 | int triangleIndexLength1; //!< len vert data obbox1 |
---|
73 | int triangleIndexLength2; //!< len vert data obbox2 |
---|
74 | }; |
---|
75 | |
---|
76 | #endif /* _OBB_TREE_NODE_H */ |
---|