Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/terrain/src/lib/graphics/spatial_separation/quadtree_node.h @ 10429

Last change on this file since 10429 was 9869, checked in by bensch, 18 years ago

orxonox/trunk: merged the new_class_id branche back to the trunk.
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/new_class_id trunk -r9683:HEAD
no conflicts… puh..

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  ObjectListDeclaration(QuadtreeNode);
29
30  public:
31    QuadtreeNode(sTriangleExt** triangles, int numTriangles,
32                 const float* pVertices, int numVertices,
33                 Quadtree* quadtree, QuadtreeNode* parent,
34                 Rectangle* rect, int treeDepth, const int maxDepth, int index
35                );
36    QuadtreeNode(const modelInfo* pModelInfo, Quadtree* quadtree, const int maxDepth);
37    virtual ~QuadtreeNode();
38
39    void buildHashTable(QuadtreeNode** nodeList, int* index);
40    inline Rectangle* getDimension() { return this->pDimension; }
41
42    bool includesPoint(const Vector& v) const;
43    sTriangleExt* getTriangle(const Vector& position) const;
44    float getHeight(const Vector& position) const;
45
46
47    void drawTree() const;
48    void draw() const;
49
50
51  private:
52    void init();
53
54    void separateNode(float minLength);
55    void separateNode();
56    Rectangle* getDimFromModel();
57
58    bool sameSide(const Vector& p1, const Vector&p2, const Vector& a, const Vector& b) const;
59    bool pointInTriangle(const Vector&p, const Vector& a, const Vector& b, const Vector& c) const;
60
61  protected:
62    QuadtreeNode*                   parent;             //!< reference to the paren QuadtreeNode (NULL if rootnode)
63    QuadtreeNode*                   nodeA;              //!< reference to the node A
64    QuadtreeNode*                   nodeB;              //!< reference to the node B
65    QuadtreeNode*                   nodeC;              //!< reference to the node C
66    QuadtreeNode*                   nodeD;              //!< reference to the node D
67    QuadtreeNode**                  nodes;              //!< reference to the quadtree nodes (nodeA, nodeB, nodeC, nodeD=[0..3])
68
69
70  private:
71    Quadtree*                       quadtree;           //!< reference to the quadtree
72    Vector                          center;             //!< center coordinate of the quadtree node - relative coordinates in model space(!)
73    float                           axisLength;         //!< axis length of the quadtree
74    float                           maxHeigth;          //!< max height of the model in the quadtree
75    float                           offset;             //!< offset of the actual quadtree rectangle
76
77    int                             treeDepth;          //!< the depth of the tree
78    int                             maxDepth;           //!< the maximal depth of the tree
79    int                             indexNode;          //!< the index number of the node
80    int                             nodeIter;           //!< temp helping variable for the hashing algorithm
81
82    sTriangleExt**                  pTriangles;         //!< reference to the triangles of the node
83    const float*                    pVertices;          //!< reference to vertices data
84    unsigned int                    numTriangles;       //!< number of triangles of the Node
85    unsigned int                    numVertices;        //!< number of vertices of the node
86    const modelInfo*                pModelInfo;         //!< reference to the modelInfo of the object
87    Rectangle*                      pDimension;         //!< pointer to the local rectangle properties
88
89    bool                            bDraw;              //!< shall it be drawn? DEBUG only
90};
91
92#endif /* _QUADTREE_NODE_H */
Note: See TracBrowser for help on using the repository browser.