| 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(); | 
|---|
| 28 |     virtual ~OBBTreeNode(); | 
|---|
| 29 |  | 
|---|
| 30 |     virtual void spawnBVTree(const int depth, const sVec3D *verticesList, unsigned int length); | 
|---|
| 31 |     virtual void spawnBVTree(const int depth, const modelInfo& modInfo); | 
|---|
| 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, const Vector& color = Vector(1,0,0), bool top = true) const; | 
|---|
| 40 |  | 
|---|
| 41 |     void debug() const; | 
|---|
| 42 |  | 
|---|
| 43 |   private: | 
|---|
| 44 |     void calculateBoxCovariance(OBB* box, const sVec3D* verticesList, unsigned int length); | 
|---|
| 45 |     void calculateBoxEigenvectors(OBB* box, const sVec3D* verticesList, unsigned int length); | 
|---|
| 46 |     void calculateBoxAxis(OBB* box, const sVec3D* verticesList, unsigned int length); | 
|---|
| 47 |  | 
|---|
| 48 |     void calculateBoxCovariance(OBB* box, const modelInfo& modInfo); | 
|---|
| 49 |     void calculateBoxEigenvectors(OBB* box, const modelInfo& modInfo); | 
|---|
| 50 |     void calculateBoxAxis(OBB* box, const modelInfo& modInfo); | 
|---|
| 51 |  | 
|---|
| 52 |  | 
|---|
| 53 |     void forkBox(OBB* box); | 
|---|
| 54 |  | 
|---|
| 55 |     bool overlapTest(OBB* boxA, OBB* boxB, WorldEntity* nodeA, WorldEntity* nodeB); | 
|---|
| 56 |  | 
|---|
| 57 |   protected: | 
|---|
| 58 |     OBB*                bvElement;                  //!< the obb element | 
|---|
| 59 |     OBBTreeNode*        nodeLeft;                   //!< ref to the left tree node | 
|---|
| 60 |     OBBTreeNode*        nodeRight;                  //!< ref to the right tree node | 
|---|
| 61 |  | 
|---|
| 62 |   private: | 
|---|
| 63 |     unsigned int        treeIndex;                  //!< Index number of the BV in the tree | 
|---|
| 64 |     const sVec3D*       vertices;                   //!< pointer to the vertices data | 
|---|
| 65 |     int                 numOfVertices;              //!< number of vertices in vertices data | 
|---|
| 66 |     int                 depth;                      //!< the depth of the node in the tree | 
|---|
| 67 |     static OBBTree*     obbTree;                    //!< reference to the obb tree | 
|---|
| 68 |     Plane*              separationPlane;            //!< the separation plane of the obb | 
|---|
| 69 |     const sVec3D*       sepPlaneCenter;             //!< only needed to draw plane | 
|---|
| 70 |     int                 longestAxisIndex;           //!< only needed to draw plane | 
|---|
| 71 |  | 
|---|
| 72 |     /* tmp saving place for obb variables */ | 
|---|
| 73 |     sVec3D*             tmpVert1;                   //!< pointer to the vert data of obbox1 | 
|---|
| 74 |     sVec3D*             tmpVert2;                   //!< pointer to the vert data of obbox1 | 
|---|
| 75 |     int                 tmpLen1;                    //!< len vert data obbox1 | 
|---|
| 76 |     int                 tmpLen2;                    //!< len vert data obbox2 | 
|---|
| 77 |  | 
|---|
| 78 |     static float**      coMat; | 
|---|
| 79 |     static float**      eigvMat; | 
|---|
| 80 |     static float*       eigvlMat; | 
|---|
| 81 |     static int*         rotCount; | 
|---|
| 82 | }; | 
|---|
| 83 |  | 
|---|
| 84 | #endif /* _OBB_TREE_NODE_H */ | 
|---|