Multiple collision boxes to a single rigidbody

eskimo456
Posts: 6
Joined: Wed Feb 15, 2012 3:26 pm

Multiple collision boxes to a single rigidbody

Post by eskimo456 »

Hi there
Sorry to keep asking questions in a short space off time.

I was wandering how would you split up an odd shape into multiple bounding boxes to be used for collision. I am thinking that I could create a rigid body for the initial shape and define a defaultMotionState. This will then update and move in the scene. If I then create several different btCollisionShape* objects.
How could I then get the position of the shapes to update with the rigid body??

Currently I am using the technique

Code: Select all

rigidBody->getMotionState()->getWorldTransform(transformation);
This then updates the default motionState of the rigid body. The shapes however either stay where they are, or all move to the same place as the rigid body. Do I need a rigid body for each shape?

Or can I use the motionState information to effect the shapes?

Many thanks

P.S Sorry for the bad explanation please reply if I have not explained what I am asking well enough
MaxDZ8
Posts: 149
Joined: Fri Jun 24, 2011 8:53 am

Re: Multiple collision boxes to a single rigidbody

Post by MaxDZ8 »

eskimo456 wrote:I was wandering how would you split up an odd shape into multiple bounding boxes to be used for collision.
Personally I wouldn't even try. I would just assume them to come out from the asset.
I know UnrealEd will create a bounding box or k-dop for each complex mesh, I think it's a semi-automated process. See this. Now, you see this is oriented to generating a single shape.
For multiple shapes, I'd point out GPU Gems Chapter 23. Chapter 23.2.2 presents a multi-shape model representation for particle (hair) collision. It appears to me this must have been a manual process.
eskimo456 wrote:How could I then get the position of the shapes to update with the rigid body??
I'm afraid your understanding of shapes... or at least your terminology is wrong.
Shapes exist "by themselves". They don't move nor collide with anything else. Rigid bodies do. A rigid body is - at its simplest - a shape instanced in the world.For complex shapes however, there's a shortcut.
Create a btCompoundShape, fill it with the required shapes and then instance the btCompoundShape as needed. I hope this makes sense.
eskimo456 wrote:Do I need a rigid body for each shape?
A rigid body can use a single shape (but it can be a compound shape). A shape can be instanced to multiple rigid bodies.
I suppose I'm misunderstanding your question.
eskimo456 wrote:Or can I use the motionState information to effect the shapes?
No, shapes don't move. Rigid bodies do. Rigid bodies can be associated to a motion state, shapes cannot. I'd be extremely careful in changing shapes at runtime, odds are they might need to be removed from the world (that is, all rigidbodies removed, shape removed, everything recreated from scratch to clean collision caches).
eskimo456
Posts: 6
Joined: Wed Feb 15, 2012 3:26 pm

Re: Multiple collision boxes to a single rigidbody

Post by eskimo456 »

Thank you for the quick reply.

The way I understood shapes was obviously wrong. I assumed the rigid Body updated with the world transforms and allowed for forces etc, and that the shape deals with collisions. Currently using the default motionState I am inputting a shape that has been defined what happens if I leave this input a null?

What happens if I just set an object using transform->setIdentity(). and the transform->setOrigin(x,y,z);

IS there any disadvantage of doing this to using a defaultMotionState? Or should a defaultMotionState always exist for the rigid body?

I am currently able to render objects and get them to move, update and collide however I am still lacking neat code and am just curious of these things so I can try and structure my code better and make it more adaptable.

Many thanks