Get RigidBody from rayTest() in Bullet Physics
#1 Members - Reputation: 131
Posted 16 December 2012 - 04:38 PM
#2 Members - Reputation: 353
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();
EDIT: Sorry but I've only used it in c++ so I don't know about the java port
Edited by rocklobster, 17 December 2012 - 01:09 AM.
#3 GDNet+ - Reputation: 1710
Posted 17 December 2012 - 01:56 AM
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.
#4 Members - Reputation: 353
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.
Good point, I wasn't sure if you could just blindly cast it to rigid body or not.






