Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/lib/collision_detection/obb_tree_node.h @ 8548

Last change on this file since 8548 was 7732, checked in by patrick, 19 years ago

orxonox: removed a memory leak

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