[8507] | 1 | /*! |
---|
| 2 | * @file aabb_tree_node.h |
---|
| 3 | * Definition of a bounding volume tree |
---|
| 4 | */ |
---|
| 5 | |
---|
| 6 | #ifndef _AABB_TREE_NODE_H |
---|
| 7 | #define _AABB_TREE_NODE_H |
---|
| 8 | |
---|
| 9 | |
---|
| 10 | #include "bv_tree_node.h" |
---|
| 11 | #include "plane.h" |
---|
| 12 | |
---|
| 13 | class BoundingVolume; |
---|
[8508] | 14 | class AABB; |
---|
[8507] | 15 | class OBBTree; |
---|
| 16 | class Plane; |
---|
| 17 | class PNode; |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | //! A class that represents a bounding volume tree |
---|
| 21 | class AABBTreeNode : public BVTreeNode |
---|
| 22 | { |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | public: |
---|
| 26 | AABBTreeNode(const OBBTree& tree, AABBTreeNode* prev, int depth); |
---|
| 27 | AABBTreeNode(int depth = 0); |
---|
| 28 | virtual ~AABBTreeNode(); |
---|
| 29 | void init(); |
---|
| 30 | |
---|
| 31 | /** this function returns the bounding volume of this tree node @return: returns the BV */ |
---|
| 32 | virtual inline const BoundingVolume* getBV() const { return (BoundingVolume*)this->bvElement; } |
---|
| 33 | |
---|
| 34 | void spawnBVTree(Model* model); |
---|
| 35 | virtual void spawnBVTree(const modelInfo& modelInf, const int* triangleIndexes, int length); |
---|
| 36 | |
---|
| 37 | virtual void collideWith(BVTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB); |
---|
| 38 | virtual void drawBV(int depth, int drawMode, const Vector& color = Vector(1,0,0), bool top = true) const; |
---|
| 39 | void debug() const; |
---|
| 40 | |
---|
| 41 | /** gets the id of the current child @return id of the child */ |
---|
| 42 | inline const int getID() { return this->nextID++; } |
---|
[8508] | 43 | inline AABB* getAABB() { return this->bvElement; } |
---|
[8507] | 44 | |
---|
| 45 | private: |
---|
[8508] | 46 | void calculateBoxAxis(AABB& box, const sVec3D* verticesList, unsigned int length); |
---|
[8507] | 47 | |
---|
[8508] | 48 | void calculateBoxCovariance(AABB& box, const modelInfo& modelInf, const int* triangleIndexes, int length); |
---|
| 49 | void calculateBoxEigenvectors(AABB& box, const modelInfo& modelInf, const int* triangleIndexes, int length); |
---|
| 50 | void calculateBoxAxis(AABB& box, const modelInfo& modelInf, const int* triangleIndexes, int length); |
---|
| 51 | void forkBox(AABB& box); |
---|
[8507] | 52 | |
---|
| 53 | void collideWithOBB(AABBTreeNode* treeNode, WorldEntity* nodeA, WorldEntity* nodeB); |
---|
[8508] | 54 | bool overlapTest(AABB* boxA, AABB* boxB, WorldEntity* nodeA, WorldEntity* nodeB); |
---|
[8507] | 55 | |
---|
| 56 | |
---|
| 57 | protected: |
---|
[8508] | 58 | AABB* bvElement; //!< the obb element |
---|
[8507] | 59 | AABBTreeNode* nodePrev; //!< ref to the previous (parent) tree node = NULL if first |
---|
| 60 | AABBTreeNode* nodeLeft; //!< ref to the left tree node |
---|
| 61 | AABBTreeNode* nodeRight; //!< ref to the right tree node |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | private: |
---|
| 65 | int treeIndex; //!< Index number of the BV in the tree |
---|
| 66 | int nextID; //!< the id of the next child |
---|
| 67 | int depth; //!< the depth of the node in the tree |
---|
| 68 | const OBBTree* obbTree; //!< reference to the obb tree |
---|
| 69 | |
---|
| 70 | const modelInfo* modelInf; //!< pointer to the models modelInfo object |
---|
| 71 | const int* triangleIndexes; //!< indexes to the used model triangles |
---|
| 72 | |
---|
| 73 | Plane separationPlane; //!< the separation plane of the obb |
---|
| 74 | sVec3D sepPlaneCenter; //!< only needed to draw plane |
---|
| 75 | int longestAxisIndex; //!< only needed to draw plane |
---|
| 76 | |
---|
| 77 | /* tmp saving place for obb variables */ |
---|
| 78 | int* triangleIndexList1; //!< pointer to the vert data of obbox1 |
---|
| 79 | int* triangleIndexList2; //!< pointer to the vert data of obbox1 |
---|
| 80 | int triangleIndexLength1; //!< len vert data obbox1 |
---|
| 81 | int triangleIndexLength2; //!< len vert data obbox2 |
---|
| 82 | |
---|
| 83 | WorldEntity* owner; |
---|
| 84 | }; |
---|
| 85 | |
---|
| 86 | #endif /* _AABB_TREE_NODE_H */ |
---|