Changeset 2430 for code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
- Timestamp:
- Dec 13, 2008, 11:45:51 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp
r2192 r2430 19 19 #include "LinearMath/btIDebugDraw.h" 20 20 21 22 btQuantizedBvh::btQuantizedBvh() : m_useQuantization(false), 21 #define RAYAABB2 22 23 btQuantizedBvh::btQuantizedBvh() : 24 m_bulletVersion(BT_BULLET_VERSION), 25 m_useQuantization(false), 23 26 //m_traversalMode(TRAVERSAL_STACKLESS_CACHE_FRIENDLY) 24 27 m_traversalMode(TRAVERSAL_STACKLESS) 25 28 //m_traversalMode(TRAVERSAL_RECURSIVE) 26 29 ,m_subtreeHeaderCount(0) //PCK: add this line 27 { 28 30 { 31 m_bvhAabbMin.setValue(-SIMD_INFINITY,-SIMD_INFINITY,-SIMD_INFINITY); 32 m_bvhAabbMax.setValue(SIMD_INFINITY,SIMD_INFINITY,SIMD_INFINITY); 29 33 } 30 34 … … 120 124 int curIndex = m_curNodeIndex; 121 125 122 assert(numIndices>0);126 btAssert(numIndices>0); 123 127 124 128 if (numIndices==1) … … 141 145 int internalNodeIndex = m_curNodeIndex; 142 146 143 setInternalNodeAabbMax(m_curNodeIndex,m_bvhAabbMin); 144 setInternalNodeAabbMin(m_curNodeIndex,m_bvhAabbMax); 147 //set the min aabb to 'inf' or a max value, and set the max aabb to a -inf/minimum value. 148 //the aabb will be expanded during buildTree/mergeInternalNodeAabb with actual node values 149 setInternalNodeAabbMin(m_curNodeIndex,m_bvhAabbMax);//can't use btVector3(SIMD_INFINITY,SIMD_INFINITY,SIMD_INFINITY)) because of quantization 150 setInternalNodeAabbMax(m_curNodeIndex,m_bvhAabbMin);//can't use btVector3(-SIMD_INFINITY,-SIMD_INFINITY,-SIMD_INFINITY)) because of quantization 151 145 152 146 153 for (i=startIndex;i<endIndex;i++) … … 178 185 updateSubtreeHeaders(leftChildNodexIndex,rightChildNodexIndex); 179 186 } 187 } else 188 { 189 180 190 } 181 191 … … 339 349 int maxIterations = 0; 340 350 351 341 352 void btQuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const 342 353 { … … 353 364 { 354 365 //catch bugs in tree data 355 assert (walkIterations < m_curNodeIndex);366 btAssert (walkIterations < m_curNodeIndex); 356 367 357 368 walkIterations++; … … 435 446 436 447 448 void btQuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const 449 { 450 btAssert(!m_useQuantization); 451 452 const btOptimizedBvhNode* rootNode = &m_contiguousNodes[0]; 453 int escapeIndex, curIndex = 0; 454 int walkIterations = 0; 455 bool isLeafNode; 456 //PCK: unsigned instead of bool 457 unsigned aabbOverlap=0; 458 unsigned rayBoxOverlap=0; 459 btScalar lambda_max = 1.0; 460 461 /* Quick pruning by quantized box */ 462 btVector3 rayAabbMin = raySource; 463 btVector3 rayAabbMax = raySource; 464 rayAabbMin.setMin(rayTarget); 465 rayAabbMax.setMax(rayTarget); 466 467 /* Add box cast extents to bounding box */ 468 rayAabbMin += aabbMin; 469 rayAabbMax += aabbMax; 470 471 #ifdef RAYAABB2 472 btVector3 rayFrom = raySource; 473 btVector3 rayDir = (rayTarget-raySource); 474 rayDir.normalize (); 475 lambda_max = rayDir.dot(rayTarget-raySource); 476 ///what about division by zero? --> just set rayDirection[i] to 1.0 477 btVector3 rayDirectionInverse; 478 rayDirectionInverse[0] = rayDir[0] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[0]; 479 rayDirectionInverse[1] = rayDir[1] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[1]; 480 rayDirectionInverse[2] = rayDir[2] == btScalar(0.0) ? btScalar(1e30) : btScalar(1.0) / rayDir[2]; 481 unsigned int sign[3] = { rayDirectionInverse[0] < 0.0, rayDirectionInverse[1] < 0.0, rayDirectionInverse[2] < 0.0}; 482 #endif 483 484 btVector3 bounds[2]; 485 486 while (curIndex < m_curNodeIndex) 487 { 488 btScalar param = 1.0; 489 //catch bugs in tree data 490 btAssert (walkIterations < m_curNodeIndex); 491 492 walkIterations++; 493 494 bounds[0] = rootNode->m_aabbMinOrg; 495 bounds[1] = rootNode->m_aabbMaxOrg; 496 /* Add box cast extents */ 497 bounds[0] += aabbMin; 498 bounds[1] += aabbMax; 499 500 aabbOverlap = TestAabbAgainstAabb2(rayAabbMin,rayAabbMax,rootNode->m_aabbMinOrg,rootNode->m_aabbMaxOrg); 501 //perhaps profile if it is worth doing the aabbOverlap test first 502 503 #ifdef RAYAABB2 504 ///careful with this check: need to check division by zero (above) and fix the unQuantize method 505 ///thanks Joerg/hiker for the reproduction case! 506 ///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858 507 rayBoxOverlap = aabbOverlap ? btRayAabb2 (raySource, rayDirectionInverse, sign, bounds, param, 0.0f, lambda_max) : false; 508 509 #else 510 btVector3 normal; 511 rayBoxOverlap = btRayAabb(raySource, rayTarget,bounds[0],bounds[1],param, normal); 512 #endif 513 514 isLeafNode = rootNode->m_escapeIndex == -1; 515 516 //PCK: unsigned instead of bool 517 if (isLeafNode && (rayBoxOverlap != 0)) 518 { 519 nodeCallback->processNode(rootNode->m_subPart,rootNode->m_triangleIndex); 520 } 521 522 //PCK: unsigned instead of bool 523 if ((rayBoxOverlap != 0) || isLeafNode) 524 { 525 rootNode++; 526 curIndex++; 527 } else 528 { 529 escapeIndex = rootNode->m_escapeIndex; 530 rootNode += escapeIndex; 531 curIndex += escapeIndex; 532 } 533 } 534 if (maxIterations < walkIterations) 535 maxIterations = walkIterations; 536 537 } 538 437 539 438 540 … … 455 557 456 558 btScalar lambda_max = 1.0; 457 #define RAYAABB2 559 458 560 #ifdef RAYAABB2 459 561 btVector3 rayFrom = raySource; … … 503 605 504 606 //catch bugs in tree data 505 assert (walkIterations < subTreeSize);607 btAssert (walkIterations < subTreeSize); 506 608 507 609 walkIterations++; … … 534 636 ///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858 535 637 638 //BT_PROFILE("btRayAabb2"); 536 639 rayBoxOverlap = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0f, lambda_max); 640 537 641 #else 538 642 rayBoxOverlap = true;//btRayAabb(raySource, rayTarget, bounds[0], bounds[1], param, normal); … … 598 702 599 703 //catch bugs in tree data 600 assert (walkIterations < subTreeSize);704 btAssert (walkIterations < subTreeSize); 601 705 602 706 walkIterations++; … … 653 757 void btQuantizedBvh::reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const 654 758 { 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 } 759 reportBoxCastOverlappingNodex(nodeCallback,raySource,rayTarget,btVector3(0,0,0),btVector3(0,0,0)); 667 760 } 668 761 … … 670 763 void btQuantizedBvh::reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin,const btVector3& aabbMax) const 671 764 { 672 bool fast_path = m_useQuantization && m_traversalMode == TRAVERSAL_STACKLESS; 673 if (fast_path) 765 //always use stackless 766 767 if (m_useQuantization) 674 768 { 675 769 walkStacklessQuantizedTreeAgainstRay(nodeCallback, raySource, rayTarget, aabbMin, aabbMax, 0, m_curNodeIndex); 676 } else { 677 /* Slow path: 678 Construct the bounding box for the entire box cast and send that down the tree */ 770 } 771 else 772 { 773 walkStacklessTreeAgainstRay(nodeCallback, raySource, rayTarget, aabbMin, aabbMax, 0, m_curNodeIndex); 774 } 775 /* 776 { 777 //recursive traversal 679 778 btVector3 qaabbMin = raySource; 680 779 btVector3 qaabbMax = raySource; … … 685 784 reportAabbOverlappingNodex(nodeCallback,qaabbMin,qaabbMax); 686 785 } 786 */ 787 687 788 } 688 789 … … 744 845 bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian) 745 846 { 746 assert(m_subtreeHeaderCount == m_SubtreeHeaders.size());847 btAssert(m_subtreeHeaderCount == m_SubtreeHeaders.size()); 747 848 m_subtreeHeaderCount = m_SubtreeHeaders.size(); 748 849 … … 1038 1139 m_bvhAabbMin(self.m_bvhAabbMin), 1039 1140 m_bvhAabbMax(self.m_bvhAabbMax), 1040 m_bvhQuantization(self.m_bvhQuantization) 1041 { 1042 1043 1044 } 1045 1046 1047 1141 m_bvhQuantization(self.m_bvhQuantization), 1142 m_bulletVersion(BT_BULLET_VERSION) 1143 { 1144 1145 } 1146 1147 1148
Note: See TracChangeset
for help on using the changeset viewer.