Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4968 in orxonox.OLD


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

Location:
orxonox/trunk/src
Files:
6 edited

Legend:

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

    r4924 r4968  
    1919#include "obb_tree.h"
    2020#include "debug.h"
    21 #include "abstract_model.h"
    2221#include "list.h"
    2322
     23#include "abstract_model.h"
    2424#include "world_entity.h"
    2525#include "terrain.h"
     
    104104{
    105105  Quadtree* q = this->terrain->ssp->getQuadtree();
    106   q->getQuadtreeFromPosition(this->player->getAbsCoor());
     106
     107  QuadtreeNode* n = q->getQuadtreeFromPosition(this->player->getAbsCoor());
     108
     109  //sTriangleExt* tri = q->getTriangleFromPosition(this->player->getAbsCoor());
    107110}
    108111
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.cc

    r4956 r4968  
    168168
    169169  /* check if object is still inside the terrain - this check is not complete @todo check all 4 bounds */
    170   if( i < this->maxIndex && j < this->maxIndex)
    171     this->nodes[i + j * this->maxIndex]->includesPoint(position);
    172   else
    173     PRINTF(5)("Object has left terrain\n");
     170  if( i < this->maxIndex && j < this->maxIndex && i >= 0 && j >= 0)
     171    return this->nodes[i + j * this->maxIndex];
     172
     173
     174  PRINTF(4)("Object has left terrain\n");
     175  return NULL;
    174176}
    175177
     
    185187{
    186188  QuadtreeNode* q = this->getQuadtreeFromPosition(position);
    187   return q->getTriangle(position);
     189
     190  if( likely(q != NULL))
     191    return q->getTriangle(position - *this->offset);
     192  return NULL;
    188193}
    189194
  • 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}
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h

    r4956 r4968  
    3838    inline Rectangle* getDimension() { return this->pDimension; }
    3939
    40     bool includesPoint(const Vector& v);
     40    bool includesPoint(const Vector& v) const;
    4141    sTriangleExt* getTriangle(const Vector& position) const;
    4242    float getHeight(const Vector& position) const;
     
    6363    QuadtreeNode*                   nodeC;              //!< reference to the node C
    6464    QuadtreeNode*                   nodeD;              //!< reference to the node D
    65     QuadtreeNode**                  nodes;              //!< reference to the quadtree nodes
     65    QuadtreeNode**                  nodes;              //!< reference to the quadtree nodes (nodeA, nodeB, nodeC, nodeD=[0..3])
    6666
    6767
  • orxonox/trunk/src/lib/graphics/spatial_separation/spatial_separation.cc

    r4923 r4968  
    6161SpatialSeparation::~SpatialSeparation ()
    6262{
     63  if( this->quadtree)
     64    delete this->quadtree;
    6365}
    6466
  • orxonox/trunk/src/story_entities/world.cc

    r4967 r4968  
    963963
    964964  SoundEngine::getInstance()->update();
    965 // music->update();
     965 // music->update();
    966966}
    967967
Note: See TracChangeset for help on using the changeset viewer.