Logo Search packages:      
Sourcecode: blender version File versions  Download package

void btCompoundCollisionAlgorithm::processCollision ( btCollisionObject *  body0,
btCollisionObject *  body1,
const btDispatcherInfo &  dispatchInfo,
btManifoldResult resultOut 
) [virtual]

btCompoundShape might have changed: /make sure the internal child collision algorithm caches are still valid

clear and update all

we need to refresh all contact manifolds note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep so we should add a 'refreshManifolds' in the btCollisionAlgorithm

Implements btCollisionAlgorithm.

Definition at line 182 of file btCompoundCollisionAlgorithm.cpp.

References ATTRIBUTE_ALIGNED16(), btAlignedObjectArray< T >::clear(), btDbvt::collideTV(), btDispatcher::freeCollisionAlgorithm(), btCollisionShape::getAabb(), btTransform::inverse(), btDbvt::m_root, btManifoldResult::refreshContactPoints(), btManifoldResult::setPersistentManifold(), and btAlignedObjectArray< T >::size().

{
      btCollisionObject* colObj = m_isSwapped? body1 : body0;
      btCollisionObject* otherObj = m_isSwapped? body0 : body1;

      

      btAssert (colObj->getCollisionShape()->isCompound());
      btCompoundShape* compoundShape = static_cast<btCompoundShape*>(colObj->getCollisionShape());

      ///btCompoundShape might have changed:
      ////make sure the internal child collision algorithm caches are still valid
      if (compoundShape->getUpdateRevision() != m_compoundShapeRevision)
      {
            ///clear and update all
            removeChildAlgorithms();
            
            preallocateChildAlgorithms(body0,body1);
      }


      btDbvt* tree = compoundShape->getDynamicAabbTree();
      //use a dynamic aabb tree to cull potential child-overlaps
      btCompoundLeafCallback  callback(colObj,otherObj,m_dispatcher,dispatchInfo,resultOut,&m_childCollisionAlgorithms[0],m_sharedManifold);

      ///we need to refresh all contact manifolds
      ///note that we should actually recursively traverse all children, btCompoundShape can nested more then 1 level deep
      ///so we should add a 'refreshManifolds' in the btCollisionAlgorithm
      {
            int i;
            btManifoldArray manifoldArray;
            for (i=0;i<m_childCollisionAlgorithms.size();i++)
            {
                  if (m_childCollisionAlgorithms[i])
                  {
                        m_childCollisionAlgorithms[i]->getAllContactManifolds(manifoldArray);
                        for (int m=0;m<manifoldArray.size();m++)
                        {
                              if (manifoldArray[m]->getNumContacts())
                              {
                                    resultOut->setPersistentManifold(manifoldArray[m]);
                                    resultOut->refreshContactPoints();
                                    resultOut->setPersistentManifold(0);//??necessary?
                              }
                        }
                        manifoldArray.clear();
                  }
            }
      }

      if (tree)
      {

            btVector3 localAabbMin,localAabbMax;
            btTransform otherInCompoundSpace;
            otherInCompoundSpace = colObj->getWorldTransform().inverse() * otherObj->getWorldTransform();
            otherObj->getCollisionShape()->getAabb(otherInCompoundSpace,localAabbMin,localAabbMax);

            const ATTRIBUTE_ALIGNED16(btDbvtVolume)   bounds=btDbvtVolume::FromMM(localAabbMin,localAabbMax);
            //process all children, that overlap with  the given AABB bounds
            tree->collideTV(tree->m_root,bounds,callback);

      } else
      {
            //iterate over all children, perform an AABB check inside ProcessChildShape
            int numChildren = m_childCollisionAlgorithms.size();
            int i;
            for (i=0;i<numChildren;i++)
            {
                  callback.ProcessChildShape(compoundShape->getChildShape(i),i);
            }
      }

      {
                        //iterate over all children, perform an AABB check inside ProcessChildShape
            int numChildren = m_childCollisionAlgorithms.size();
            int i;
            btManifoldArray   manifoldArray;

            for (i=0;i<numChildren;i++)
            {
                  if (m_childCollisionAlgorithms[i])
                  {
                        btCollisionShape* childShape = compoundShape->getChildShape(i);
                  //if not longer overlapping, remove the algorithm
                        btTransform orgTrans = colObj->getWorldTransform();
                        btTransform orgInterpolationTrans = colObj->getInterpolationWorldTransform();
                        const btTransform& childTrans = compoundShape->getChildTransform(i);
                        btTransform newChildWorldTrans = orgTrans*childTrans ;

                        //perform an AABB check first
                        btVector3 aabbMin0,aabbMax0,aabbMin1,aabbMax1;
                        childShape->getAabb(newChildWorldTrans,aabbMin0,aabbMax0);
                        otherObj->getCollisionShape()->getAabb(otherObj->getWorldTransform(),aabbMin1,aabbMax1);

                        if (!TestAabbAgainstAabb2(aabbMin0,aabbMax0,aabbMin1,aabbMax1))
                        {
                              m_childCollisionAlgorithms[i]->~btCollisionAlgorithm();
                              m_dispatcher->freeCollisionAlgorithm(m_childCollisionAlgorithms[i]);
                              m_childCollisionAlgorithms[i] = 0;
                        }

                  }
                  
            }

            

      }
}


Generated by  Doxygen 1.6.0   Back to index