Page 1 of 1

Spinning object.

Posted: Sat Sep 12, 2009 7:28 am
by Rademanc
Hi. I have a spinning object that I don't want to spin at all.
How can i keep it from spinning?
When I try and add a rotaionalAxisConstraint it gives me an error.

RotationalAxisConstraint r1 = new RotationalAxisConstraint(anchor, Vector3.UnitX, true);
space.add(r1);

{"Object synchronization method was called from an unsynchronized block of code."}

Re: Spinning object.

Posted: Sat Sep 12, 2009 5:34 pm
by Norbo
Thanks for the bug report, it should be fixed in the next version. It can be worked around by disabling multithreading or forcing a call to the SingleBodyConstraint's sortInvolvedEntities method (which would basically require extending the SingleBodyConstraint in question).

However, to restrict angular motion, you can also just modify the inertia tensor inverse. A simple example can be seen in the CharacterController class:

Code: Select all

body.localSpaceInertiaTensorInverse = Toolbox.zeroMatrix;
This makes the character's body unable to rotate around any axis.

You can also choose particular axes to restrict by setting particular rows of the inverse inertia tensor to zero.

Code: Select all

            Matrix inertiaTensorInverse =body.localSpaceInertiaTensorInverse;
            inertiaTensorInverse.M21 = 0;
            inertiaTensorInverse.M22 = 0;
            inertiaTensorInverse.M23 = 0;
           body.localSpaceInertiaTensorInverse = inertiaTensorInverse;
The above code restricts the body from rotating around the Y axis. The first row (M11, M12, M13) is the X axis, and the third row (M31, M32, M33) is the Z axis.

The idea behind these modifications is that you're scaling the inertia around those axes. So you can think about it like this: if the inverse is zero, the inertia tensor for that row must be something like infinity. An object with infinite mass cannot have its velocity changed by collisions.

Re: Spinning object.

Posted: Sat Sep 12, 2009 8:34 pm
by Rademanc
Thanks. I appreciate the help.