Bullet physics collision detection seems to be a huge pain.
-
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
Bullet physics collision detection seems to be a huge pain.
Does anyone know how you can just get the collision normal, and penetration depth for a btGhostObject? I'm trying to write a character system but I can't figure out all the callbacks and manifold pairs. I just need the body that collided with the character, the collision normal, and the penetration distance. Does anyone know how?
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
It's really not that bad when you understand that overlapping pair's are generated by the "broad" phase and manifolds and contact points are generated by the "narrow" phase:
Broadphase - Calculate collision objects whose AABB's overlap (collide).
Narrowphase - Calculate contact point info for the broadphase pair results.
Callbacks may be used to filter results for either phase. Collision "masks" may also be used for filtering. See chapter 6 in the Bullet manual to learn more about filtering.
btGhostObject is unique in that you use it to track only pairs that overlap with the ghost object itself.
After each simulation step use the ghost pair cache to generate the contact point information. From btKinematicCharacterController::recoverFromPenetration():
Broadphase - Calculate collision objects whose AABB's overlap (collide).
Narrowphase - Calculate contact point info for the broadphase pair results.
Callbacks may be used to filter results for either phase. Collision "masks" may also be used for filtering. See chapter 6 in the Bullet manual to learn more about filtering.
btGhostObject is unique in that you use it to track only pairs that overlap with the ghost object itself.
After each simulation step use the ghost pair cache to generate the contact point information. From btKinematicCharacterController::recoverFromPenetration():
Code: Select all
collisionWorld->getDispatcher()->dispatchAllCollisionPairs(m_ghostObject->getOverlappingPairCache(), collisionWorld->getDispatchInfo(), collisionWorld->getDispatcher());
m_currentPosition = m_ghostObject->getWorldTransform().getOrigin();
btScalar maxPen = btScalar(0.0);
for (int i = 0; i < m_ghostObject->getOverlappingPairCache()->getNumOverlappingPairs(); i++)
{
m_manifoldArray.resize(0);
btBroadphasePair* collisionPair = &m_ghostObject->getOverlappingPairCache()->getOverlappingPairArray()[i];
// generate contact point information
if (collisionPair->m_algorithm)
collisionPair->m_algorithm->getAllContactManifolds(m_manifoldArray);
for (int j=0;j<m_manifoldArray.size();j++)
{
btPersistentManifold* manifold = m_manifoldArray[j];
btScalar directionSign = manifold->getBody0() == m_ghostObject ? btScalar(-1.0) : btScalar(1.0);
for (int p=0;p<manifold->getNumContacts();p++)
{
const btManifoldPoint&pt = manifold->getContactPoint(p);
// with "pt" you now have:
// pt.getDistance(), pt.m_normalWorldOnB, and position info for both bodies.
}
}
}
-
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
I use this:
But everything is shaking, how can I get it to colide with stuff without going all over the place?
Code: Select all
btManifoldPoint point = manifold->getContactPoint(j);
//Move character out of intersection
btVector3 pos = m_collisionObject->getWorldTransform().getOrigin();
pos -= btVector3(0,point.getDistance(),0);
pos *= point.m_normalWorldOnB;
m_collisionObject->getWorldTransform().setOrigin(pos);
But everything is shaking, how can I get it to colide with stuff without going all over the place?
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
I'm currently using Bullet's btKinematicCharacterController and it sometimes produces shaky results when sliding. It also doesn't behave well when you jump and hit a collision object located above the character.
After I finish working on irrb updates for Blender 2.5x, I plan on digging into Irrlicht's collision response which is really good at sliding. Hopefully that logic can be incorporated into a controller for Bullet.
FTR, Irrlicht's collision response is based on Improved Collision detection and Response. If you happen to get it working with Bullet before I do, please post a link to your code - it would save me and likely others a lot of time. Thanks.
After I finish working on irrb updates for Blender 2.5x, I plan on digging into Irrlicht's collision response which is really good at sliding. Hopefully that logic can be incorporated into a controller for Bullet.
FTR, Irrlicht's collision response is based on Improved Collision detection and Response. If you happen to get it working with Bullet before I do, please post a link to your code - it would save me and likely others a lot of time. Thanks.
-
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
Yeah, I'll post it if I get it working.
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
-
- Posts: 1691
- Joined: Sun May 18, 2008 9:42 pm
I just copied the code from the bullet character controller. The problem is that it gets stuck on the triangle edges, then starts sliding down the edge of the tri.
That would be illogical captain...
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar
My first full game:
http://www.kongregate.com/games/3DModel ... tor#tipjar