Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4924 in orxonox.OLD for orxonox/trunk/src/lib


Ignore:
Timestamp:
Jul 21, 2005, 4:46:41 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: the last cleanups, now the classes look better

Location:
orxonox/trunk/src/lib
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/collision_detection/cd_engine.cc

    r4923 r4924  
    7171
    7272
    73 
     73/**
     74 *  this checks the collisions with the objects
     75 */
    7476void CDEngine::checkCollisionObjects()
    7577{
     
    9698
    9799
     100/**
     101 *  this checks the collisions with the ground
     102 */
    98103void CDEngine::checkCollisionGround()
    99104{
     
    103108
    104109
     110/**
     111 *  this draws the bounding volume tree
     112 * @param depth until which depth to draw the tree
     113 * @param drawMode mod which states how to draw it
     114 */
    105115void CDEngine::drawBV(int depth, int drawMode) const
    106116{
     
    116126  }
    117127  delete iterator;
    118   //model->draw();
    119128}
    120129
    121130
    122 
    123 
    124 
     131/**
     132 * some debug output on the class
     133 */
    125134void CDEngine::debug()
    126135{
     
    133142}
    134143
     144
     145/**
     146 * this spawns a tree for debug purposes only
     147 */
    135148void CDEngine::debugSpawnTree(int depth, sVec3D* vertices, int numVertices)
    136149{
     
    140153}
    141154
     155
     156/**
     157 * this draws the debug spawn tree
     158 */
    142159void CDEngine::debugDraw(int depth, int drawMode)
    143160{
  • orxonox/trunk/src/lib/collision_detection/cd_engine.h

    r4919 r4924  
    5555
    5656  void debug();
    57   void debugSpawnTree(int depth, sVec3D* vertices, int numVertices);
    58   void debugDraw(int depth, int drawMode);
     57
    5958
    6059 private:
     
    6665  void checkCollisionObjects();
    6766  void checkCollisionGround();
     67
     68  void debugSpawnTree(int depth, sVec3D* vertices, int numVertices);
     69  void debugDraw(int depth, int drawMode);
    6870
    6971
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.cc

    r4923 r4924  
    99   any later version.
    1010
    11    ### File Specific:
     11### File Specific:
    1212   main-programmer: Patrick Boenzli
    1313   co-programmer: ...
     
    1919
    2020#include "quadtree_node.h"
     21#include "vector.h"
     22
    2123#include "material.h"
    22 #include "vector.h"
     24
    2325
    2426using namespace std;
     
    2729/**
    2830 *  standard constructor
    29    @todo this constructor is not jet implemented - do it
    30 */
     31 */
    3132Quadtree::Quadtree (modelInfo* pModelInfo, const int treeDepth)
    3233{
    33    this->setClassID(CL_QUADTREE, "Quadtree");
    34    this->pModelInfo = pModelInfo;
    35    this->treeDepth = treeDepth;
     34  this->setClassID(CL_QUADTREE, "Quadtree");
     35  this->pModelInfo = pModelInfo;
     36  this->treeDepth = treeDepth;
    3637
    37    /* initialize the materials for debug draw */
    38    this->materials = new Material*[4];
    39    for(int i = 0; i < 4; ++i)
    40    {
    41      materials[i] = new Material();
    42      materials[i]->setIllum(3);
    43    }
    44    materials[0]->setAmbient(0.0, 0.3, 0.0);
    45    materials[1]->setAmbient(0.4, 0.0, 0.2);
    46    materials[2]->setAmbient(1.0, 0.0, 0.0);
    47    materials[3]->setAmbient(5.0, 3.0, 1.0);
     38  /* initialize the materials for debug draw */
     39  this->materials = new Material*[4];
     40  for(int i = 0; i < 4; ++i)
     41  {
     42    materials[i] = new Material();
     43    materials[i]->setIllum(3);
     44  }
     45  materials[0]->setAmbient(0.0, 0.3, 0.0);
     46  materials[1]->setAmbient(0.4, 0.0, 0.2);
     47  materials[2]->setAmbient(1.0, 0.0, 0.0);
     48  materials[3]->setAmbient(5.0, 3.0, 1.0);
    4849
    49    /* build the tree */
    50    this->rootNode = new QuadtreeNode(this->pModelInfo, this, this->treeDepth);
     50  /* build the tree */
     51  this->rootNode = new QuadtreeNode(this->pModelInfo, this, this->treeDepth);
    5152
    52    /* make an array with access to the leafs of the Quad-Tree */
    53    this->nodes = new QuadtreeNode*[(int)pow(4, treeDepth)];
    54    int* index = new int; *index = 0;
    55    for(int i = 0; i < (int)pow(2, treeDepth); ++i)
    56    {
    57      printf("============================\n");
    58      this->rootNode->buildHashTable(this->nodes, index);
    59    }
    60    this->sortHashTable(this->nodes);
    61    this->revertHashTable(this->nodes);
     53  /* make an array with access to the leafs of the Quad-Tree */
     54  this->nodes = new QuadtreeNode*[(int)pow(4, treeDepth)];
     55  int* index = new int; *index = 0;
     56  for(int i = 0; i < (int)pow(2, treeDepth); ++i)
     57  {
     58    this->rootNode->buildHashTable(this->nodes, index);
     59  }
     60  /* sort and revert the hash table to fit the right position */
     61  this->sortHashTable(this->nodes);
     62  this->revertHashTable(this->nodes);
    6263
    63    for(int i = 0; i < (int)pow(4, treeDepth); ++i)
    64    {
    65      printf("node %i, %f, %f \n", i, this->nodes[i]->getDimension()->getCenter()->x, this->nodes[i]->getDimension()->getCenter()->z);
    66    }
    67 
    68    this->quadLength = this->nodes[0]->getDimension()->getAxis() * 2.0f;
    69    Rectangle* r = this->rootNode->getDimension();
    70 
    71    Vector* offset = new Vector();
    72    float xOff = r->getCenter()->x - r->getAxis();
    73    float yOff = r->getCenter()->z - r->getAxis();
    74    this->offset->x = xOff;
    75    this->offset->z = yOff;
    76 
    77    this->maxIndex = (int)pow(2, this->treeDepth);
     64  /* define some important and often used variables */
     65  this->quadLength = this->nodes[0]->getDimension()->getAxis() * 2.0f;
     66  Rectangle* r = this->rootNode->getDimension();
     67  Vector* offset = new Vector();
     68  float xOff = r->getCenter()->x - r->getAxis();
     69  float yOff = r->getCenter()->z - r->getAxis();
     70  this->offset->x = xOff;
     71  this->offset->z = yOff;
     72  this->maxIndex = (int)pow(2, this->treeDepth);
    7873}
    7974
     
    8176/**
    8277 *  standard deconstructor
    83 
    84 */
     78 */
    8579Quadtree::~Quadtree ()
    8680{
     
    9387
    9488/**
    95   \brief this function rotates the array and mirrors it in the middle
    96   \param nodes: the nodes to translate
     89 * this function rotates the array and mirrors it in the middle
     90 * @param nodes: the nodes to translate
    9791
    9892  since the original matrix is counted from the right upper edge to the right lower one, we have to reorganize the elements
     
    123117}
    124118
     119
    125120/**
    126   \brief sorts the hash table using their positions
    127   \param nodes the nodes to use
    128 
     121 *  sorts the hash table using their positions
     122 * @param nodes the nodes to use
    129123 */
    130124void Quadtree::sortHashTable(QuadtreeNode** nodes)
     
    158152
    159153/**
    160   \brief maps a position to a quadtree
    161   \param position the position so look for
    162   \return the quadtree
     154 * maps a position to a quadtree
     155 * @param position the position so look for
     156 * @return the quadtree
    163157
    164158  this function will return the quadtree that contains the position
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h

    r4922 r4924  
    11/*!
    22    \file quadtree.h
    3   *  Definition of a spatial data separation using quadtree
     3 *  Definition of a spatial data separation using quadtree
    44
    5 */
     5  This is the top element of the quadtree framework. A Quadtree is build of QuadtreeNodes, which are again separated
     6  into QuadtreeNodes until a certain depth is reached
     7 */
    68
    79#ifndef _QUADTREE_H
     
    2022class Quadtree : public BaseObject {
    2123
    22  public:
    23   Quadtree(modelInfo* pModelInfo, const int treeDepth);
    24   virtual ~Quadtree();
    2524
    26   QuadtreeNode* getQuadtreeFromPosition(const Vector& position);
     25  public:
     26    Quadtree(modelInfo* pModelInfo, const int treeDepth);
     27    virtual ~Quadtree();
    2728
    28   void drawTree() const;
    29   inline Material* getMaterial(int indexNode) const { return this->materials[indexNode % 4]; }
     29    QuadtreeNode* getQuadtreeFromPosition(const Vector& position);
     30
     31    void drawTree() const;
     32    inline Material* getMaterial(int indexNode) const { return this->materials[indexNode % 4]; }
     33
    3034
    3135  private:
     
    3337    void sortHashTable(QuadtreeNode** nodes);
    3438
    35  private:
    36    QuadtreeNode*                   rootNode;              //!< reference to the root node of the quadtree
    37    modelInfo*                      pModelInfo;            //!< reference to the modelInfo of the object
    38    int                             treeDepth;             //!< depth of the tree
    3939
    40    float                           quadLength;            //!< length of the leaf quadtree nodes
    41    Vector*                         offset;                //!< vector to the left lower corner of the root quadtree node
    42    int                             maxIndex;              //!< maximal index for the nodes array
     40  private:
     41    QuadtreeNode*                   rootNode;              //!< reference to the root node of the quadtree
     42    QuadtreeNode**                  nodes;                 //!< reference to all quadtree nodes (only leafs of the quad tree)
     43    modelInfo*                      pModelInfo;            //!< reference to the modelInfo of the object
     44    int                             treeDepth;             //!< depth of the tree
    4345
    44    Material**                      materials;             //!< materials for debug drawing purposes
     46    float                           quadLength;            //!< length of the leaf quadtree nodes
     47    Vector*                         offset;                //!< vector to the left lower corner of the root quadtree node
     48    int                             maxIndex;              //!< maximal index for the nodes array
    4549
    46    QuadtreeNode**                  nodes;                 //!< reference to all quadtree nodes (only leafs of the quad tree)
     50    Material**                      materials;             //!< materials for debug drawing purposes
    4751};
    4852
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc

    r4923 r4924  
    99   any later version.
    1010
    11    ### File Specific:
     11### File Specific:
    1212   main-programmer: Patrick Boenzli
    1313   co-programmer: ...
     
    2929/**
    3030 *  standard constructor
    31 */
     31 */
    3232QuadtreeNode::QuadtreeNode (sTriangleExt** triangles, int numTriangles,
    3333                            const float* pVertices, int numVertices,
     
    3636                           )
    3737{
     38  /* save all important variables localy */
    3839  this->pTriangles = triangles;
    3940  this->numTriangles = numTriangles;
    4041  this->pVertices = pVertices;
    4142  this->numVertices = numVertices;
    42 
    4343  this->quadtree = quadtree;
    4444  this->parent = parent;
    45 
    4645  this->pDimension = rect;
    4746  this->treeDepth = treeDepth;
     
    4948  this->indexNode = index;
    5049
    51 
    5250  /* debug output */
    5351  for( int i = 0; i < this->treeDepth; ++i)
     
    6967QuadtreeNode::QuadtreeNode(modelInfo* pModelInfo, Quadtree* quadtree, const int maxDepth)
    7068{
     69  /* save all important variables localy */
    7170  this->pModelInfo = pModelInfo;
    7271  this->quadtree = quadtree;
     72  this->maxDepth = maxDepth;
    7373
    7474  /* create an array of triangle references */
     
    8080    this->pTriangles[i] = &this->pModelInfo->pTriangles[i];
    8181
    82   this->treeDepth = 0;
    83   this->maxDepth = maxDepth;
    84   this->indexNode = 0;
    85 
    8682  /* debug output */
    8783  for( int i = 0; i < this->treeDepth; ++i)
     
    8985  PRINT(3)(" | +-| (Event) Building Node Nr. %i Depth: %i/%i, pointer: %p\n", this->indexNode, treeDepth, maxDepth, this);
    9086
     87  /* set some important variables */
     88  this->treeDepth = 0;
     89  this->indexNode = 0;
    9190  this->pDimension = this->getDimFromModel();
     91
    9292  this->init();
    9393}
     
    101101  this->setClassID(CL_QUADTREE_NODE, "QuadtreeNode");
    102102
     103  /* init the rest of the variables for both init types */
    103104  this->offset = 0.0f;
    104105  this->nodeIter = -1;
     
    114115    this->nodes[i] = NULL;
    115116
     117  /* now separate the nodes */
    116118  if( this->treeDepth < this->maxDepth)
    117119    this->separateNode();
     
    137139
    138140/**
    139   \brief this functions builds up a hash table containing all leafs of the Quadtree in a sorted array
    140   \param nodeList the nodelist array to add them
    141   \param index the current index in the array
     141 * this functions builds up a hash table containing all leafs of the Quadtree in a sorted array
     142 * @param nodeList the nodelist array to add them
     143 * @param index the current index in the array
    142144
    143145  The algorithm used for this purpose is home-brown. its not to fast but and the nodes are not always in the right
     
    166168 *  gives the signal to separate the model into a quadtree
    167169 * @param treeDepth the max depth, the steps to go if treeDept == 0 leaf reached
     170
     171 * @todo ATTENION: This function is currently not used and not implemented, but would be a nice addon
    168172 */
    169173void QuadtreeNode::separateNode(float minLength)
     
    185189 *  gives the signal to separate the model into a quadtree
    186190 * @param treeDepth the max depth, the steps to go if treeDept == 0 leaf reached
    187 */
     191 */
    188192void QuadtreeNode::separateNode()
    189193{
     194  /* separate the four regions into the four lists */
    190195  tList<sTriangleExt*>*           listA = new tList<sTriangleExt*>();    //!< triangle list of nodeA
    191196  tList<sTriangleExt*>*           listB = new tList<sTriangleExt*>();    //!< triangle list of nodeB
     
    197202  rectCenter = this->pDimension->getCenter();
    198203  for( int i = 0; i < this->numTriangles; ++i)
     204  {
     205    for( int j = 0; j < 3; ++j)
    199206    {
    200       for( int j = 0; j < 3; ++j)
    201         {
    202           pVert = &this->pVertices[this->pTriangles[i]->indexToVertices[j]];
    203           if( pVert[0] > rectCenter->x + this->offset && pVert[2] > rectCenter->z + this->offset)
    204             listA->add(&this->pTriangles[i]);
    205           if( pVert[0] < rectCenter->x + this->offset && pVert[2] > rectCenter->z + this->offset)
    206             listB->add(&this->pTriangles[i]);
    207           if( pVert[0] < rectCenter->x + this->offset && pVert[2] < rectCenter->z + this->offset)
    208             listC->add(&this->pTriangles[i]);
    209           if( pVert[0] > rectCenter->x + this->offset && pVert[2] < rectCenter->z + this->offset)
    210             listD->add(&this->pTriangles[i]);
    211         }
     207      pVert = &this->pVertices[this->pTriangles[i]->indexToVertices[j]];
     208      if( pVert[0] > rectCenter->x + this->offset && pVert[2] > rectCenter->z + this->offset)
     209        listA->add(&this->pTriangles[i]);
     210      if( pVert[0] < rectCenter->x + this->offset && pVert[2] > rectCenter->z + this->offset)
     211        listB->add(&this->pTriangles[i]);
     212      if( pVert[0] < rectCenter->x + this->offset && pVert[2] < rectCenter->z + this->offset)
     213        listC->add(&this->pTriangles[i]);
     214      if( pVert[0] > rectCenter->x + this->offset && pVert[2] < rectCenter->z + this->offset)
     215        listD->add(&this->pTriangles[i]);
    212216    }
    213     for( int i = 0; i < treeDepth; ++i)
    214       PRINT(3)(" |");
    215     PRINT(3)(" | +-| (II) Quadtree Counts - separating: A: %i, B: %i, C: %i, D: %i\n", listA->getSize(), listB->getSize(), listC->getSize(), listD->getSize());
    216 
    217   /* Separating into to the triangle lists  */
     217  }
     218  for( int i = 0; i < treeDepth; ++i)
     219    PRINT(3)(" |");
     220  PRINT(3)(" | +-| (II) Quadtree Counts - separating: A: %i, B: %i, C: %i, D: %i\n", listA->getSize(), listB->getSize(), listC->getSize(), listD->getSize());
     221
     222
     223  /* Separating into to the triangle arrays */
    218224  sTriangleExt**                 pTriA;                                 //!< Triangle array A
    219225  sTriangleExt**                 pTriB;                                 //!< Triangle array B
     
    238244  pTriD = new sTriangleExt*[listD->getSize()];
    239245
    240 
    241246  counter = 0;
    242247  iterator = listA->getIterator();
    243248  tempTri = iterator->nextElement();
    244249  while( tempTri)
    245     {
    246       pTriA[counter] = *tempTri;
    247       tempTri = iterator->nextElement();
    248       ++counter;
    249     }
    250 
     250  {
     251    pTriA[counter] = *tempTri;
     252    tempTri = iterator->nextElement();
     253    ++counter;
     254  }
    251255  counter = 0;
    252256  iterator = listB->getIterator();
    253257  tempTri = iterator->nextElement();
    254258  while( tempTri)
    255     {
    256       pTriB[counter] = *tempTri;
    257       tempTri = iterator->nextElement();
    258       ++counter;
    259     }
    260 
     259  {
     260    pTriB[counter] = *tempTri;
     261    tempTri = iterator->nextElement();
     262    ++counter;
     263  }
    261264  counter = 0;
    262265  iterator = listC->getIterator();
    263266  tempTri = iterator->nextElement();
    264267  while( tempTri)
    265     {
    266       pTriC[counter] = *tempTri;
    267       tempTri = iterator->nextElement();
    268       ++counter;
    269     }
    270 
     268  {
     269    pTriC[counter] = *tempTri;
     270    tempTri = iterator->nextElement();
     271    ++counter;
     272  }
    271273  counter = 0;
    272274  iterator = listD->getIterator();
    273275  tempTri = iterator->nextElement();
    274276  while( tempTri)
    275     {
    276       pTriD[counter] = *tempTri;
    277       tempTri = iterator->nextElement();
    278       ++counter;
    279     }
     277  {
     278    pTriD[counter] = *tempTri;
     279    tempTri = iterator->nextElement();
     280    ++counter;
     281  }
    280282
    281283  /* now do cleanup */
     
    288290
    289291  /* now create the rectangle dimensions */
    290   Vector v;
     292  Vector                     v;                                                             //!< temp saving place
     293  Rectangle*                 rA;                                                            //!< new size of the node A
     294  Rectangle*                 rB;                                                            //!< new size of the node B
     295  Rectangle*                 rC;                                                            //!< new size of the node C
     296  Rectangle*                 rD;                                                            //!< new size of the node D
     297
    291298
    292299  v.x = this->pDimension->getCenter()->x + this->pDimension->getAxis() / 2.0f;
    293300  v.y = 0.0;
    294301  v.z = this->pDimension->getCenter()->z + this->pDimension->getAxis() / 2.0f;
    295   Rectangle* rA = new Rectangle(v, this->pDimension->getAxis() / 2.0f);
    296 
     302  rA = new Rectangle(v, this->pDimension->getAxis() / 2.0f);
    297303  v.z = this->pDimension->getCenter()->z - this->pDimension->getAxis() / 2.0f;
    298   Rectangle* rB = new Rectangle(v, this->pDimension->getAxis() / 2.0f);
    299 
     304  rB = new Rectangle(v, this->pDimension->getAxis() / 2.0f);
    300305  v.x = this->pDimension->getCenter()->x - this->pDimension->getAxis() / 2.0f;
    301   Rectangle* rC = new Rectangle(v, this->pDimension->getAxis() / 2.0f);
    302 
     306  rC = new Rectangle(v, this->pDimension->getAxis() / 2.0f);
    303307  v.z = this->pDimension->getCenter()->z + this->pDimension->getAxis() / 2.0f;
    304   Rectangle* rD = new Rectangle(v, this->pDimension->getAxis() / 2.0f);
    305 
    306   /* now propagate */
     308  rD = new Rectangle(v, this->pDimension->getAxis() / 2.0f);
     309
     310  /* now create the new nodes */
    307311  this->nodeA = new QuadtreeNode(pTriA, lenA, this->pVertices, this->numVertices, this->quadtree, this, rA, this->treeDepth + 1, this->maxDepth, (this->treeDepth + 1) * 10 + 0);
    308 
    309312  this->nodeB = new QuadtreeNode(pTriB, lenB, this->pVertices, this->numVertices, this->quadtree, this, rB, this->treeDepth + 1, this->maxDepth, (this->treeDepth + 1) * 10 + 1);
    310 
    311313  this->nodeC = new QuadtreeNode(pTriC, lenC, this->pVertices, this->numVertices, this->quadtree, this, rC, this->treeDepth + 1, this->maxDepth, (this->treeDepth + 1) * 10 + 2);
    312 
    313314  this->nodeD = new QuadtreeNode(pTriD, lenD, this->pVertices, this->numVertices, this->quadtree, this, rD, this->treeDepth + 1, this->maxDepth, (this->treeDepth + 1) * 10 + 3);
     315
    314316  /* map the array references, this is for faster and automatical interfacing  \todo: use only array */
    315317  this->nodes[0] = this->nodeA;
     
    321323
    322324/**
    323    \brief gets the maximal dimension of a model
    324    \return the dimension of the AbstractModel as a Rectangle
     325 * gets the maximal dimension of a model
     326 * @return the dimension of the AbstractModel as a Rectangle
    325327
    326328   The rectangle is x-z axis aligned. ATTENTION: if there are any vertices in the model, that exceed the
     
    368370
    369371 /**
    370   * checks if a point is included in this quadtree
    371   * @param v the vector to be checked
    372   * @returns true if the vector is included
     372 * checks if a point is included in this quadtree
     373 * @param v the vector to be checked
     374 * @returns true if the vector is included
    373375  */
    374376bool QuadtreeNode::includesPoint(const Vector& v)
Note: See TracChangeset for help on using the changeset viewer.