use size_t instead of int, for allocator
added hashtable based PairManager, thanks Pierre Terdiman and Erin Catto improved friction in 'cachefriendly' solver moved 'refreshcontactpoints' into collision detection, instead of solver avoid linear search for contact manifolds, by storing an index ignore margin for sphere shape (its entire radius is already margin) avoid alignment checks in BVH serialization, they don't compile on 64-bit architectures made 'bomb' box more heavy
This commit is contained in:
@@ -81,6 +81,7 @@ btPersistentManifold* btCollisionDispatcher::getNewManifold(void* b0,void* b1)
|
||||
|
||||
void* mem = m_persistentManifoldPoolAllocator->allocate(sizeof(btPersistentManifold));
|
||||
btPersistentManifold* manifold = new(mem) btPersistentManifold (body0,body1,0);
|
||||
manifold->m_index1a = m_manifoldsPtr.size();
|
||||
m_manifoldsPtr.push_back(manifold);
|
||||
|
||||
return manifold;
|
||||
@@ -100,16 +101,14 @@ void btCollisionDispatcher::releaseManifold(btPersistentManifold* manifold)
|
||||
//printf("releaseManifold: gNumManifold %d\n",gNumManifold);
|
||||
clearManifold(manifold);
|
||||
|
||||
///todo: this can be improved a lot, linear search might be slow part!
|
||||
int findIndex = m_manifoldsPtr.findLinearSearch(manifold);
|
||||
if (findIndex < m_manifoldsPtr.size())
|
||||
{
|
||||
m_manifoldsPtr.swap(findIndex,m_manifoldsPtr.size()-1);
|
||||
m_manifoldsPtr.pop_back();
|
||||
int findIndex = manifold->m_index1a;
|
||||
btAssert(findIndex < m_manifoldsPtr.size());
|
||||
m_manifoldsPtr.swap(findIndex,m_manifoldsPtr.size()-1);
|
||||
m_manifoldsPtr[findIndex]->m_index1a = findIndex;
|
||||
m_manifoldsPtr.pop_back();
|
||||
|
||||
manifold->~btPersistentManifold();
|
||||
m_persistentManifoldPoolAllocator->free(manifold);
|
||||
}
|
||||
manifold->~btPersistentManifold();
|
||||
m_persistentManifoldPoolAllocator->free(manifold);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,8 @@ void btCollisionWorld::addCollisionObject(btCollisionObject* collisionObject,sho
|
||||
type,
|
||||
collisionObject,
|
||||
collisionFilterGroup,
|
||||
collisionFilterMask
|
||||
collisionFilterMask,
|
||||
m_dispatcher1
|
||||
)) ;
|
||||
|
||||
|
||||
@@ -134,7 +135,7 @@ void btCollisionWorld::performDiscreteCollisionDetection()
|
||||
for (int i=0;i<m_collisionObjects.size();i++)
|
||||
{
|
||||
m_collisionObjects[i]->getCollisionShape()->getAabb(m_collisionObjects[i]->getWorldTransform(),aabbMin,aabbMax);
|
||||
m_broadphasePairCache->setAabb(m_collisionObjects[i]->getBroadphaseHandle(),aabbMin,aabbMax);
|
||||
m_broadphasePairCache->setAabb(m_collisionObjects[i]->getBroadphaseHandle(),aabbMin,aabbMax,m_dispatcher1);
|
||||
}
|
||||
|
||||
m_broadphasePairCache->calculateOverlappingPairs(m_dispatcher1);
|
||||
|
||||
@@ -189,9 +189,10 @@ void btConvexConcaveCollisionAlgorithm::processCollision (btCollisionObject* bod
|
||||
|
||||
concaveShape->processAllTriangles( &m_btConvexTriangleCallback,m_btConvexTriangleCallback.getAabbMin(),m_btConvexTriangleCallback.getAabbMax());
|
||||
|
||||
resultOut->refreshContactPoints();
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -152,6 +152,11 @@ void btConvexConvexAlgorithm ::processCollision (btCollisionObject* body0,btColl
|
||||
m_gjkPairDetector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
|
||||
#endif
|
||||
|
||||
if (m_ownManifold)
|
||||
{
|
||||
resultOut->refreshContactPoints();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -79,7 +79,9 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
|
||||
}
|
||||
|
||||
btManifoldPoint newPt(localA,localB,normalOnBInWorld,depth);
|
||||
|
||||
newPt.m_positionWorldOnA = pointA;
|
||||
newPt.m_positionWorldOnB = pointInWorld;
|
||||
|
||||
int insertIndex = m_manifoldPtr->getCacheEntry(newPt);
|
||||
|
||||
newPt.m_combinedFriction = calculateCombinedFriction(m_body0,m_body1);
|
||||
|
||||
@@ -18,7 +18,7 @@ subject to the following restrictions:
|
||||
#define MANIFOLD_RESULT_H
|
||||
|
||||
class btCollisionObject;
|
||||
class btPersistentManifold;
|
||||
#include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"
|
||||
class btManifoldPoint;
|
||||
|
||||
#include "BulletCollision/NarrowPhaseCollision/btDiscreteCollisionDetectorInterface.h"
|
||||
@@ -70,6 +70,22 @@ public:
|
||||
|
||||
virtual void addContactPoint(const btVector3& normalOnBInWorld,const btVector3& pointInWorld,btScalar depth);
|
||||
|
||||
SIMD_FORCE_INLINE void refreshContactPoints()
|
||||
{
|
||||
btAssert(m_manifoldPtr);
|
||||
if (!m_manifoldPtr->getNumContacts())
|
||||
return;
|
||||
|
||||
bool isSwapped = m_manifoldPtr->getBody0() != m_body0;
|
||||
|
||||
if (isSwapped)
|
||||
{
|
||||
m_manifoldPtr->refreshContactPoints(m_rootTransB,m_rootTransA);
|
||||
} else
|
||||
{
|
||||
m_manifoldPtr->refreshContactPoints(m_rootTransA,m_rootTransB);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
@@ -68,18 +68,25 @@ void btSphereBoxCollisionAlgorithm::processCollision (btCollisionObject* body0,b
|
||||
|
||||
btScalar dist = getSphereDistance(boxObj,pOnBox,pOnSphere,sphereCenter,radius);
|
||||
|
||||
resultOut->setPersistentManifold(m_manifoldPtr);
|
||||
|
||||
if (dist < SIMD_EPSILON)
|
||||
{
|
||||
btVector3 normalOnSurfaceB = (pOnBox- pOnSphere).normalize();
|
||||
|
||||
/// report a contact. internally this will be kept persistent, and contact reduction is done
|
||||
|
||||
resultOut->setPersistentManifold(m_manifoldPtr);
|
||||
resultOut->addContactPoint(normalOnSurfaceB,pOnBox,dist);
|
||||
|
||||
}
|
||||
|
||||
|
||||
if (m_ownManifold)
|
||||
{
|
||||
if (m_manifoldPtr->getNumContacts())
|
||||
{
|
||||
resultOut->refreshContactPoints();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,8 @@ void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0
|
||||
if (!m_manifoldPtr)
|
||||
return;
|
||||
|
||||
resultOut->setPersistentManifold(m_manifoldPtr);
|
||||
|
||||
btSphereShape* sphere0 = (btSphereShape*)col0->getCollisionShape();
|
||||
btSphereShape* sphere1 = (btSphereShape*)col1->getCollisionShape();
|
||||
|
||||
@@ -54,10 +56,13 @@ void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0
|
||||
btScalar radius0 = sphere0->getRadius();
|
||||
btScalar radius1 = sphere1->getRadius();
|
||||
|
||||
m_manifoldPtr->clearManifold();
|
||||
|
||||
///iff distance positive, don't generate a new contact
|
||||
if ( len > (radius0+radius1))
|
||||
{
|
||||
return;
|
||||
|
||||
}
|
||||
///distance (negative means penetration)
|
||||
btScalar dist = len - (radius0+radius1);
|
||||
|
||||
@@ -68,9 +73,12 @@ void btSphereSphereCollisionAlgorithm::processCollision (btCollisionObject* col0
|
||||
btVector3 pos1 = col1->getWorldTransform().getOrigin() + radius1* normalOnSurfaceB;
|
||||
|
||||
/// report a contact. internally this will be kept persistent, and contact reduction is done
|
||||
resultOut->setPersistentManifold(m_manifoldPtr);
|
||||
|
||||
|
||||
resultOut->addContactPoint(normalOnSurfaceB,pos1,dist);
|
||||
|
||||
//no resultOut->refreshContactPoints(); needed, because of clearManifold (all points are new)
|
||||
|
||||
}
|
||||
|
||||
btScalar btSphereSphereCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
|
||||
@@ -48,8 +48,11 @@ void btSphereTriangleCollisionAlgorithm::processCollision (btCollisionObject* co
|
||||
if (!m_manifoldPtr)
|
||||
return;
|
||||
|
||||
btSphereShape* sphere = (btSphereShape*)col0->getCollisionShape();
|
||||
btTriangleShape* triangle = (btTriangleShape*)col1->getCollisionShape();
|
||||
btCollisionObject* sphereObj = m_swapped? col1 : col0;
|
||||
btCollisionObject* triObj = m_swapped? col0 : col1;
|
||||
|
||||
btSphereShape* sphere = (btSphereShape*)sphereObj->getCollisionShape();
|
||||
btTriangleShape* triangle = (btTriangleShape*)triObj->getCollisionShape();
|
||||
|
||||
/// report a contact. internally this will be kept persistent, and contact reduction is done
|
||||
resultOut->setPersistentManifold(m_manifoldPtr);
|
||||
@@ -62,6 +65,9 @@ void btSphereTriangleCollisionAlgorithm::processCollision (btCollisionObject* co
|
||||
|
||||
detector.getClosestPoints(input,*resultOut,dispatchInfo.m_debugDraw);
|
||||
|
||||
if (m_ownManifold)
|
||||
resultOut->refreshContactPoints();
|
||||
|
||||
}
|
||||
|
||||
btScalar btSphereTriangleCollisionAlgorithm::calculateTimeOfImpact(btCollisionObject* col0,btCollisionObject* col1,const btDispatcherInfo& dispatchInfo,btManifoldResult* resultOut)
|
||||
|
||||
@@ -18,6 +18,7 @@ subject to the following restrictions:
|
||||
|
||||
|
||||
|
||||
|
||||
btUnionFind::~btUnionFind()
|
||||
{
|
||||
Free();
|
||||
|
||||
Reference in New Issue
Block a user