Changeset 8393 for code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp
- Timestamp:
- May 3, 2011, 5:07:42 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/external/bullet/BulletCollision/CollisionDispatch/btInternalEdgeUtility.cpp
r8351 r8393 2 2 3 3 #include "BulletCollision/CollisionShapes/btBvhTriangleMeshShape.h" 4 #include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h" 4 5 #include "BulletCollision/CollisionShapes/btTriangleShape.h" 5 6 #include "BulletCollision/CollisionDispatch/btCollisionObject.h" … … 9 10 10 11 //#define DEBUG_INTERNAL_EDGE 11 12 12 13 13 #ifdef DEBUG_INTERNAL_EDGE … … 457 457 return; 458 458 459 btBvhTriangleMeshShape* trimesh = (btBvhTriangleMeshShape*)colObj0->getRootCollisionShape(); 460 btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) trimesh->getTriangleInfoMap(); 459 btBvhTriangleMeshShape* trimesh = 0; 460 461 if( colObj0->getRootCollisionShape()->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE ) 462 trimesh = ((btScaledBvhTriangleMeshShape*)colObj0->getRootCollisionShape())->getChildShape(); 463 else 464 trimesh = (btBvhTriangleMeshShape*)colObj0->getRootCollisionShape(); 465 466 btTriangleInfoMap* triangleInfoMapPtr = (btTriangleInfoMap*) trimesh->getTriangleInfoMap(); 461 467 if (!triangleInfoMapPtr) 462 468 return; … … 502 508 btVector3 localContactNormalOnB = colObj0->getWorldTransform().getBasis().transpose() * cp.m_normalWorldOnB; 503 509 localContactNormalOnB.normalize();//is this necessary? 504 505 if ((info->m_edgeV0V1Angle)< SIMD_2_PI) 510 511 // Get closest edge 512 int bestedge=-1; 513 float disttobestedge=BT_LARGE_FLOAT; 514 // 515 // Edge 0 -> 1 516 if (btFabs(info->m_edgeV0V1Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) 517 { 518 btVector3 nearest; 519 btNearestPointInLineSegment( cp.m_localPointB, v0, v1, nearest ); 520 float len=(contact-nearest).length(); 521 // 522 if( len < disttobestedge ) 523 { 524 bestedge=0; 525 disttobestedge=len; 526 } 527 } 528 // Edge 1 -> 2 529 if (btFabs(info->m_edgeV1V2Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) 530 { 531 btVector3 nearest; 532 btNearestPointInLineSegment( cp.m_localPointB, v1, v2, nearest ); 533 float len=(contact-nearest).length(); 534 // 535 if( len < disttobestedge ) 536 { 537 bestedge=1; 538 disttobestedge=len; 539 } 540 } 541 // Edge 2 -> 0 542 if (btFabs(info->m_edgeV2V0Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) 543 { 544 btVector3 nearest; 545 btNearestPointInLineSegment( cp.m_localPointB, v2, v0, nearest ); 546 float len=(contact-nearest).length(); 547 // 548 if( len < disttobestedge ) 549 { 550 bestedge=2; 551 disttobestedge=len; 552 } 553 } 554 555 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW 556 btVector3 upfix=tri_normal * btVector3(0.1f,0.1f,0.1f); 557 btDebugDrawLine(tr * v0 + upfix, tr * v1 + upfix, red ); 558 #endif 559 if (btFabs(info->m_edgeV0V1Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) 506 560 { 507 561 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW … … 510 564 btScalar len = (contact-nearest).length(); 511 565 if(len<triangleInfoMapPtr->m_edgeDistanceThreshold) 566 if( bestedge==0 ) 512 567 { 513 568 btVector3 edge(v0-v1); … … 578 633 #endif //BT_INTERNAL_EDGE_DEBUG_DRAW 579 634 580 if ((info->m_edgeV1V2Angle)< SIMD_2_PI) 635 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW 636 btDebugDrawLine(tr * v1 + upfix, tr * v2 + upfix , green ); 637 #endif 638 639 if (btFabs(info->m_edgeV1V2Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) 581 640 { 582 641 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW … … 588 647 btScalar len = (contact-nearest).length(); 589 648 if(len<triangleInfoMapPtr->m_edgeDistanceThreshold) 649 if( bestedge==1 ) 590 650 { 591 651 isNearEdge = true; … … 659 719 btDebugDrawLine(tr*nearest,tr*cp.m_localPointB,blue); 660 720 #endif //BT_INTERNAL_EDGE_DEBUG_DRAW 661 662 if ((info->m_edgeV2V0Angle)< SIMD_2_PI) 721 #ifdef BT_INTERNAL_EDGE_DEBUG_DRAW 722 btDebugDrawLine(tr * v2 + upfix, tr * v0 + upfix , blue ); 723 #endif 724 725 if (btFabs(info->m_edgeV2V0Angle)< triangleInfoMapPtr->m_maxEdgeAngleThreshold) 663 726 { 664 727 … … 669 732 btScalar len = (contact-nearest).length(); 670 733 if(len<triangleInfoMapPtr->m_edgeDistanceThreshold) 734 if( bestedge==2 ) 671 735 { 672 736 isNearEdge = true; … … 760 824 } else 761 825 { 826 btVector3 newNormal = tri_normal *frontFacing; 827 //if the tri_normal is pointing opposite direction as the current local contact normal, skip it 828 btScalar d = newNormal.dot(localContactNormalOnB) ; 829 if (d< 0) 830 { 831 return; 832 } 762 833 //modify the normal to be the triangle normal (or backfacing normal) 763 cp.m_normalWorldOnB = colObj0->getWorldTransform().getBasis() *(tri_normal *frontFacing); 764 } 765 766 834 cp.m_normalWorldOnB = colObj0->getWorldTransform().getBasis() *newNormal; 835 } 836 767 837 // Reproject collision point along normal. 768 838 cp.m_positionWorldOnB = cp.m_positionWorldOnA - cp.m_normalWorldOnB * cp.m_distance1;
Note: See TracChangeset
for help on using the changeset viewer.