Jump to content
Posted 16 December 2012 - 04:38 PM
Posted 17 December 2012 - 01:01 AM
collisionObject->setUserPointer((void*)rigidBody); // then when you ray cast you can get the user pointer from the collision object btRigidBody* body = (btRigidBody*)rayHitObject->getUserPointer();
Edited by rocklobster, 17 December 2012 - 01:09 AM.
Posted 17 December 2012 - 01:56 AM
Posted 17 December 2012 - 02:22 AM
There's likely nothing wrong in your understanding.
Let's start from the difference between btCollisionObject and btRigidBody.
btRigidBody is a btCollisionObject with extra state added to manage dynamics.
Unfortunately, dynamics are optional in Bullet (btCollisionWorld) and the dynamics-enabled world is a derived class.
Ray casting (and other tests) are provided by the basic collision-only world and they know only about btCollisionObject so yes, there's a information loss.
So, what we do if we need a btRigidBody?
Here's the deal. If you use the dynamic-enabled world, you just create btRigidBody only. Therefore you can just blindly cast the pointer. Note the user-pointer involves a cast anyway.
Caveat: if you use bullet serialization files you must be extra special sure they don't inject btCollisionObject, otherwise, everything will run amok.