Callback for collision

bprieto
Posts: 2
Joined: Fri Jul 13, 2007 2:49 pm

Callback for collision

Post by bprieto »

I need a way to detect when a dynamic rigid body hits the player of my game, which is a kinematic body.

Curently just after the stepsimulation call, I search all contact manifolds to try to find the collision. I identify the rigid body associated to the player by the userpointer. The thing is that I'm not always getting that there is a hit, when I can see that there was one.

I was thinking that also to the collision objects we could add like a callback class the is called when a collision is made

The code that I'm currently using is:

btPersistentManifold* contactManifold = m_dynamicsWorld->getDispatcher()->getManifoldByIndexInternal(i);
btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());

for (int j=0;j<numContacts;j++)
{
btManifoldPoint& pt = contactManifold->getContactPoint(j);
...
}
bprieto
Posts: 2
Joined: Fri Jul 13, 2007 2:49 pm

Post by bprieto »

The issue seems that is:
int numContacts = contactManifold->getNumContacts();

this returns 0, perhaps is there some issue that the conacts points are not stored because one of the bodies is kinematic?
Zimbarbo
Posts: 14
Joined: Thu Jun 28, 2007 2:26 pm

Collision Callback

Post by Zimbarbo »

What you will want to do is register a callback.

Firs

Code: Select all

public void CollisionCallback(ref BroadphasePair collisionPair, CollisionDispatcher dispatcher, DispatcherInfo dispatchInfo)
        {
            int i = 3;
            CollisionObject collisionObjectA = collisionPair.ProxyA.ClientData as CollisionObject;
            CollisionObject collisionObjectB = collisionPair.ProxyB.ClientData as CollisionObject;

            // collision stuff
Next, register it intothe dispatcher...

Code: Select all

_collisionDispatcher = new CollisionDispatcher();
_collisionDispatcher.NearCallback += CollisionCallback;
Now, whenever two things hit, the callback is called, and you can see exactly what hit.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Post by Erwin Coumans »

Zimbarbo, and others: please don't post XNA / X# snippets in this forum. It makes things very confusing.

This forum is meant for C++ Bullet development, and primarily for users of the C++ version of Bullet.

Thanks for your understanding,
Erwin