Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 31, 2009, 8:05:51 PM (16 years ago)
Author:
rgrieder
Message:

Update from Bullet 2.73 to 2.74.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/bullet/BulletCollision/CollisionDispatch/btCompoundCollisionAlgorithm.cpp

    r2662 r2882  
    2020#include "LinearMath/btIDebugDraw.h"
    2121#include "LinearMath/btAabbUtil2.h"
     22#include "btManifoldResult.h"
    2223
    2324btCompoundCollisionAlgorithm::btCompoundCollisionAlgorithm( const btCollisionAlgorithmConstructionInfo& ci,btCollisionObject* body0,btCollisionObject* body1,bool isSwapped)
     
    2930
    3031        btCollisionObject* colObj = m_isSwapped? body1 : body0;
     32        btAssert (colObj->getCollisionShape()->isCompound());
     33       
     34        btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
     35        m_compoundShapeRevision = compoundShape->getUpdateRevision();
     36       
     37        preallocateChildAlgorithms(body0,body1);
     38}
     39
     40void    btCompoundCollisionAlgorithm::preallocateChildAlgorithms(btCollisionObject* body0,btCollisionObject* body1)
     41{
     42        btCollisionObject* colObj = m_isSwapped? body1 : body0;
    3143        btCollisionObject* otherObj = m_isSwapped? body0 : body1;
    32         assert (colObj->getCollisionShape()->isCompound());
     44        btAssert (colObj->getCollisionShape()->isCompound());
    3345       
    3446        btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
     47
    3548        int numChildren = compoundShape->getNumChildShapes();
    3649        int i;
     
    4760                        btCollisionShape* childShape = compoundShape->getChildShape(i);
    4861                        colObj->internalSetTemporaryCollisionShape( childShape );
    49                         m_childCollisionAlgorithms[i] = ci.m_dispatcher1->findAlgorithm(colObj,otherObj,m_sharedManifold);
     62                        m_childCollisionAlgorithms[i] = m_dispatcher->findAlgorithm(colObj,otherObj,m_sharedManifold);
    5063                        colObj->internalSetTemporaryCollisionShape( tmpShape );
    5164                }
     
    5366}
    5467
    55 
    56 btCompoundCollisionAlgorithm::~btCompoundCollisionAlgorithm()
     68void    btCompoundCollisionAlgorithm::removeChildAlgorithms()
    5769{
    5870        int numChildren = m_childCollisionAlgorithms.size();
     
    6678                }
    6779        }
     80}
     81
     82btCompoundCollisionAlgorithm::~btCompoundCollisionAlgorithm()
     83{
     84        removeChildAlgorithms();
    6885}
    6986
     
    168185        btCollisionObject* otherObj = m_isSwapped? body0 : body1;
    169186
    170         assert (colObj->getCollisionShape()->isCompound());
     187       
     188
     189        btAssert (colObj->getCollisionShape()->isCompound());
    171190        btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
     191
     192        ///btCompoundShape might have changed:
     193        ////make sure the internal child collision algorithm caches are still valid
     194        if (compoundShape->getUpdateRevision() != m_compoundShapeRevision)
     195        {
     196                ///clear and update all
     197                removeChildAlgorithms();
     198               
     199                preallocateChildAlgorithms(body0,body1);
     200        }
     201
    172202
    173203        btDbvt* tree = compoundShape->getDynamicAabbTree();
     
    175205        btCompoundLeafCallback  callback(colObj,otherObj,m_dispatcher,dispatchInfo,resultOut,&m_childCollisionAlgorithms[0],m_sharedManifold);
    176206
     207        ///we need to refresh all contact manifolds
     208        ///note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep
     209        ///so we should add a 'refreshManifolds' in the btCollisionAlgorithm
     210        {
     211                int i;
     212                btManifoldArray manifoldArray;
     213                for (i=0;i<m_childCollisionAlgorithms.size();i++)
     214                {
     215                        if (m_childCollisionAlgorithms[i])
     216                        {
     217                                m_childCollisionAlgorithms[i]->getAllContactManifolds(manifoldArray);
     218                                for (int m=0;m<manifoldArray.size();m++)
     219                                {
     220                                        if (manifoldArray[m]->getNumContacts())
     221                                        {
     222                                                resultOut->setPersistentManifold(manifoldArray[m]);
     223                                                resultOut->refreshContactPoints();
     224                                                resultOut->setPersistentManifold(0);//??necessary?
     225                                        }
     226                                }
     227                                manifoldArray.clear();
     228                        }
     229                }
     230        }
    177231
    178232        if (tree)
     
    243297        btCollisionObject* otherObj = m_isSwapped? body0 : body1;
    244298
    245         assert (colObj->getCollisionShape()->isCompound());
     299        btAssert (colObj->getCollisionShape()->isCompound());
    246300       
    247301        btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());
     
    286340
    287341
     342
Note: See TracChangeset for help on using the changeset viewer.