How to find which objects that is in contact with each other

Soollee
Posts: 4
Joined: Sun Nov 08, 2009 11:06 am

How to find which objects that is in contact with each other

Post by Soollee »

I start with apologizing if this topic has been discussed before. I read through a lot of post and not find the information I was looking for.

My problem is that I'm not quite understand the collision callback mechanism. What I want is to be able to know which specific objects that is in contact with each other. For instance if I'm developing a game where a car should go from start to finish where the finish is represented by some static object and the car is a dynamic one. Let's say that I want to reset the cars position when the car hit the goal. How can I know when these two object hit each other?

As i read in the documentation one way to detect collisions is to iterate over all contact manifolds but is there no information about which objects that are in contact?

Thank for the help!
edouard
Posts: 8
Joined: Fri Sep 25, 2009 2:08 pm

Re: How to find which objects that is in contact with each other

Post by edouard »

The manifold gives you all the collision pair at this moment in the world you only have to compare your body to the object it returns you. You can have the object like this

Code: Select all

		btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
		btRigidBody * ObjectA = (btRigidBody*)btRigidBody::upcast(obA);
		btRigidBody * ObjectB = (btRigidBody*)btRigidBody::upcast(obB);
A more optimized way of doing this is using a ghost object for your goal. You can obtain only the pair of object that your ghost is colliding with

Hopes this help

Edouard