Update Physic Shape

Post Reply
User avatar
sio2interactive
Posts: 31
Joined: Tue Jul 29, 2008 10:26 am
Contact:

Update Physic Shape

Post by sio2interactive »

Quick question that sounds simple but I can't find the answer...

I want to resize a btCapsuleShapeZ, Im currently using the shape for a character and when the animation of this character is running I want to update the height and radius...

How can I do that?

Obviously I don't want to recreate a new collision shape every frame, and do not want to use a convex hull or triangle mesh and update all the tris/verts every frame either... the simplest solution is simply to update the height and radius to fit the current dimXYZ of my animation frame.

Tks in advance,

Cheers,
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Update Physic Shape

Post by Erwin Coumans »

There is no easy way right now, apart from re-creating a new capsule.

I'll make sure to add the feature for upcoming Bullet 2.76 release. This should be available later this month.
You can read implementation details and track progress here http://code.google.com/p/bullet/issues/detail?id=325
Thanks,
Erwin
User avatar
sio2interactive
Posts: 31
Joined: Tue Jul 29, 2008 10:26 am
Contact:

Re: Update Physic Shape

Post by sio2interactive »

I see, allright, fair enough...

I implement to recreate a new capsule every frame, now how can I flush the contact points?


Tks in advance,

Cheers,
User avatar
sio2interactive
Posts: 31
Joined: Tue Jul 29, 2008 10:26 am
Contact:

Re: Update Physic Shape

Post by sio2interactive »

Allright got it... probably totally unoptimized but waever...

_btBroadphaseInterface->getOverlappingPairCache()->cleanProxyFromPairs( _btRigidBody->getBroadphaseProxy(), _btCollisionDispatcher );

If someone have a better version please post it.

Cheers!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Update Physic Shape

Post by Erwin Coumans »

Generally it is not recommended to change the shape while its body is in the world, so either remove the body from the world first, or use cleanProxyFromPairs to flush the contacts (as you already mentioned).

In the latest trunk there is a new method, 'setImplicitShapeDimensions' that lets you change the shape of a capsule (or box, cylinder, cone). This will be available in Bullet 2.76 later this month.
Note that the implicit shape dimensions store half extents such as radius and not full extents such as diameter.

So to set a new radius and length of a capsule, use:

Code: Select all

//remove the body from the world before making any change to the collision shape (or use cleanProxyFromPairs afterwards)
capsule->setImplicitShapeDimensions(btVector3(radius,0.5*length,radius));
//re-add the body into the world, or call cleanProxyFromPairs
Thanks for the feedback,
Erwin
Post Reply