| 1 | /*! | 
|---|
| 2 | * @file proto_class.h | 
|---|
| 3 | *  Definition of a QuadtreeNode which represents a quad in a Quadtree | 
|---|
| 4 |  | 
|---|
| 5 | This struct is used to partition big land scapes into smaller ones for different reasons: | 
|---|
| 6 | - for collision detection: only a subset of all triangles need to be tested vs a given body | 
|---|
| 7 | - for object culling purposes: the quadtrees that are not in the field of view can be ommitted in the draw process | 
|---|
| 8 | - for LOD (level of Detail). The models can be drawn using different LODs depending on the distance | 
|---|
| 9 |  | 
|---|
| 10 | This struct includes all the triangles, vertices, normal informations needed to make something usefull with | 
|---|
| 11 | a terrain partition. | 
|---|
| 12 | */ | 
|---|
| 13 |  | 
|---|
| 14 | #ifndef _QUADTREE_NODE_H | 
|---|
| 15 | #define _QUADTREE_NODE_H | 
|---|
| 16 |  | 
|---|
| 17 | #include "base_object.h" | 
|---|
| 18 |  | 
|---|
| 19 | #include "model.h" | 
|---|
| 20 |  | 
|---|
| 21 | // FORWARD DECLARATION | 
|---|
| 22 | class Quadtree; | 
|---|
| 23 |  | 
|---|
| 24 |  | 
|---|
| 25 | //! A class for a Quadtree Node representation | 
|---|
| 26 | class QuadtreeNode : public BaseObject { | 
|---|
| 27 |  | 
|---|
| 28 | public: | 
|---|
| 29 | QuadtreeNode(sTriangleExt** triangles, int numTriangles, | 
|---|
| 30 | const float* pVertices, int numVertices, | 
|---|
| 31 | Quadtree* quadtree, QuadtreeNode* parent, | 
|---|
| 32 | Rectangle* rect, int treeDepth, const int maxDepth, int index | 
|---|
| 33 | ); | 
|---|
| 34 | QuadtreeNode(const modelInfo* pModelInfo, Quadtree* quadtree, const int maxDepth); | 
|---|
| 35 | virtual ~QuadtreeNode(); | 
|---|
| 36 |  | 
|---|
| 37 | void buildHashTable(QuadtreeNode** nodeList, int* index); | 
|---|
| 38 | inline Rectangle* getDimension() { return this->pDimension; } | 
|---|
| 39 |  | 
|---|
| 40 | bool includesPoint(const Vector& v) const; | 
|---|
| 41 | sTriangleExt* getTriangle(const Vector& position) const; | 
|---|
| 42 | float getHeight(const Vector& position) const; | 
|---|
| 43 |  | 
|---|
| 44 |  | 
|---|
| 45 | void drawTree() const; | 
|---|
| 46 | void draw() const; | 
|---|
| 47 |  | 
|---|
| 48 |  | 
|---|
| 49 | private: | 
|---|
| 50 | void init(); | 
|---|
| 51 |  | 
|---|
| 52 | void separateNode(float minLength); | 
|---|
| 53 | void separateNode(); | 
|---|
| 54 | Rectangle* getDimFromModel(); | 
|---|
| 55 |  | 
|---|
| 56 | bool sameSide(const Vector& p1, const Vector&p2, const Vector& a, const Vector& b) const; | 
|---|
| 57 | bool pointInTriangle(const Vector&p, const Vector& a, const Vector& b, const Vector& c) const; | 
|---|
| 58 |  | 
|---|
| 59 | protected: | 
|---|
| 60 | QuadtreeNode*                   parent;             //!< reference to the paren QuadtreeNode (NULL if rootnode) | 
|---|
| 61 | QuadtreeNode*                   nodeA;              //!< reference to the node A | 
|---|
| 62 | QuadtreeNode*                   nodeB;              //!< reference to the node B | 
|---|
| 63 | QuadtreeNode*                   nodeC;              //!< reference to the node C | 
|---|
| 64 | QuadtreeNode*                   nodeD;              //!< reference to the node D | 
|---|
| 65 | QuadtreeNode**                  nodes;              //!< reference to the quadtree nodes (nodeA, nodeB, nodeC, nodeD=[0..3]) | 
|---|
| 66 |  | 
|---|
| 67 |  | 
|---|
| 68 | private: | 
|---|
| 69 | Quadtree*                       quadtree;           //!< reference to the quadtree | 
|---|
| 70 | Vector                          center;             //!< center coordinate of the quadtree node - relative coordinates in model space(!) | 
|---|
| 71 | float                           axisLength;         //!< axis length of the quadtree | 
|---|
| 72 | float                           maxHeigth;          //!< max height of the model in the quadtree | 
|---|
| 73 | float                           offset;             //!< offset of the actual quadtree rectangle | 
|---|
| 74 |  | 
|---|
| 75 | int                             treeDepth;          //!< the depth of the tree | 
|---|
| 76 | int                             maxDepth;           //!< the maximal depth of the tree | 
|---|
| 77 | int                             indexNode;          //!< the index number of the node | 
|---|
| 78 | int                             nodeIter;           //!< temp helping variable for the hashing algorithm | 
|---|
| 79 |  | 
|---|
| 80 | sTriangleExt**                  pTriangles;         //!< reference to the triangles of the node | 
|---|
| 81 | const float*                    pVertices;          //!< reference to vertices data | 
|---|
| 82 | unsigned int                    numTriangles;       //!< number of triangles of the Node | 
|---|
| 83 | unsigned int                    numVertices;        //!< number of vertices of the node | 
|---|
| 84 | const modelInfo*                pModelInfo;         //!< reference to the modelInfo of the object | 
|---|
| 85 | Rectangle*                      pDimension;         //!< pointer to the local rectangle properties | 
|---|
| 86 |  | 
|---|
| 87 | bool                            bDraw;              //!< shall it be drawn? DEBUG only | 
|---|
| 88 | }; | 
|---|
| 89 |  | 
|---|
| 90 | #endif /* _QUADTREE_NODE_H */ | 
|---|