add additional callback

This commit is contained in:
nicolaichuk 2017-03-23 14:18:50 +03:00
parent 1897939ec7
commit d26952acac
4 changed files with 25 additions and 2 deletions

View File

@ -33,8 +33,6 @@ class btDispatcher;
class btCollisionObject;
class btCollisionShape;
typedef bool (*btShapePairCallback)(const btCollisionShape* pShape0, const btCollisionShape* pShape1);
extern btShapePairCallback gCompoundCompoundChildShapePairCallback;
/// btCompoundCompoundCollisionAlgorithm supports collision between two btCompoundCollisionShape shapes
class btCompoundCompoundCollisionAlgorithm : public btCompoundCollisionAlgorithm

View File

@ -111,6 +111,7 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
return;
bool isSwapped = m_manifoldPtr->getBody0() != m_body0Wrap->getCollisionObject();
bool isNewCollision = m_manifoldPtr->getNumContacts() == 0;
btVector3 pointA = pointInWorld + normalOnBInWorld * depth;
@ -187,5 +188,9 @@ void btManifoldResult::addContactPoint(const btVector3& normalOnBInWorld,const b
(*gContactAddedCallback)(m_manifoldPtr->getContactPoint(insertIndex),obj0Wrap,newPt.m_partId0,newPt.m_index0,obj1Wrap,newPt.m_partId1,newPt.m_index1);
}
if (gContactStartedCallback && isNewCollision)
{
gContactStartedCallback(m_manifoldPtr);
}
}

View File

@ -21,6 +21,8 @@ subject to the following restrictions:
btScalar gContactBreakingThreshold = btScalar(0.02);
ContactDestroyedCallback gContactDestroyedCallback = 0;
ContactProcessedCallback gContactProcessedCallback = 0;
ContactStartedCallback gContactStartedCallback = 0;
ContactEndedCallback gContactEndedCallback = 0;
///gContactCalcArea3Points will approximate the convex hull area using 3 points
///when setting it to false, it will use 4 points to compute the area: it is more accurate but slower
bool gContactCalcArea3Points = true;

View File

@ -28,10 +28,18 @@ struct btCollisionResult;
///maximum contact breaking and merging threshold
extern btScalar gContactBreakingThreshold;
#ifndef SWIG
class btPersistentManifold;
typedef bool (*ContactDestroyedCallback)(void* userPersistentData);
typedef bool (*ContactProcessedCallback)(btManifoldPoint& cp,void* body0,void* body1);
typedef void (*ContactStartedCallback)(btPersistentManifold* const &manifold);
typedef void (*ContactEndedCallback)(btPersistentManifold* const &manifold);
extern ContactDestroyedCallback gContactDestroyedCallback;
extern ContactProcessedCallback gContactProcessedCallback;
extern ContactStartedCallback gContactStartedCallback;
extern ContactEndedCallback gContactEndedCallback;
#endif //SWIG
//the enum starts at 1024 to avoid type conflicts with btTypedConstraint
enum btContactManifoldTypes
@ -171,6 +179,11 @@ public:
btAssert(m_pointCache[lastUsedIndex].m_userPersistentData==0);
m_cachedPoints--;
if (gContactEndedCallback && m_cachedPoints == 0)
{
gContactEndedCallback(this);
}
}
void replaceContactPoint(const btManifoldPoint& newPoint,int insertIndex)
{
@ -220,6 +233,11 @@ public:
{
clearUserCache(m_pointCache[i]);
}
if (gContactEndedCallback && m_cachedPoints)
{
gContactEndedCallback(this);
}
m_cachedPoints = 0;
}