Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.