Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: implemented a point in triangle function

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