Spinning object.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Rademanc
Posts: 16
Joined: Sat Apr 25, 2009 4:21 pm

Spinning object.

Post 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."}
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Spinning object.

Post 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.
Rademanc
Posts: 16
Joined: Sat Apr 25, 2009 4:21 pm

Re: Spinning object.

Post by Rademanc »

Thanks. I appreciate the help.
Post Reply