Page 1 of 1

Small angular impulses

Posted: Sat Jul 23, 2011 2:53 am
by woodbyte
I just started using BEPUphysics (v0.16.0) and ran into a bit of a problem with the ApplyImpulse method.
Let S be a Sphere(Prefab) with radius and mass equal to 1, then:

Code: Select all

S.AngularDamping = 0;
S.ApplyImpulse(Vector3.UnitX, -Vector3.UnitZ * M);
should make S spin with some constant angular velocity.
And indeed it does, but when magnitude M is small enough (<= 0.1870f in my tests with S centered at origin), it will only spin for a few steps and then stop.

Also, the following alternative had the same issue:

Code: Select all

S.AngularVelocity = new Vector3(0, M, 0); // angular motion will stop after a few frames if M <= 0.264f
I hope I'm missing something really basic here. :)

Re: Small angular impulses

Posted: Sat Jul 23, 2011 3:01 am
by Norbo
That's caused by the deactivation system. It will attempt to stabilize and disable very slow objects. You can prevent it from freezing entirely by setting the object's IsAlwaysActive property to true. However, stabilization will still be applied. You can disable stabilization separately by setting the Space.DeactivationManager.UseStabilization to false.

Stabilization is nice to have on in the general case, though, particularly if you have complicated interactions like large stacks or constraint systems.

You can also tune the Space.DeactivationManager.LowVelocityTimeMinimum and Space.DeactivationManager.VelocityLowerLimit. Stabilization only occurs under the velocity limit, and deactivation will not occur until an object is below the velocity limit for the time minimum.

Re: Small angular impulses

Posted: Sat Jul 23, 2011 3:12 am
by Norbo
I went ahead and also added a property to the Entity, AllowStabilization. It can be set to false and no stabilization will be applied to that entity even if the deactivation manager uses stabilization in general.

I didn't explain it in the previous post, but to make it clear- stabilization damps energy out of the system. Even if an object with low velocity doesn't deactivate, it can still slow down due to stabilization if it's enabled.

The development version that includes this change can be found here: http://bepuphysics.codeplex.com/SourceC ... evelopment

Re: Small angular impulses

Posted: Sat Jul 23, 2011 3:31 am
by woodbyte
I forgot to mention above that I performed the test with IsAlwaysActive set to true. I've now turned off stabilization and it behaves as expected.
Thanks very much for the prompt reply.
Norbo wrote:I went ahead and also added a property to the Entity, AllowStabilization. It can be set to false and no stabilization will occur even if the deactivation manager uses stabilization in general (...)
Wonderful, this was going to be my next question!

To give it some context, I'm currently modeling a space shuttle using ApplyImpulse for thrusters placed across the hull and need it to be as accurate as possible. I understand how stabilization can be important (I played a bit with the GettingStartedDemo and after piling ALOT of boxes on top of one another the simulation slowed down quite a bit, only to speed up soon after when the boxes were deactivated). So I'm quite happy that I can turn off stabilization for only some objects and keep the remaining interactions as fast as possible.

Thanks for your help and for making BEPUphysics in the first place. XNA development would be a lot worse without it.