- Timestamp:
- Jul 25, 2005, 9:01:08 PM (19 years ago)
- 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 159 159 this function will return the quadtree that contains the position 160 160 */ 161 QuadtreeNode* Quadtree::getQuadtreeFromPosition(const Vector& position) 161 QuadtreeNode* Quadtree::getQuadtreeFromPosition(const Vector& position) const 162 162 { 163 163 /* shift into model space */ … … 182 182 this function will return the quadtree that contains the position 183 183 */ 184 sTriangleExt* Quadtree::getTriangleFromPosition(const Vector& position) 184 sTriangleExt* Quadtree::getTriangleFromPosition(const Vector& position) const 185 185 { 186 186 QuadtreeNode* q = this->getQuadtreeFromPosition(position); -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree.h
r4929 r4956 27 27 virtual ~Quadtree(); 28 28 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; 31 31 32 32 void drawTree() const; -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc
r4929 r4956 389 389 390 390 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 392 float 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 */ 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))) 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 */ 449 bool QuadtreeNode::pointInTriangle(const Vector&p, const Vector& a, const Vector& b, const Vector& c) const 397 450 { 398 451 if( this->sameSide(p, a, b, c) && this->sameSide(p, b, a, c) && sameSide(p, c, a, b)) 399 452 return true; 400 453 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 */ 464 bool QuadtreeNode::sameSide(const Vector& p1, const Vector&p2, const Vector& a, const Vector& b) const 411 465 { 412 466 Vector cp1 = (b - a).cross(p1 - a); -
orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.h
r4929 r4956 36 36 37 37 void buildHashTable(QuadtreeNode** nodeList, int* index); 38 inline Rectangle* getDimension() { return this->pDimension; } 39 38 40 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 42 44 43 45 void drawTree() const; … … 52 54 Rectangle* getDimFromModel(); 53 55 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; 56 58 57 59 protected:
Note: See TracChangeset
for help on using the changeset viewer.