Manual Collision Resolution of btScaledBvhTriangleMeshShape?
Posted: Mon May 11, 2015 10:00 pm
So I'm trying to use Bullet just for collision detection, so I can do my own collision resolution. I'm currently stuck on the resolution of a CapsuleShape and a static environment mesh using btScaledBvhTriangleMeshShape. I got CapsuleShape/CapsuleShape collision resolution working quite well relatively easily, however when I try to perform CapsuleShape/btScaledBvhTriangleMeshShape collision resolution, the capsule can just phase through the walls in between the seams of the triangles! I did some searching on google and in these forums and I found a few posts that describe using ContactAddedCallback to call the btAdjustInternalEdgeContacts function when btManifoldPoints are added to the manifold of the collisionObject that has the btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK flag set. In this way, I guess it tries to clear the internal edges so that you aren't getting any collision normals that don't match with the normals of the triangles (the walls of the static physical geometry)? But when I tried this, it still didn't do what I wanted.
For some insight into what my main loop looks like, I'm doing something very similar to what this guy is doing: http://hamelot.co.uk/programming/using- ... detection/
Each entity in the simulation has a function that gets called to resolve physical collisions with the static geometry:
And my findClosestManifoldPoint function just does this:
Is this resolution technique not going to do what I want? Does anyone have any insight on what I might be doing wrong or if this is even possible?
For some insight into what my main loop looks like, I'm doing something very similar to what this guy is doing: http://hamelot.co.uk/programming/using- ... detection/
Each entity in the simulation has a function that gets called to resolve physical collisions with the static geometry:
Code: Select all
void Entity::resolvePhysicalCollision(btPersistentManifold* manifold)
{
int smallestMpIndex = findClosestManifoldPoint(manifold);
if(smallestMpIndex < 0)
{
return;
}
btManifoldPoint& smallestMP = manifold->getContactPoint(smallestMpIndex);
moveBy(smallestMP.m_normalWorldOnB*fabsf(smallestMP.getDistance()));
}
Code: Select all
int Entity::findClosestManifoldPoint(btPersistentManifold* manifold)
{
bool foundValidMP = false;
int smallestMPIndex = -1;
btManifoldPoint& smallestMP = manifold->getContactPoint(0);
btScalar smallestDist = INFINITY;
if(smallestMP.getDistance() < 0.f)
{
foundValidMP = true;
smallestDist = fabsf(smallestMP.getDistance());
smallestMPIndex = 0;
}
for(int c = 1; c < manifold->getNumContacts(); c++)
{
btManifoldPoint& mp = manifold->getContactPoint(c);
if(mp.getDistance() >= 0.f)
{
continue;
}
btScalar mpDist = fabsf(mp.getDistance());
if(mpDist < smallestDist || !foundValidMP)
{
smallestDist = mpDist;
smallestMP = mp;
foundValidMP = true;
smallestMPIndex = c;
}
}
return smallestMPIndex;
}