How to dynamically scale an object

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

How to dynamically scale an object

Post by Danthekilla »

Hey,

How do you change the scale of an object? We could rebuild the whole thing, but just stretching out a pre-existing sphere would be easier.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: How to dynamically scale an object

Post by Norbo »

You can change the radius property of the sphere at runtime. This will have the expected effect on the dimensions of the sphere, but it will not recalculate the inertia tensor. You can recalculate the inertia tensor by calling the entity's becomeDynamic/Kinematic function.

As an example to recalculate the inertia tensor:

Code: Select all

sphere.radius = 4;
sphere.becomeDynamic(sphere.mass);
A slightly trickier problem to deal with happens when trying to scale an object 'smoothly' at runtime and it's colliding with other entities. In this case, the 'expansion velocity' created by the scaling is not taken into account by contact points and the entities will begin to interpenetrate. Position correction impulses will resolve this penetration over a few frames, but it will appear 'squishier' than a normal rigid collision. You can fake the 'expansion velocity' by applying equal and opposite impulses to both the expanding entity and colliding entity. Calculating these impulses can be done approximately or correctly, though computing the correct values can be tricky (the jacobians are currently internal on collision constraints).

Other entities that have settable dimensions, like the Box entity, can be dealt with similarly. There is currently no easy way to scale up a ConvexHull and some of the other more complicated types without rebuilding them, however.
Danthekilla
Posts: 136
Joined: Sun Jan 17, 2010 11:35 am

Re: How to dynamically scale an object

Post by Danthekilla »

Ok, thankyou for the reply. We are rebuilding objects when scaled, which seems to work quite fine.
Post Reply