Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 20, 2008, 5:40:38 PM (17 years ago)
Author:
rgrieder
Message:

Downgraded Bullet to latest tagged version: 2.72
That should give us more stability.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/physics/src/bullet/BulletCollision/BroadphaseCollision/btQuantizedBvh.cpp

    r1963 r1972  
    1919#include "LinearMath/btIDebugDraw.h"
    2020
    21 #define RAYAABB2
    2221
    2322btQuantizedBvh::btQuantizedBvh() : m_useQuantization(false),
     
    2625                                        //m_traversalMode(TRAVERSAL_RECURSIVE)
    2726                                        ,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
    3129}
    3230
     
    122120        int curIndex = m_curNodeIndex;
    123121
    124         btAssert(numIndices>0);
     122        assert(numIndices>0);
    125123
    126124        if (numIndices==1)
     
    143141        int internalNodeIndex = m_curNodeIndex;
    144142       
    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);
    150145       
    151146        for (i=startIndex;i<endIndex;i++)
     
    183178                        updateSubtreeHeaders(leftChildNodexIndex,rightChildNodexIndex);
    184179                }
    185         } else
    186         {
    187 
    188180        }
    189181
     
    347339int maxIterations = 0;
    348340
    349 
    350341void    btQuantizedBvh::walkStacklessTree(btNodeOverlapCallback* nodeCallback,const btVector3& aabbMin,const btVector3& aabbMax) const
    351342{
     
    362353        {
    363354                //catch bugs in tree data
    364                 btAssert (walkIterations < m_curNodeIndex);
     355                assert (walkIterations < m_curNodeIndex);
    365356
    366357                walkIterations++;
     
    444435
    445436
    446 void    btQuantizedBvh::walkStacklessTreeAgainstRay(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin, const btVector3& aabbMax, int startNodeIndex,int endNodeIndex) const
    447 {
    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 bool
    455         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 RAYAABB2
    470         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.0
    475         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 #endif
    481 
    482         btVector3 bounds[2];
    483 
    484         while (curIndex < m_curNodeIndex)
    485         {
    486                 btScalar param = 1.0;
    487                 //catch bugs in tree data
    488                 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 first
    500 
    501 #ifdef RAYAABB2
    502                         ///careful with this check: need to check division by zero (above) and fix the unQuantize method
    503                         ///thanks Joerg/hiker for the reproduction case!
    504                         ///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858
    505                 rayBoxOverlap = aabbOverlap ? btRayAabb2 (raySource, rayDirectionInverse, sign, bounds, param, 0.0f, lambda_max) : false;
    506 
    507 #else
    508                 btVector3 normal;
    509                 rayBoxOverlap = btRayAabb(raySource, rayTarget,bounds[0],bounds[1],param, normal);
    510 #endif
    511 
    512                 isLeafNode = rootNode->m_escapeIndex == -1;
    513                
    514                 //PCK: unsigned instead of bool
    515                 if (isLeafNode && (rayBoxOverlap != 0))
    516                 {
    517                         nodeCallback->processNode(rootNode->m_subPart,rootNode->m_triangleIndex);
    518                 }
    519                
    520                 //PCK: unsigned instead of bool
    521                 if ((rayBoxOverlap != 0) || isLeafNode)
    522                 {
    523                         rootNode++;
    524                         curIndex++;
    525                 } else
    526                 {
    527                         escapeIndex = rootNode->m_escapeIndex;
    528                         rootNode += escapeIndex;
    529                         curIndex += escapeIndex;
    530                 }
    531         }
    532         if (maxIterations < walkIterations)
    533                 maxIterations = walkIterations;
    534 
    535 }
    536 
    537437
    538438
     
    555455
    556456        btScalar lambda_max = 1.0;
    557 
     457#define RAYAABB2
    558458#ifdef RAYAABB2
    559459        btVector3 rayFrom = raySource;
     
    603503
    604504                //catch bugs in tree data
    605                 btAssert (walkIterations < subTreeSize);
     505                assert (walkIterations < subTreeSize);
    606506
    607507                walkIterations++;
     
    634534                        ///http://www.bulletphysics.com/Bullet/phpBB3/viewtopic.php?f=9&t=1858
    635535
    636                         //BT_PROFILE("btRayAabb2");
    637536                        rayBoxOverlap = btRayAabb2 (raySource, rayDirection, sign, bounds, param, 0.0f, lambda_max);
    638                        
    639537#else
    640538                        rayBoxOverlap = true;//btRayAabb(raySource, rayTarget, bounds[0], bounds[1], param, normal);
     
    700598
    701599                //catch bugs in tree data
    702                 btAssert (walkIterations < subTreeSize);
     600                assert (walkIterations < subTreeSize);
    703601
    704602                walkIterations++;
     
    755653void    btQuantizedBvh::reportRayOverlappingNodex (btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget) const
    756654{
    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        }
    758667}
    759668
     
    761670void    btQuantizedBvh::reportBoxCastOverlappingNodex(btNodeOverlapCallback* nodeCallback, const btVector3& raySource, const btVector3& rayTarget, const btVector3& aabbMin,const btVector3& aabbMax) const
    762671{
    763         //always use stackless
    764 
    765         if (m_useQuantization)
     672        bool fast_path = m_useQuantization && m_traversalMode == TRAVERSAL_STACKLESS;
     673        if (fast_path)
    766674        {
    767675                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 */
    776679                btVector3 qaabbMin = raySource;
    777680                btVector3 qaabbMax = raySource;
     
    782685                reportAabbOverlappingNodex(nodeCallback,qaabbMin,qaabbMax);
    783686        }
    784         */
    785 
    786687}
    787688
     
    843744bool btQuantizedBvh::serialize(void *o_alignedDataBuffer, unsigned /*i_dataBufferSize */, bool i_swapEndian)
    844745{
    845         btAssert(m_subtreeHeaderCount == m_SubtreeHeaders.size());
     746        assert(m_subtreeHeaderCount == m_SubtreeHeaders.size());
    846747        m_subtreeHeaderCount = m_SubtreeHeaders.size();
    847748
Note: See TracChangeset for help on using the changeset viewer.