Dynamically scale an Entity

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Roybott
Posts: 2
Joined: Sun Aug 29, 2010 9:23 pm

Dynamically scale an Entity

Post by Roybott »

I'm possibily missing something here but I can't seem to see what it is :).

Lets say I have some Boxes in my Space, they collide with each other fine, what I would like to be able to do is scale one of the boxes whilst the game is running (say by holding the right trigger).

I understand how to scale the model/graphical representation of the object, but I can't figure out how to scale the collision Entity so that the object can collide with objects at its new scale/size. Applying a Scale Matrix to the WorldTransform doesn't have the desired effect and I can't see any 'scale' properties of the Entity object, so I'm wondering if there is a sensible way to do this other than recreating the Entity each time with the new height/width/length values?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Dynamically scale an Entity

Post by Norbo »

While local scaling isn't universally supported in v0.14.1 and before, the Box entity's Width/Length/Height properties can be set dynamically. This is equivalent to changing the local scaling. The WorldTransform is a rigid transformation (rotation and translation only). If the matrix includes scaling, it will be interpreted incorrectly.

Note that collisions do not take into account the deformation velocity, so you will likely see interpenetration while scaling. It will be resolved over a few frames by the position correction system, but it won't seem as rigid as normal collisions.

v0.15.0 is revisiting the design of almost every part of the engine. Part of the redesign will make universal local scaling for collision shapes possible. That specific feature may or may not make it into v0.15.0 due to other high priority changes and time constraints. If it does end up getting pushed back, it will show up in v0.15.1 or v0.16.0 (whichever ends up being the next version).
seabert
Posts: 11
Joined: Sun Aug 29, 2010 10:33 pm

Re: Dynamically scale an Entity

Post by seabert »

I don't think you need to re-create your boxes you can simply modify the height, width and length at runtime.
If you really want to use a Matrix object to do it, something like this should work fine:

Code: Select all

        private void ScaleEntity(Box e, Matrix m)
        {
            e.Width *= m.M11;
            e.Height *= m.M22;
            e.Length *= m.M33;
        }
Hope this helps :)
Roybott
Posts: 2
Joined: Sun Aug 29, 2010 9:23 pm

Re: Dynamically scale an Entity

Post by Roybott »

Awesome, thank you both for the replies, the reports of great support for BEPU via the forum was correct :)

Just to check, I assume I can dynamically change the dimensions of any of the Entities (Sphere's radius, Capsules length, etc)?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Dynamically scale an Entity

Post by Norbo »

Yes. Another thing to watch out for when changing the dimensions of dynamic entities is their inertia. You might notice that a box scaled up a bunch no longer feels quite right when rotating. Calling BecomeDynamic on the entity will force it to recalculate its inertia. The LocalInertiaTensor(Inverse) property can be manually changed, too.
the reports of great support for BEPU via the forum was correct
:)
Post Reply