[4805] | 1 | /*! |
---|
[5039] | 2 | * @file proto_class.h |
---|
[4923] | 3 | * Definition of a QuadtreeNode which represents a quad in a Quadtree |
---|
[4805] | 4 | |
---|
[4923] | 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. |
---|
[4845] | 12 | */ |
---|
[4805] | 13 | |
---|
| 14 | #ifndef _QUADTREE_NODE_H |
---|
| 15 | #define _QUADTREE_NODE_H |
---|
| 16 | |
---|
| 17 | #include "base_object.h" |
---|
[5819] | 18 | |
---|
[6617] | 19 | #include "plane.h" |
---|
[6022] | 20 | #include "model.h" |
---|
[4811] | 21 | |
---|
[5405] | 22 | // FORWARD DECLARATION |
---|
[4813] | 23 | class Quadtree; |
---|
[4805] | 24 | |
---|
[4868] | 25 | |
---|
[4805] | 26 | //! A class for a Quadtree Node representation |
---|
| 27 | class QuadtreeNode : public BaseObject { |
---|
| 28 | |
---|
[4845] | 29 | public: |
---|
[4887] | 30 | QuadtreeNode(sTriangleExt** triangles, int numTriangles, |
---|
[4896] | 31 | const float* pVertices, int numVertices, |
---|
[4897] | 32 | Quadtree* quadtree, QuadtreeNode* parent, |
---|
[4923] | 33 | Rectangle* rect, int treeDepth, const int maxDepth, int index |
---|
| 34 | ); |
---|
[5430] | 35 | QuadtreeNode(const modelInfo* pModelInfo, Quadtree* quadtree, const int maxDepth); |
---|
[4845] | 36 | virtual ~QuadtreeNode(); |
---|
[4805] | 37 | |
---|
[4911] | 38 | void buildHashTable(QuadtreeNode** nodeList, int* index); |
---|
[4923] | 39 | inline Rectangle* getDimension() { return this->pDimension; } |
---|
[4904] | 40 | |
---|
[4968] | 41 | bool includesPoint(const Vector& v) const; |
---|
[4956] | 42 | sTriangleExt* getTriangle(const Vector& position) const; |
---|
| 43 | float getHeight(const Vector& position) const; |
---|
| 44 | |
---|
| 45 | |
---|
[4922] | 46 | void drawTree() const; |
---|
[4921] | 47 | void draw() const; |
---|
[4812] | 48 | |
---|
| 49 | |
---|
[4845] | 50 | private: |
---|
[4852] | 51 | void init(); |
---|
[4805] | 52 | |
---|
[4898] | 53 | void separateNode(float minLength); |
---|
| 54 | void separateNode(); |
---|
[4897] | 55 | Rectangle* getDimFromModel(); |
---|
[4896] | 56 | |
---|
[4956] | 57 | bool sameSide(const Vector& p1, const Vector&p2, const Vector& a, const Vector& b) const; |
---|
| 58 | bool pointInTriangle(const Vector&p, const Vector& a, const Vector& b, const Vector& c) const; |
---|
[4923] | 59 | |
---|
[4896] | 60 | protected: |
---|
| 61 | QuadtreeNode* parent; //!< reference to the paren QuadtreeNode (NULL if rootnode) |
---|
| 62 | QuadtreeNode* nodeA; //!< reference to the node A |
---|
| 63 | QuadtreeNode* nodeB; //!< reference to the node B |
---|
| 64 | QuadtreeNode* nodeC; //!< reference to the node C |
---|
| 65 | QuadtreeNode* nodeD; //!< reference to the node D |
---|
[4968] | 66 | QuadtreeNode** nodes; //!< reference to the quadtree nodes (nodeA, nodeB, nodeC, nodeD=[0..3]) |
---|
[4896] | 67 | |
---|
[4923] | 68 | |
---|
[4845] | 69 | private: |
---|
| 70 | Quadtree* quadtree; //!< reference to the quadtree |
---|
| 71 | Vector center; //!< center coordinate of the quadtree node - relative coordinates in model space(!) |
---|
| 72 | float axisLength; //!< axis length of the quadtree |
---|
| 73 | float maxHeigth; //!< max height of the model in the quadtree |
---|
[4851] | 74 | float offset; //!< offset of the actual quadtree rectangle |
---|
[4811] | 75 | |
---|
[4887] | 76 | int treeDepth; //!< the depth of the tree |
---|
[4898] | 77 | int maxDepth; //!< the maximal depth of the tree |
---|
[4900] | 78 | int indexNode; //!< the index number of the node |
---|
[4923] | 79 | int nodeIter; //!< temp helping variable for the hashing algorithm |
---|
[4887] | 80 | |
---|
[4851] | 81 | sTriangleExt** pTriangles; //!< reference to the triangles of the node |
---|
| 82 | const float* pVertices; //!< reference to vertices data |
---|
[4845] | 83 | unsigned int numTriangles; //!< number of triangles of the Node |
---|
[4868] | 84 | unsigned int numVertices; //!< number of vertices of the node |
---|
[5430] | 85 | const modelInfo* pModelInfo; //!< reference to the modelInfo of the object |
---|
[4851] | 86 | Rectangle* pDimension; //!< pointer to the local rectangle properties |
---|
[4921] | 87 | |
---|
| 88 | bool bDraw; //!< shall it be drawn? DEBUG only |
---|
[4805] | 89 | }; |
---|
| 90 | |
---|
| 91 | #endif /* _QUADTREE_NODE_H */ |
---|