Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/spatial_separation/quadtree_node.h @ 6687

Last change on this file since 6687 was 6617, checked in by bensch, 19 years ago

trunk: split Rotation/Line/Quaternion/Plane(Rectangle) into seperate files

File size: 4.1 KB
Line 
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 "plane.h"
20#include "model.h"
21
22// FORWARD DECLARATION
23class Quadtree;
24
25
26//! A class for a Quadtree Node representation
27class QuadtreeNode : public BaseObject {
28
29  public:
30    QuadtreeNode(sTriangleExt** triangles, int numTriangles,
31                 const float* pVertices, int numVertices,
32                 Quadtree* quadtree, QuadtreeNode* parent,
33                 Rectangle* rect, int treeDepth, const int maxDepth, int index
34                );
35    QuadtreeNode(const modelInfo* pModelInfo, Quadtree* quadtree, const int maxDepth);
36    virtual ~QuadtreeNode();
37
38    void buildHashTable(QuadtreeNode** nodeList, int* index);
39    inline Rectangle* getDimension() { return this->pDimension; }
40
41    bool includesPoint(const Vector& v) const;
42    sTriangleExt* getTriangle(const Vector& position) const;
43    float getHeight(const Vector& position) const;
44
45
46    void drawTree() const;
47    void draw() const;
48
49
50  private:
51    void init();
52
53    void separateNode(float minLength);
54    void separateNode();
55    Rectangle* getDimFromModel();
56
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;
59
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
66    QuadtreeNode**                  nodes;              //!< reference to the quadtree nodes (nodeA, nodeB, nodeC, nodeD=[0..3])
67
68
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
74    float                           offset;             //!< offset of the actual quadtree rectangle
75
76    int                             treeDepth;          //!< the depth of the tree
77    int                             maxDepth;           //!< the maximal depth of the tree
78    int                             indexNode;          //!< the index number of the node
79    int                             nodeIter;           //!< temp helping variable for the hashing algorithm
80
81    sTriangleExt**                  pTriangles;         //!< reference to the triangles of the node
82    const float*                    pVertices;          //!< reference to vertices data
83    unsigned int                    numTriangles;       //!< number of triangles of the Node
84    unsigned int                    numVertices;        //!< number of vertices of the node
85    const modelInfo*                pModelInfo;         //!< reference to the modelInfo of the object
86    Rectangle*                      pDimension;         //!< pointer to the local rectangle properties
87
88    bool                            bDraw;              //!< shall it be drawn? DEBUG only
89};
90
91#endif /* _QUADTREE_NODE_H */
Note: See TracBrowser for help on using the repository browser.