Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4922 in orxonox.OLD


Ignore:
Timestamp:
Jul 21, 2005, 3:59:28 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: started cleaning up the code a little and making the comments

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

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.cc

    r4921 r4922  
    6464     printf("node %i, %f, %f \n", i, this->nodes[i]->getDimension()->getCenter()->x, this->nodes[i]->getDimension()->getCenter()->z);
    6565   }
     66
     67   this->quadLength = this->nodes[0]->getDimension()->getAxis() * 2.0f;
     68   Rectangle* r = this->rootNode->getDimension();
     69
     70   Vector* offset = new Vector();
     71   float xOff = r->getCenter()->x - r->getAxis();
     72   float yOff = r->getCenter()->z - r->getAxis();
     73   this->offset->x = xOff;
     74   this->offset->z = yOff;
     75
     76   this->maxIndex = (int)pow(2, this->treeDepth);
    6677}
    6778
     
    7687  delete [] this->nodes;
    7788  delete this->rootNode;
     89  delete offset;
    7890}
    7991
    8092
    8193/**
     94  \brief this function rotates the array and mirrors it in the middle
     95  \param nodes: the nodes to translate
    8296
    8397  since the original matrix is counted from the right upper edge to the right lower one, we have to reorganize the elements
     
    108122}
    109123
     124/**
     125  \brief sorts the hash table using their positions
     126  \param nodes the nodes to use
    110127
     128 */
    111129void Quadtree::sortHashTable(QuadtreeNode** nodes)
    112130{
    113131  int                  len         = (int)pow(2, this->treeDepth);          //!< the length of a quadtree side
    114   float a,b;
    115   QuadtreeNode* tmpNode;
     132  float                a;                                                   //!< temp place for float a
     133  float                b;                                                   //!< temp place for float b
     134  QuadtreeNode*        tmpNode;                                             //!< tmp place for a QuadtreeNode
    116135
    117   for(int i = 0; i < len; ++i)
     136  for( int i = 0; i < len; ++i)
    118137  {
    119     for(int j = 0; j < len; ++j)
     138    for( int j = 0; j < len; ++j)
    120139    {
    121       for(int k = j + 1; k < len; ++k)
     140      for( int k = j + 1; k < len; ++k)
    122141      {
    123142        a = this->nodes[i * len + j]->getDimension()->getCenter()->z;
     
    131150        }
    132151      }
     152    }
     153  }
    133154
    134     }
    135 
    136   }
    137155}
    138156
    139157
     158/**
     159  \brief maps a position to a quadtree
     160  \param position the position so look for
     161  \return the quadtree
    140162
     163  this function will return the quadtree that contains the position
     164 */
    141165QuadtreeNode* Quadtree::getQuadtreeFromPosition(const Vector& position)
    142166{
    143   Vector v = position;
    144   Rectangle* r = this->rootNode->getDimension();
    145   float len = this->nodes[0]->getDimension()->getAxis() * 2.0f;
     167  /* shift into model space */
     168  Vector v = position - *this->offset;
     169  /* map */
     170  int i = (int)(v.x / quadLength);
     171  int j = (int)(v.z / quadLength);
    146172
    147   Vector edge;
    148   float xOff = r->getCenter()->x - r->getAxis();
    149   float yOff = r->getCenter()->z - r->getAxis();
    150   edge.x = xOff, edge.z = yOff;
    151 
    152   /* shift into model space */
    153   v = position - edge;
    154   /* map */
    155   int i = (int)(v.x / len);
    156   int j = (int)(v.z / len);
    157 
    158   int max = (int)pow(2, this->treeDepth);
    159 
    160   if( i < max && j < max)
    161   {
    162     printf("-----------\nthe array coordinates are: %i, %i\n", i, j);
    163     printf("position: %f,%f, center %f, %f\n", position.x, position.z, this->nodes[i + j * max]->getDimension()->getCenter()->x, this->nodes[i + j * max]->getDimension()->getCenter()->z);
    164 
    165     //this->nodes[i + j * max]->draw();
    166     this->nodes[i + j * max]->includesPoint(position);
    167   }
     173  /* check if object is still inside the terrain */
     174  if( i < this->maxIndex && j < this->maxIndex)
     175    this->nodes[i + j * this->maxIndex]->includesPoint(position);
    168176  else
    169     printf("object has left terrain\n");
     177    PRINTF(0)("Object has left terrain\n");
    170178}
    171179
     
    174182 *  draws the debug quadtree boxes around the model
    175183 */
    176 void Quadtree::drawTree(int depth, int drawMode) const
     184void Quadtree::drawTree() const
    177185{
    178   //this->rootNode->drawTree(depth, drawMode);
    179   for(int i = 0; i < (int)pow(4, this->treeDepth); ++i)
    180   {
    181     this->nodes[i]->draw();
    182   }
    183 
    184 
     186  this->rootNode->drawTree();
     187//   for(int i = 0; i < (int)pow(4, this->treeDepth); ++i)
     188//   {
     189//     this->nodes[i]->draw();
     190//   }
    185191}
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h

    r4920 r4922  
    2626  QuadtreeNode* getQuadtreeFromPosition(const Vector& position);
    2727
    28   void drawTree(int depth, int drawMode) const;
     28  void drawTree() const;
    2929  inline Material* getMaterial(int indexNode) const { return this->materials[indexNode % 4]; }
    3030
     
    3838   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
     43
    4044   Material**                      materials;             //!< materials for debug drawing purposes
    4145
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc

    r4921 r4922  
    135135
    136136
     137/**
     138
     139 */
    137140void QuadtreeNode::buildHashTable(QuadtreeNode** nodeList, int* index)
    138141{
     
    362365  Vector center = *this->pDimension->getCenter();
    363366  float ax = this->pDimension->getAxis();
     367
    364368  if( v.x > center.x - ax && v.x < center.x + ax &&
    365369      v.z > center.z - ax && v.z < center.z + ax )
    366     printf("THIS POINT IS INSIDE :) \n");
    367   else
    368     printf("POINT IS NOT INSIEDE\n");
    369   this->bDraw = true;
    370 }
     370  {
     371    this->bDraw = true;
     372    return true;
     373  }
     374  return false;
     375}
     376
    371377
    372378/**
    373379 *  draws the debug quadtree boxes around the model
    374380 */
    375 void QuadtreeNode::drawTree(int depth, int drawMode) const
     381void QuadtreeNode::drawTree() const
    376382{
    377383  if( this->treeDepth == this->maxDepth)
     
    381387    float h = 50.0f;
    382388
    383     //printf("draw @ %f, %f to %f, %f", t1.x + ax, t1.z + ax, t1.x - ax, t1.z - ax);
    384 
    385389    this->quadtree->getMaterial(this->indexNode)->select();
    386390    glBegin(GL_QUADS);
    387     glVertex3f(t1.x + ax, h - depth * 10.0f, t1.z + ax);
    388     glVertex3f(t1.x - ax, h - depth * 10.0f, t1.z + ax);
    389     glVertex3f(t1.x - ax, h - depth * 10.0f, t1.z - ax);
    390     glVertex3f(t1.x + ax, h - depth * 10.0f, t1.z - ax);
     391    glVertex3f(t1.x + ax, h - this->treeDepth * 10.0f, t1.z + ax);
     392    glVertex3f(t1.x - ax, h - this->treeDepth * 10.0f, t1.z + ax);
     393    glVertex3f(t1.x - ax, h - this->treeDepth * 10.0f, t1.z - ax);
     394    glVertex3f(t1.x + ax, h - this->treeDepth * 10.0f, t1.z - ax);
    391395    glEnd();
    392396  }
     
    394398
    395399  if( this->nodeA != NULL)
    396     this->nodeA->drawTree(depth - 1, drawMode);
     400    this->nodeA->drawTree();
    397401  if( this->nodeB != NULL)
    398     this->nodeB->drawTree(depth - 1, drawMode);
     402    this->nodeB->drawTree();
    399403  if( this->nodeC != NULL)
    400     this->nodeC->drawTree(depth - 1, drawMode);
     404    this->nodeC->drawTree();
    401405  if( this->nodeD != NULL)
    402     this->nodeD->drawTree(depth - 1, drawMode);
    403 }
     406    this->nodeD->drawTree();
     407}
     408
    404409
    405410void QuadtreeNode::draw() const
     
    411416  float h = 70.0f;
    412417
    413     //printf("draw @ %f, %f to %f, %f", t1.x + ax, t1.z + ax, t1.x - ax, t1.z - ax);
    414 
    415418  glBegin(GL_QUADS);
    416419  this->quadtree->getMaterial(this->indexNode)->select();
    417 //   for( int i = 0; i < 50; ++i)
    418 //   {
    419   int i = 0;
    420     glVertex3f(t1.x + ax, h + 10.0f * i, t1.z + ax);
    421     glVertex3f(t1.x - ax, h + 10.0f * i, t1.z + ax);
    422     glVertex3f(t1.x - ax, h + 10.0f * i, t1.z - ax);
    423     glVertex3f(t1.x + ax, h + 10.0f * i, t1.z - ax);
    424 //   }
     420
     421  glVertex3f(t1.x + ax, h, t1.z + ax);
     422  glVertex3f(t1.x - ax, h, t1.z + ax);
     423  glVertex3f(t1.x - ax, h, t1.z - ax);
     424  glVertex3f(t1.x + ax, h, t1.z - ax);
     425
    425426  glEnd();
    426427
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h

    r4921 r4922  
    3434    bool includesPoint(const Vector& v);
    3535
    36     void drawTree(int depth, int drawMode) const;
     36    void drawTree() const;
    3737    void draw() const;
    3838
  • orxonox/trunk/src/lib/graphics/spatial_separation/spatial_separation.cc

    r4921 r4922  
    9999Quadtree* SpatialSeparation::createQuadtree(AbstractModel* model)
    100100{
    101   this->quadtree = new Quadtree(model->getModelInfo(), 5);
     101  this->quadtree = new Quadtree(model->getModelInfo(), 4);
    102102
    103103  return this->quadtree;
    104104}
    105 
    106 
    107 
    108 
    109 
    110105
    111106
     
    116111    return;
    117112
    118   this->quadtree->drawTree(4, 0);
     113  this->quadtree->drawTree();
    119114}
    120115
Note: See TracChangeset for help on using the changeset viewer.