Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4920 in orxonox.OLD for orxonox/trunk/src/lib/graphics


Ignore:
Timestamp:
Jul 21, 2005, 2:33:32 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: now the right quadtree is selected, position to quadtreeNode mapping works

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

Legend:

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

    r4917 r4920  
    5757     this->rootNode->buildHashTable(this->nodes, index);
    5858   }
     59   this->sortHashTable(this->nodes);
    5960   this->revertHashTable(this->nodes);
     61
     62   for(int i = 0; i < (int)pow(4, treeDepth); ++i)
     63   {
     64     printf("node %i, %f, %f \n", i, this->nodes[i]->getDimension()->getCenter()->x, this->nodes[i]->getDimension()->getCenter()->z);
     65   }
    6066}
    6167
     
    103109
    104110
     111void Quadtree::sortHashTable(QuadtreeNode** nodes)
     112{
     113  int                  len         = (int)pow(2, this->treeDepth);          //!< the length of a quadtree side
     114  float a,b;
     115  QuadtreeNode* tmpNode;
     116
     117  for(int i = 0; i < len; ++i)
     118  {
     119    for(int j = 0; j < len; ++j)
     120    {
     121      for(int k = j + 1; k < len; ++k)
     122      {
     123        a = this->nodes[i * len + j]->getDimension()->getCenter()->z;
     124        b = this->nodes[i * len + k]->getDimension()->getCenter()->z;
     125
     126        if( b > a)
     127        {
     128          tmpNode = this->nodes[i * len + j];
     129          this->nodes[i * len + j] = this->nodes[i * len + k];
     130          this->nodes[i * len + k] = tmpNode;
     131        }
     132      }
     133
     134    }
     135
     136  }
     137}
     138
     139
     140
    105141QuadtreeNode* Quadtree::getQuadtreeFromPosition(const Vector& position)
    106142{
     
    108144  Rectangle* r = this->rootNode->getDimension();
    109145  float len = this->nodes[0]->getDimension()->getAxis() * 2.0f;
     146
     147  Vector edge;
    110148  float xOff = r->getCenter()->x - r->getAxis();
    111149  float yOff = r->getCenter()->z - r->getAxis();
     150  edge.x = xOff, edge.z = yOff;
    112151
    113   int i = (int)(( position.x - xOff) / len) + 1;
    114   int j = (int)(( position.z - yOff) / len) + 1;
     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);
    115157
    116   printf("the array coordinates are: %i, %i\n", i, j);
     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    this->nodes[i + j * max]->drawTree(0,0);
     165    this->nodes[i + j * max]->includesPoint(position);
     166  }
     167  else
     168    printf("object has left terrain\n");
     169
    117170}
    118171
     
    126179  for(int i = 0; i < (int)pow(4, this->treeDepth); ++i)
    127180  {
    128     this->nodes[i]->drawTree(0, 0);
     181    //this->nodes[i]->drawTree(0, 0);
    129182  }
    130183
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h

    r4915 r4920  
    3131  private:
    3232    void revertHashTable(QuadtreeNode** nodes);
     33    void sortHashTable(QuadtreeNode** nodes);
    3334
    3435 private:
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc

    r4918 r4920  
    357357
    358358
     359bool QuadtreeNode::includesPoint(const Vector& v)
     360{
     361  Vector center = *this->pDimension->getCenter();
     362  float ax = this->pDimension->getAxis();
     363  if( v.x > center.x - ax && v.x < center.x + ax &&
     364      v.z > center.z - ax && v.z < center.z + ax )
     365    printf("THIS POINT IS INSIDE :) \n");
     366  else
     367    printf("POINT IS NOT INSIEDE\n");
     368}
     369
    359370/**
    360371 *  draws the debug quadtree boxes around the model
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h

    r4917 r4920  
    3131    float getHeight(const Vector& position);
    3232    Rectangle* getDimension() { return this->pDimension; }
     33
     34    bool includesPoint(const Vector& v);
    3335
    3436    void drawTree(int depth, int drawMode) const;
Note: See TracChangeset for help on using the changeset viewer.