Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 4956 in orxonox.OLD for orxonox/trunk/src/lib


Ignore:
Timestamp:
Jul 25, 2005, 9:01:08 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: added the last functions needed to get the heigt from the terrain. test phase now

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

Legend:

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

    r4949 r4956  
    159159  this function will return the quadtree that contains the position
    160160 */
    161 QuadtreeNode* Quadtree::getQuadtreeFromPosition(const Vector& position)
     161QuadtreeNode* Quadtree::getQuadtreeFromPosition(const Vector& position) const
    162162{
    163163  /* shift into model space */
     
    182182  this function will return the quadtree that contains the position
    183183 */
    184 sTriangleExt* Quadtree::getTriangleFromPosition(const Vector& position)
     184sTriangleExt* Quadtree::getTriangleFromPosition(const Vector& position) const
    185185{
    186186  QuadtreeNode* q = this->getQuadtreeFromPosition(position);
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h

    r4929 r4956  
    2727    virtual ~Quadtree();
    2828
    29     QuadtreeNode* getQuadtreeFromPosition(const Vector& position);
    30     sTriangleExt* getTriangleFromPosition(const Vector& position);
     29    QuadtreeNode* getQuadtreeFromPosition(const Vector& position) const;
     30    sTriangleExt* getTriangleFromPosition(const Vector& position) const;
    3131
    3232    void drawTree() const;
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc

    r4929 r4956  
    389389
    390390
    391 sTriangleExt* QuadtreeNode::getTriangle(const Vector& position)
    392 {
    393 
    394 }
    395 
    396 bool QuadtreeNode::pointInTriangle(const Vector&p, const Vector& a, const Vector& b, const Vector& c)
     391
     392float QuadtreeNode::getHeight(const Vector& position) const
     393{
     394  Vector a, b, c;
     395  sTriangleExt* tri;
     396
     397  for( int i = 0; i < this->numTriangles; ++i)
     398    {
     399      a = *(sVec3D*)&this->pVertices[this->pTriangles[i]->indexToVertices[0]];
     400      b = *(sVec3D*)&this->pVertices[this->pTriangles[i]->indexToVertices[1]];
     401      c = *(sVec3D*)&this->pVertices[this->pTriangles[i]->indexToVertices[2]];
     402     
     403      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*/
     424sTriangleExt* 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)))
     435        return this->pTriangles[i];
     436    }
     437  return NULL;
     438}
     439
     440
     441/**
     442 *  checks if the point is in the triangle
     443 * @param point to be checked
     444 * @param rectangle edge a
     445 * @param rectangle edge b
     446 * @param rectangle edge c
     447 * @returns true if the point is inside
     448*/
     449bool QuadtreeNode::pointInTriangle(const Vector&p, const Vector& a, const Vector& b, const Vector& c) const
    397450{
    398451  if( this->sameSide(p, a, b, c) && this->sameSide(p, b, a, c) && sameSide(p, c, a, b))
    399452    return true;
    400453  return false;
    401   /*
    402   function PointInTriangle(p, a,b,c)
    403   if SameSide(p,a, b,c) and SameSide(p,b, a,c)
    404   and SameSide(p,c, a,b) then return true
    405   else return false
    406   */
    407 }
    408 
    409 
    410 bool QuadtreeNode::sameSide(const Vector& p1, const Vector&p2, const Vector& a, const Vector& b)
     454}
     455
     456
     457/**
     458 *  checks if two points are on the same side
     459 * @param point one to be checked
     460 * @param point two to be checked
     461 * @param begining point of the line
     462 * @param end of the line
     463*/
     464bool QuadtreeNode::sameSide(const Vector& p1, const Vector&p2, const Vector& a, const Vector& b) const
    411465{
    412466  Vector cp1 = (b - a).cross(p1 - a);
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h

    r4929 r4956  
    3636
    3737    void buildHashTable(QuadtreeNode** nodeList, int* index);
     38    inline Rectangle* getDimension() { return this->pDimension; }
     39
    3840    bool includesPoint(const Vector& v);
    39     sTriangleExt* getTriangle(const Vector& position);
    40     float getHeight(const Vector& position);
    41     inline Rectangle* getDimension() { return this->pDimension; }
     41    sTriangleExt* getTriangle(const Vector& position) const;
     42    float getHeight(const Vector& position) const;
     43
    4244
    4345    void drawTree() const;
     
    5254    Rectangle* getDimFromModel();
    5355
    54     bool sameSide(const Vector& p1, const Vector&p2, const Vector& a, const Vector& b);
    55     bool pointInTriangle(const Vector&p, const Vector& a, const Vector& b, const Vector& c);
     56    bool sameSide(const Vector& p1, const Vector&p2, const Vector& a, const Vector& b) const;
     57    bool pointInTriangle(const Vector&p, const Vector& a, const Vector& b, const Vector& c) const;
    5658
    5759  protected:
Note: See TracChangeset for help on using the changeset viewer.