Changeset 1972 for code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
- Timestamp:
- Oct 20, 2008, 5:40:38 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
r1963 r1972 19 19 #include "LinearMath/btIDebugDraw.h" 20 20 21 #define RAYAABB222 21 23 22 btQuantizedBvh::btQuantizedBvh() : m_useQuantization(false), … … 26 25 //m_traversalMode(TRAVERSAL_RECURSIVE) 27 26 ,m_subtreeHeaderCount(0) //PCK: add this line 28 { 29 m_bvhAabbMin.setValue(-SIMD_INFINITY,-SIMD_INFINITY,-SIMD_INFINITY); 30 m_bvhAabbMax.setValue(SIMD_INFINITY,SIMD_INFINITY,SIMD_INFINITY); 27 { 28 31 29 } 32 30 … … 122 120 int curIndex = m_curNodeIndex; 123 121 124 btAssert(numIndices>0);122 assert(numIndices>0); 125 123 126 124 if (numIndices==1) … … 143 141 int internalNodeIndex = m_curNodeIndex; 144 142 145 //set the min aabb to 'inf' or a max value, and set the max aabb to a -inf/minimum value. 146 //the aabb will be expanded during buildTree/mergeInternalNodeAabb with actual node values 147 setInternalNodeAabbMin(m_curNodeIndex,m_bvhAabbMax);//can't use btVector3(SIMD_INFINITY,SIMD_INFINITY,SIMD_INFINITY)) because of quantization 148 setInternalNodeAabbMax(m_curNodeIndex,m_bvhAabbMin);//can't use btVector3(-SIMD_INFINITY,-SIMD_INFINITY,-SIMD_INFINITY)) because of quantization 149 143 setInternalNodeAabbMax(m_curNodeIndex,m_bvhAabbMin); 144 setInternalNodeAabbMin(m_curNodeIndex,m_bvhAabbMax); 150 145 151 146 for (i=startIndex;i<endIndex;i++) … … 183 178 updateSubtreeHeaders(leftChildNodexIndex,rightChildNodexIndex); 184 179 } 185 } else186 {187 188 180 } 189 181 … … 347 339 int maxIterations = 0; 348 340 349 350 341 void btQuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const 351 342 { … … 362 353 { 363 354 //catch bugs in tree data 364 btAssert (walkIterations < m_curNodeIndex);355 assert (walkIterations < m_curNodeIndex); 365 356 366 357 walkIterations++; … … 444 435 445 436 446 void btQuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const447 {448 btAssert(!m_useQuantization);449 450 const btOptimizedBvhNode* rootNode = &m_contiguousNodes[0];451 int escapeIndex, curIndex = 0;452 int walkIterations = 0;453 bool isLeafNode;454 //PCK: unsigned instead of bool455 unsigned aabbOverlap=0;456 unsigned rayBoxOverlap=0;457 btScalar lambda_max = 1.0;458 459 /* Quick pruning by quantized box */460 btVector3 rayAabbMin = raySource;461 btVector3 rayAabbMax = raySource;462 rayAabbMin.setMin(rayTarget);463 rayAabbMax.setMax(rayTarget);464 465 /* Add box cast extents to bounding box */466 rayAabbMin += aabbMin;467 rayAabbMax += aabbMax;468 469 #ifdef RAYAABB2470 btVector3 rayFrom = raySource;471 btVector3 rayDir = (rayTarget-raySource);472 rayDir.normalize ();473 lambda_max = rayDir.dot(rayTarget-raySource);474 ///what about division by zero? --> just set rayDirection[i] to 1.0475 btVector3 rayDirectionInverse;476 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[0];477 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[1];478 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[2];479 unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0};480 #endif481 482 btVector3 bounds[2];483 484 while (curIndex < m_curNodeIndex)485 {486 btScalar param = 1.0;487 //catch bugs in tree data488 btAssert (walkIterations < m_curNodeIndex);489 490 walkIterations++;491 492 bounds[0] = rootNode->m_aabbMinOrg;493 bounds[1] = rootNode->m_aabbMaxOrg;494 /* Add box cast extents */495 bounds[0] += aabbMin;496 bounds[1] += aabbMax;497 498 aabbOverlap = TestAabbAgainstAabb2(rayAabbMin,rayAabbMax,rootNode->m_aabbMinOrg,rootNode->m_aabbMaxOrg);499 //perhaps profile if it is worth doing the aabbOverlap test first500 501 #ifdef RAYAABB2502 ///careful with this check: need to check division by zero (above) and fix the unQuantize method503 ///thanks Joerg/hiker for the reproduction case!504 ///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858505 rayBoxOverlap = aabbOverlap ? btRayAabb2 (raySource, rayDirectionInverse, sign, bounds, param, 0.0f, lambda_max) : false;506 507 #else508 btVector3 normal;509 rayBoxOverlap = btRayAabb(raySource, rayTarget,bounds[0],bounds[1],param, normal);510 #endif511 512 isLeafNode = rootNode->m_escapeIndex == -1;513 514 //PCK: unsigned instead of bool515 if (isLeafNode && (rayBoxOverlap != 0))516 {517 nodeCallback->processNode(rootNode->m_subPart,rootNode->m_triangleIndex);518 }519 520 //PCK: unsigned instead of bool521 if ((rayBoxOverlap != 0) || isLeafNode)522 {523 rootNode++;524 curIndex++;525 } else526 {527 escapeIndex = rootNode->m_escapeIndex;528 rootNode += escapeIndex;529 curIndex += escapeIndex;530 }531 }532 if (maxIterations < walkIterations)533 maxIterations = walkIterations;534 535 }536 537 437 538 438 … … 555 455 556 456 btScalar lambda_max = 1.0; 557 457 #define RAYAABB2 558 458 #ifdef RAYAABB2 559 459 btVector3 rayFrom = raySource; … … 603 503 604 504 //catch bugs in tree data 605 btAssert (walkIterations < subTreeSize);505 assert (walkIterations < subTreeSize); 606 506 607 507 walkIterations++; … … 634 534 ///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858 635 535 636 //BT_PROFILE("btRayAabb2");637 536 rayBoxOverlap = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0f, lambda_max); 638 639 537 #else 640 538 rayBoxOverlap = true;//btRayAabb(raySource, rayTarget, bounds[0], bounds[1], param, normal); … … 700 598 701 599 //catch bugs in tree data 702 btAssert (walkIterations < subTreeSize);600 assert (walkIterations < subTreeSize); 703 601 704 602 walkIterations++; … … 755 653 void btQuantizedBvh::reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const 756 654 { 757 reportBoxCastOverlappingNodex(nodeCallback,raySource,rayTarget,btVector3(0,0,0),btVector3(0,0,0)); 655 bool fast_path = m_useQuantization && m_traversalMode == TRAVERSAL_STACKLESS; 656 if (fast_path) 657 { 658 walkStacklessQuantizedTreeAgainstRay(nodeCallback, raySource, rayTarget, btVector3(0, 0, 0), btVector3(0, 0, 0), 0, m_curNodeIndex); 659 } else { 660 /* Otherwise fallback to AABB overlap test */ 661 btVector3 aabbMin = raySource; 662 btVector3 aabbMax = raySource; 663 aabbMin.setMin(rayTarget); 664 aabbMax.setMax(rayTarget); 665 reportAabbOverlappingNodex(nodeCallback,aabbMin,aabbMax); 666 } 758 667 } 759 668 … … 761 670 void btQuantizedBvh::reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin,const btVector3& aabbMax) const 762 671 { 763 //always use stackless 764 765 if (m_useQuantization) 672 bool fast_path = m_useQuantization && m_traversalMode == TRAVERSAL_STACKLESS; 673 if (fast_path) 766 674 { 767 675 walkStacklessQuantizedTreeAgainstRay(nodeCallback, raySource, rayTarget, aabbMin, aabbMax, 0, m_curNodeIndex); 768 } 769 else 770 { 771 walkStacklessTreeAgainstRay(nodeCallback, raySource, rayTarget, aabbMin, aabbMax, 0, m_curNodeIndex); 772 } 773 /* 774 { 775 //recursive traversal 676 } else { 677 /* Slow path: 678 Construct the bounding box for the entire box cast and send that down the tree */ 776 679 btVector3 qaabbMin = raySource; 777 680 btVector3 qaabbMax = raySource; … … 782 685 reportAabbOverlappingNodex(nodeCallback,qaabbMin,qaabbMax); 783 686 } 784 */785 786 687 } 787 688 … … 843 744 bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian) 844 745 { 845 btAssert(m_subtreeHeaderCount == m_SubtreeHeaders.size());746 assert(m_subtreeHeaderCount == m_SubtreeHeaders.size()); 846 747 m_subtreeHeaderCount = m_SubtreeHeaders.size(); 847 748
Note: See TracChangeset
for help on using the changeset viewer.