Freeing a rotational axis with a 6DofConstraint

Post Reply
tp
Posts: 13
Joined: Sat Dec 09, 2006 8:10 am

Freeing a rotational axis with a 6DofConstraint

Post by tp »

I am using a Generic6DofConstraint to implement an upright constraint that keeps my (capsule) actors from falling over while they move. I am interested in locking the X and Z axes, Y is up in my case and I want to have that axis free (see below).

Code: Select all

pConstraint->setLimit(0, -SIMD_INFINITY, SIMD_INFINITY);
pConstraint->setLimit(1, -SIMD_INFINITY, SIMD_INFINITY);
pConstraint->setLimit(2, -SIMD_INFINITY, SIMD_INFINITY);
pConstraint->setLimit(3, 0, 0);
pConstraint->setLimit(4, 1, 0);
pConstraint->setLimit(5, 0, 0);
Here I am attempting to limit the Y axis with the documented convention that high < low means that the axis is free. The result is that after the value for Y rotation goes past -pi/2 or +pi/2 (i.e. over 90 degrees to either side), the simulation explodes. Using -SIMD_INFINITY, SIMD_INFINITY as the limits does not help, as they are just normalized to -pi/2, +pi/2 inside btGeneric6DofConstraint::setLimit.

If I constrain the Y axis with the limits 0,0, everything is fine and the axis is locked. However, I need the capsule to be able to pull around another rigid body on the X-Z-plane, and that requires the capsule to be able to spin around the Y axis. The pulling works just fine with a Generic6DofSpringConstraint, the problem is that using these two together (upright + pull), does not work.

Any advice is greatly appreciated.
User avatar
projectileman
Posts: 109
Joined: Thu Dec 14, 2006 4:27 pm
Location: Colombia
Contact:

Re: Freeing a rotational axis with a 6DofConstraint

Post by projectileman »

Take a look into the commented text in btGeneric6DofConstraint.h file at line 222, there specifies the valid angle ranges for rotational constraints. You could only freeing the X rotational axis, and you must keep Y and Z limited with values between (-PI/2 , PI/2) . That's because the complexity of the formulas for getting the Euler rotational angles: there is some value ranges where a gimbal lock could occur.

So you must change the constraint reference frame and setting X as the only free rotational axis by setting LoRange>HiRange.
arcwf
Posts: 7
Joined: Fri Mar 20, 2009 3:26 am

Re: Freeing a rotational axis with a 6DofConstraint

Post by arcwf »

projectileman is quite correct. Using the X axis as the "upright" axis does indeed work, but you need to change the reference frames so that the X axis becomes the world Y axis. Here is the code in our engine that uses this solution:

Code: Select all

    _bt_balancer_body = new btRigidBody(
        btRigidBody::btRigidBodyConstructionInfo(
            0, 0, 0, bt_vector_zero ) );

    // must use X axis as Y axis because 6dof wont spin freely on Y
    btTransform frameina( btTransform::getIdentity() );
    btTransform frameinb( btTransform::getIdentity() );
    frameina.getBasis().setEulerZYX( 0, 0, SIMD_HALF_PI );
    _bt_balancer_body->getWorldTransform()
        .getBasis().setEulerZYX( 0, 0, SIMD_HALF_PI );

    btGeneric6DofConstraint * sixdof = new btGeneric6DofConstraint(
        *_bt_rigid_body, *_bt_balancer_body,
        frameina, frameinb, true ); // use linear reference frame a
    sixdof->setLimit( 0, -SIMD_INFINITY, SIMD_INFINITY );
    sixdof->setLimit( 1, -SIMD_INFINITY, SIMD_INFINITY );
    sixdof->setLimit( 2, -SIMD_INFINITY, SIMD_INFINITY );
    sixdof->setLimit( 3, -SIMD_PI, SIMD_PI ); // only x axis can turn freely
    sixdof->setLimit( 4, 0, 0 );
    sixdof->setLimit( 5, 0, 0 );
    _bt_balancer_constraint = sixdof;
Also, Erwin posted http://www.bulletphysics.org/Bullet/php ... 436#p19436
a far simpler solution using btRigidBody::setAngularFactor.

Code: Select all

btVector3 angularfactor( 0, 1, 0 );
_bt_rigid_body->setAngularFactor( angularfactor );
Nevertheless, the btGeneric6DofConstraint solution is the best for us because our worlds are spherical planets, so the "upright" axis changes as bodies move rather than being fixed to the universal Y axis.

--Christopher :D
Post Reply