Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 29, 2005, 12:20:03 AM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: some fixeds in the quadtree framework. No debug draw anymore

File:
1 edited

Legend:

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

    r4957 r4968  
    134134  if( this->nodeD != NULL)
    135135    delete this->nodeD;
     136
     137  if( this->pTriangles)
     138    delete [] this->pTriangles;
     139
     140  if( this->pDimension)
     141    delete this->pDimension;
    136142}
    137143
     
    374380 * @returns true if the vector is included
    375381  */
    376 bool QuadtreeNode::includesPoint(const Vector& v)
     382bool QuadtreeNode::includesPoint(const Vector& v) const
    377383{
    378384  Vector center = *this->pDimension->getCenter();
     
    381387  if( v.x > center.x - ax && v.x < center.x + ax &&
    382388      v.z > center.z - ax && v.z < center.z + ax )
    383   {
    384     this->bDraw = true;
    385389    return true;
    386   }
    387390  return false;
    388391}
     
    396399
    397400  for( int i = 0; i < this->numTriangles; ++i)
     401  {
     402    a = *(sVec3D*)&this->pVertices[this->pTriangles[i]->indexToVertices[0]];
     403    b = *(sVec3D*)&this->pVertices[this->pTriangles[i]->indexToVertices[1]];
     404    c = *(sVec3D*)&this->pVertices[this->pTriangles[i]->indexToVertices[2]];
     405
     406    if( unlikely(this->pointInTriangle(position, a, b, c)))
    398407    {
     408      tri = this->pTriangles[i];
     409      break;
     410    }
     411  }
     412
     413  /* calculate height out of the data collected above */
     414
     415}
     416
     417
     418/**
     419 *  get triangles that includes the position
     420 * @param position the position that is going to be checked
     421 * @returns the triangle in which the position is included, NULL if there is no such triangle
     422
     423 There is some random behaviour if there are more than one triangle at the same y
     424 coordinate. At the moment the function just takes the first triangle, that included the
     425 vector
     426 */
     427sTriangleExt* QuadtreeNode::getTriangle(const Vector& position) const
     428{
     429  Vector a, b, c;
     430  PRINTF(0)("Get Triangle, %i\n", this->numTriangles);
     431
     432  for( int i = 0; i < numTriangles; ++i)
     433    {
     434
    399435      a = *(sVec3D*)&this->pVertices[this->pTriangles[i]->indexToVertices[0]];
    400436      b = *(sVec3D*)&this->pVertices[this->pTriangles[i]->indexToVertices[1]];
     
    402438
    403439      if( unlikely(this->pointInTriangle(position, a, b, c)))
    404         {
    405           tri = this->pTriangles[i];
    406           break;
    407         }
    408     }
    409 
    410   /* calculate height out of the data collected above */
    411 
    412 }
    413 
    414 
    415 /**
    416  *  get triangles that includes the position
    417  * @param position the position that is going to be checked
    418  * @returns the triangle in which the position is included, NULL if there is no such triangle
    419 
    420  There is some random behaviour if there are more than one triangle at the same y
    421  coordinate. At the moment the function just takes the first triangle, that included the
    422  vector
    423 */
    424 sTriangleExt* QuadtreeNode::getTriangle(const Vector& position) const
    425 {
    426   Vector a, b, c;
    427 
    428   for( int i = 0; i < this->numTriangles; ++i)
    429     {
    430       a = *(sVec3D*)&this->pVertices[this->pTriangles[i]->indexToVertices[0]];
    431       b = *(sVec3D*)&this->pVertices[this->pTriangles[i]->indexToVertices[1]];
    432       c = *(sVec3D*)&this->pVertices[this->pTriangles[i]->indexToVertices[2]];
    433 
    434       if( unlikely(this->pointInTriangle(position, a, b, c)))
    435440        return this->pTriangles[i];
     441
    436442    }
    437443  return NULL;
     
    446452 * @param rectangle edge c
    447453 * @returns true if the point is inside
    448 */
     454 */
    449455bool QuadtreeNode::pointInTriangle(const Vector&p, const Vector& a, const Vector& b, const Vector& c) const
    450456{
     457
     458  PRINTF(0)("p: (%f, %f, %f)\n", p.x, p.y, p.z);
     459  PRINTF(0)("a: (%f, %f, %f)\n", a.x, a.y, a.z);
     460  PRINTF(0)("b: (%f, %f, %f)\n", b.x, b.y, b.z);
     461  PRINTF(0)("c: (%f, %f, %f)\n", c.x, c.y, c.z);
     462
    451463  if( this->sameSide(p, a, b, c) && this->sameSide(p, b, a, c) && sameSide(p, c, a, b))
    452464    return true;
     
    461473 * @param begining point of the line
    462474 * @param end of the line
    463 */
     475 */
    464476bool QuadtreeNode::sameSide(const Vector& p1, const Vector&p2, const Vector& a, const Vector& b) const
    465477{
     
    509521void QuadtreeNode::draw() const
    510522{
    511   if( likely(!bDraw))
     523  if( likely(!this->bDraw))
    512524    return;
     525
    513526  Vector t1 = *this->pDimension->getCenter();
    514527  float ax = this->pDimension->getAxis();
     
    524537
    525538  glEnd();
    526 
    527 }
     539}
Note: See TracChangeset for help on using the changeset viewer.