Changeset 4956 in orxonox.OLD for orxonox/trunk/src/lib/graphics/spatial_separation/quadtree_node.cc
- Timestamp:
- Jul 25, 2005, 9:01:08 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note: See TracChangeset
for help on using the changeset viewer.