Physics Simulation Forum

 

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Dec 15, 2009 6:23 am 
Offline

Joined: Sat Dec 09, 2006 8:10 am
Posts: 13
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:
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.


Top
 Profile  
 
PostPosted: Tue Dec 15, 2009 10:49 pm 
Offline
User avatar

Joined: Thu Dec 14, 2006 4:27 pm
Posts: 109
Location: Colombia
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.


Top
 Profile  
 
PostPosted: Tue Jul 27, 2010 4:00 pm 
Offline

Joined: Fri Mar 20, 2009 3:26 am
Posts: 7
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:
    _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 viewtopic.php?f=9&t=3369&p=19436#p19436
a far simpler solution using btRigidBody::setAngularFactor.

Code:
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Jonathan and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group