Updating btCollisionObject transforms

Aztal
Posts: 1
Joined: Sat Jun 23, 2012 4:09 pm

Updating btCollisionObject transforms

Post by Aztal »

Hello, I just started implementing Bullet in my project with DirectX 9 and c++. I've read the manual and looked through the wiki, but I still can't find the answer to this. I want to only use the collision detection features, but I can't figure out how to update objects once they're added to my instance of btDiscreteDynamicsWorld. Currently I'm doing it every frame with btCollisionObject->SetTransform(), but no collisions are detected when I check, and I read somewhere that you can't update the transforms once they're added to the world and active.

Using only objects with btBoxShape as their shape, how do I update their positions every frame so that they collide when I do a contact test? I think I understand using stepSimulation() or performDiscreteCollisionDetection() to literally update/check everything. It's just the individual object movement that I'm confused about. Do you have to use motion states just for the collision detection?


If my question is already answered somewhere, I would really appreciate a link. Thanks for your time!
trollington
Posts: 8
Joined: Thu Nov 24, 2011 3:08 pm

Re: Updating btCollisionObject transforms

Post by trollington »

You have to update the object's broadphase proxy. The broadphase proxies represent the bounding boxes of all your objects and are arranged in a tree structure. Any time that you move a static object, you have to update the aabb min/max in the broadphase, which requires an update to the actual tree structure.

Untested code:

btVector3 aabbmin, aabbmax;
yourObject->getCollisionShape()->getAabb(yourObject->getWorldTransform(), aabbmin, aabbmax); // extracts the object's min/max axis aligned bounding box world coordinates
yourBulletWorld->getBroadphase()->setAabb(yourObject->getBroadphaseHandle(), aabbmin, aabbmax, 0); // sets the proxy's aabb and updates the tree