Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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


Ignore:
Timestamp:
Jul 21, 2005, 6:07:23 PM (19 years ago)
Author:
patrick
Message:

orxonox/trunk: implemented a point in triangle function

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

Legend:

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

    r4925 r4929  
    167167  int j = (int)(v.z / quadLength);
    168168
    169   /* check if object is still inside the terrain */
     169  /* check if object is still inside the terrain - this check is not complete @todo check all 4 bounds */
    170170  if( i < this->maxIndex && j < this->maxIndex)
    171171    this->nodes[i + j * this->maxIndex]->includesPoint(position);
     
    176176
    177177/**
     178 *  maps a position to a triangle
     179 * @param position the position so look for
     180 * @return the triangle
     181
     182  this function will return the quadtree that contains the position
     183 */
     184sTriangleExt* Quadtree::getTriangleFromPosition(const Vector& position)
     185{
     186  QuadtreeNode* q = this->getQuadtreeFromPosition(position);
     187  return q->getTriangle(position);
     188}
     189
     190
     191/**
    178192 *  draws the debug quadtree boxes around the model
    179193 */
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h

    r4924 r4929  
    2828
    2929    QuadtreeNode* getQuadtreeFromPosition(const Vector& position);
     30    sTriangleExt* getTriangleFromPosition(const Vector& position);
    3031
    3132    void drawTree() const;
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc

    r4925 r4929  
    389389
    390390
     391sTriangleExt* QuadtreeNode::getTriangle(const Vector& position)
     392{
     393
     394}
     395
     396bool QuadtreeNode::pointInTriangle(const Vector&p, const Vector& a, const Vector& b, const Vector& c)
     397{
     398  if( this->sameSide(p, a, b, c) && this->sameSide(p, b, a, c) && sameSide(p, c, a, b))
     399    return true;
     400  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
     410bool QuadtreeNode::sameSide(const Vector& p1, const Vector&p2, const Vector& a, const Vector& b)
     411{
     412  Vector cp1 = (b - a).cross(p1 - a);
     413  Vector cp2 = (b - a).cross(p2 - a);
     414
     415  if( unlikely(cp1.dot(cp2) >= 0)) return true;
     416  return false;
     417}
     418
     419
    391420/**
    392421 *  draws all the debug quadtree squares
  • orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h

    r4923 r4929  
    3737    void buildHashTable(QuadtreeNode** nodeList, int* index);
    3838    bool includesPoint(const Vector& v);
     39    sTriangleExt* getTriangle(const Vector& position);
    3940    float getHeight(const Vector& position);
    4041    inline Rectangle* getDimension() { return this->pDimension; }
     
    5152    Rectangle* getDimFromModel();
    5253
     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);
    5356
    5457  protected:
Note: See TracChangeset for help on using the changeset viewer.