Page 1 of 1
How to dynamically change the scale of my entity object ?
Posted: Sun Aug 28, 2011 7:27 pm
by rc183
Hi,
I have one question about BEPU Physic.
I have a ball model associated to a Sphere entity (BEPU Sphere Object) and i try to modify the scale of this ball dinamicaly depending of the time.
I tried to modify the WorldTransform attribute of my Sphere entity but it doesn't seem work. I think that my scale is ignored.
There is a better way to create this effect ?
Thank you in advance for your answers.
Re: How to dynamically change the scale of my entity object
Posted: Sun Aug 28, 2011 7:43 pm
by Norbo
WorldTransform is a rigid transform, meaning it should contain only orientation and translation. Including scale or shear components in a Matrix will confuse the property setter and end up with wrong orientation/translation.
There is no universal 'scale' property across all entities. However, many shapes have properties that can be changed. For example, a SphereShape (used by the Sphere prefab entity) has a Radius property. It is settable.
There's also a TransformableShape that can take any other convex shape and an affine transform. You can nonuniformly scale and shear shapes by doing this, but be aware that using this eliminates the engine's ability to use the inner shapes' special case collision detection systems. It might not be as efficient.
Note that changing an entity's shape such that it encounters a new collision due to expansion will have a 'squishy' collision response. Collision response primarily relies on correcting velocity, with penetration being corrected over multiple frames. Since the shape change is instantaneous and nonphysical, it has to rely entirely on the penetration correction, which, again, takes multiple frames.
Re: How to dynamically change the scale of my entity object
Posted: Mon Aug 29, 2011 12:38 pm
by rc183
Thank you very much for your answer.
I have tried to modify the radius attribute of my sphere. The radius correctly change but my model and the bouding box are always too big (no change is applied).
I have tried to call the UpdateBoudingBox method after the change of the radius but nothing seems to work.
This is normal ?
Thank you in advance.
Re: How to dynamically change the scale of my entity object
Posted: Mon Aug 29, 2011 8:38 pm
by Norbo
The bounding box is computed with every call to UpdateBoundingBox based on the current dimensions of the shape. The UpdateBoundingBox calls will occur automatically if the object is active (and changing dimensions should wake the object up, if I remember correctly).
So if it is truly not changing, then no, that is not expected.
Could it just a lack of graphical change? Examining it before and after the dimension change and bounding box update using the debugger would make it obvious.
If you're using the ModelDrawer, note that it does not bother updating its graphics when an entity changes shape. To update the appearance, you need to remove the entity from the ModelDrawer and add it again.