Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Get RigidBody from rayTest() in Bullet Physics


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 alexmb522   Members   -  Reputation: 131

Like
0Likes
Like

Posted 16 December 2012 - 04:38 PM

I've recently started implementing physics in my game. I'm using the java port of the bullet physics engine. I'm trying to interact with rigid bodies in my scene using rayTest() to select what rigid body to interact with. I'm confused on the correct way of using the rayTest(start, end, callback) function. From my callback I can retrieve a CollisionBody but I need a RigidBody. I'm wondering If I'm about the this the wrong way. Thanks.

Sponsor:

#2 rocklobster   Members   -  Reputation: 415

Like
0Likes
Like

Posted 17 December 2012 - 01:01 AM

You could try storing the rigid body in the user pointer.

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 Krohm   Crossbones+   -  Reputation: 3245

Like
0Likes
Like

Posted 17 December 2012 - 01:56 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.

#4 rocklobster   Members   -  Reputation: 415

Like
0Likes
Like

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.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS