Identifying Collision Objects

Please don't post Bullet support questions here, use the above forums instead.
YAN3
Posts: 11
Joined: Fri May 07, 2010 2:18 pm

Identifying Collision Objects

Post by YAN3 »

Hello everyone. I have a noob question please. Is there a way to keep track and identify the objects in my collision world in such a way that I can always access a certain collision body that i am looking for? For example, I inserted 3 boxes into the collision world in such a way that they are all colliding with each other. Then I read the collision manifold for each colliding pair, retrieved the involved objects, and tried to look up their indexes in the array of all collision objects that I have.

Code: Select all

btCollisionObject* obja = static_cast<btCollisionObject*>(contactManifold->getBody0());
btCollisionObject* objb = static_cast<btCollisionObject*>(contactManifold->getBody1());

btVector3 aPos = obja->getWorldTransform().getOrigin();
btVector3 bPos = objb->getWorldTransform().getOrigin();

btAlignedObjectArray<btCollisionObject*> collisionBodies = collisionWorld->getCollisionObjectArray();

int index1 = collisionBodies.findBinarySearch(obja);
int index2 = collisionBodies.findBinarySearch(objb);

But when I inserted them in the same order but with different positions and collisions and did the same, I got different values for index1 and index2 for each colliding pair. In other words, I got different indexes in the collision objects array for the same physical boxes as before.

My application requires me to detect which boxes are colliding with each other and then save their 'IDs'. So is there some way to be able to always access 'object 1' for example using collisionBodies[1] such that this would always refer to the same box regardless of its new position in the world or its collisions? I don't understand how the objects are ordered in that array and would appreciate any clarification. Thanks a lot.

Regards,
Nick