Adding CollisionObjects After Static Geometry Breaks

Post Reply
K6L2
Posts: 7
Joined: Mon May 11, 2015 9:43 pm

Adding CollisionObjects After Static Geometry Breaks

Post by K6L2 »

I am using only the collision detection parts of Bullet.

I am adding static geometry to the collision world by building an array of triangle shapes using btTriangleShape, with each triangle having its own btCollisionObject.

Physical entities are added to the collision world by creating a btCapsuleShape, each having its own btCollisionObject.

I've noticed the most peculiar thing: if I add the entities to the scene first, everything works fine. However, if I load in the static geometry of the world first, collision detection just breaks completely! What I can observe when this happens is things just start falling through the floor. Has anyone ever experienced something like this? Any insight into what I might be doing wrong?
K6L2
Posts: 7
Joined: Mon May 11, 2015 9:43 pm

Re: Adding CollisionObjects After Static Geometry Breaks

Post by K6L2 »

Dang this forum is so lonely lol...

Well I managed to fix my own issue again. The problem was just me being stupid in the collision resolution with static geometry. Before I was just doing:

Code: Select all

    int smallestMpIndex = findClosestManifoldPoint(manifold, true);
    if(smallestMpIndex < 0)
    {
        return;
    }
    btManifoldPoint& smallestMP = manifold->getContactPoint(smallestMpIndex);
    btVector3 resolutionVec = smallestMP.m_normalWorldOnB*fabsf(smallestMP.getDistance());
Which was stupid because that always assumes that the static geometry is the second body. To fixed it I just made sure that I was always getting the correct normal manually like so:

Code: Select all

    bool isBodyA = static_cast<CollisionProxy*>(manifold->getBody0()->getUserPointer())->data() == this;
    int smallestMpIndex = findClosestManifoldPoint(manifold, true);
    if(smallestMpIndex < 0)
    {
        return;
    }
    btManifoldPoint& smallestMP = manifold->getContactPoint(smallestMpIndex);
    const btVector3& mpThis = (isBodyA ? smallestMP.getPositionWorldOnA() : smallestMP.getPositionWorldOnB());
    const btVector3& mpOther = (isBodyA ? smallestMP.getPositionWorldOnB() : smallestMP.getPositionWorldOnA());
    btVector3 awayVec = (mpOther - mpThis);
    awayVec.safeNormalize();
    btVector3 resolutionVec = awayVec*fabsf(smallestMP.getDistance());
Post Reply