AWPGeneric6DofConstraint problem

Software: Away3D 4.x

dona, Jr. Member
Posted: 24 September 2012 07:56 AM   Total Posts: 46

Hi,

I was trying to use AWPGeneric6DofConstraint. It shows some buggy results,

Here is the needs and codes,

//creating the joint
dofJoint = new AWPGeneric6DofConstraint(boxBody, new Vector3D(), boxBody.rotation.clone());

//angular limits
var angularLimits:Number = 50 * AWPMath.DEGREES_TO_RADIANS;

//setting the x_axis rotational limit.
dofJoint.getRotationalLimitMotor(0).loLimit = -angularLimits;
dofJoint.getRotationalLimitMotor(0).hiLimit = angularLimits; 
dofJoint.getRotationalLimitMotor(0).enableMotor = true;

//free rotation around y_axis, by giving Lowerlimit > Upperlimit
dofJoint.getRotationalLimitMotor(1).loLimit = angularLimits;
dofJoint.getRotationalLimitMotor(1).hiLimit =-angularLimits;
dofJoint.getRotationalLimitMotor(1).enableMotor = false;

 
//setting the z_axis rotational limit.
dofJoint.getRotationalLimitMotor(2).loLimit = -angularLimits;
dofJoint.getRotationalLimitMotor(2).hiLimit = angularLimits;
dofJoint.getRotationalLimitMotor(2).enableMotor = true;

//setting the linear limits to zero
dofJoint.setLinearLimit(new Vector3D(), new Vector3D());
physicsWorld.addConstraint(dofJoint, true);


But when i’m updating the boxBody.rotationY -= .1 in a timer loop, that boxBody rotating around Y_AXIS up to -90 degree, not giving free rotation.I think i missed something to give full free rotation around Y_AXIS. Anybody knows about it?


Thanks

 

 

 

   

John Brookes, Moderator
Posted: 24 September 2012 09:20 AM   Total Posts: 732   [ # 1 ]

http://code.google.com/p/bullet/source/browse/trunk/src/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.h
Line 235 and on

Angular limits must be in these ranges:
X : [-INF, INF]
Y : [-PI/2, PI/2]
Z : [-INF, INF]

Just use X or Z for free rotation.

   

dona, Jr. Member
Posted: 24 September 2012 09:37 AM   Total Posts: 46   [ # 2 ]

Thanks John, very useful information!

   

dona, Jr. Member
Posted: 24 September 2012 06:49 PM   Total Posts: 46   [ # 3 ]

Again, found a strange problem,(might be my error, i haven’t noticed yet), when i’m updating a rigid body rotation, rotationY+=0.1 without using any constraint it shows the same problem, that rotates upto 90 degrees.Do you know the logic behind it?

   

dona, Jr. Member
Posted: 24 September 2012 07:25 PM   Total Posts: 46   [ # 4 ]

I understand how to rotate it from your answer in http://away3d.com/forum/viewthread/3218/

But i didn’t understand the logic behind rotationY limit (-90< rotationY < 90) while using rotationY+=1

   

Yang Li, Administrator
Posted: 25 September 2012 12:04 AM   Total Posts: 80   [ # 5 ]

I think it relate to gimbal lock(http://en.wikipedia.org/wiki/Gimbal_lock)

   

dona, Jr. Member
Posted: 25 September 2012 05:06 AM   Total Posts: 46   [ # 6 ]

Thanks Yang li,

I thought to create a Generic6DofConstraint for keeping a vehicle upright.Could you suggest a best work around for this issue?

   

John Brookes, Moderator
Posted: 27 September 2012 01:59 PM   Total Posts: 732   [ # 7 ]

Just use the rollInfluence.
That and the amount of friction will stop the vehicle rolling over.

You can also use compound shapes to lower the center of gravity on the vehicle.
see
https://docs.google.com/document/edit?id=18edpOwtGgCwNyvakS78jxMajCuezotCU_0iezcwiFQc


Not related to vehicles but to freeze an axis of a rigidbody use angularFactor
eg
myRb.angularFactor = new vector3D(0,1,0);//only rotates in Y

   

dona, Jr. Member
Posted: 27 September 2012 02:30 PM   Total Posts: 46   [ # 8 ]

Thanks a lot John,

I tried using angularFactor, my application needs some degree of freedom around each axis. I’ll get back to you with your first two suggestions results. I hope it will work.

   

Mal Duffin, Newbie
Posted: 03 December 2013 12:24 AM   Total Posts: 14   [ # 9 ]

I’m seeing the same issue, has anyone found a solution to this ( not allowing the vehicle to roll over a certain amount in the x and z, but have full rotation around in y ).

As soon as I set the 6dof angular limits, they all seem to get used.

I tried both setAngularLimit…

aConstraint2.setAngularLimit(new Vector3D(0, 0, 0), new Vector3D(0, 0, 0));

and getRotationalLimitMotor ( aIndex )...

var aRotLimit:AWPRotationalLimitMotor = aConstraint.getRotationalLimitMotor ( 1 );
  aRotLimit.enableMotor = false;

Setting enableMotor to false doesn’t seem to work.

In the source, the check for the limit is…
public function isLimited() : Boolean {
  if (loLimit > hiLimit) return false;

I’ve also made sure that loLimit is say 1, and hiLimit is -1.

In the source file…
https://github.com/away3d/awayphysics-core-fp11/blob/master/Bullet/BulletDynamics/ConstraintSolver/btGeneric6DofConstraint.cpp

I noticed that at line 488, the linearLimits are tested to see if they are limited before the code runs for the 3 linear axis ( line 486 )

if (m_linearLimits.isLimited(i))

However, no check is done for isLimited for the 3 angular axis ( line 506 )

Should the ‘if (testAngularLimitMotor(i))’ code be wrapped with a…

if (m_angularLimits.isLimited(i))

in order to get this working OK?

 

   

Mal Duffin, Newbie
Posted: 03 December 2013 12:46 AM   Total Posts: 14   [ # 10 ]

One last thing, just in case it helps…

If I set the rotation for the z to be just under PI/2 ( 90 ) in both directions, the code allows for that rotation in a stable fashion.

aRotLimit.loLimit = -(Math.PI / 2 ) + 0.1;
aRotLimit.hiLimit = (Math.PI / 2 ) - 0.1;

If I remove the 0.1’s, when the vehicle hits the limits, it flips out and gets launced into a weird spin.

   

Mal Duffin, Newbie
Posted: 03 December 2013 12:21 PM   Total Posts: 14   [ # 11 ]

Just saw this in the Bullet forums, seems like a known issue…

http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=4457

Will try to use that work-around that was mentioned ( rotating the constraint, using x as up and then constraining the other axis )

   

Mal Duffin, Newbie
Posted: 05 December 2013 03:14 PM   Total Posts: 14   [ # 12 ]

Here’s a working solution for anyone having the same issue…

private function addRotationConstraintToVehicle ( aCar:AWPRaycastVehicle ):void
{
var aRigidBody:AWPRigidBody = aCar.getRigidBody ();
 
var aRB2:AWPRigidBody = new AWPRigidBody ( new AWPSphereShape ( 0.01 ) );
aRB2.collisionFlags = AWPCollisionFlags.CF_NO_CONTACT_RESPONSE;
 
var aConstraint:AWPGeneric6DofConstraint = new AWPGeneric6DofConstraint ( aRigidBody, new Vector3D (), aRigidBody.rotation.clone (), aRB2, new Vector3D (), new Vector3D ( 0, 0, 90 ) );
var aRotRangeLimit:Number = 0.2; // Angle to allow car to roll  
 
var aLinearRange:Number = int.MAX_VALUE;
aConstraint.setLinearLimit ( new Vector3D ( -aLinearRange, -aLinearRange, -aLinearRange ), new Vector3D ( aLinearRange, aLinearRange, aLinearRange ) );

aConstraint.setAngularLimit ( new Vector3D ( 1, -aRotRangeLimit, -Math.PI / 2 - aRotRangeLimit ), new Vector3D ( -1, aRotRangeLimit, -Math.PI / 2 + aRotRangeLimit ) );

physicsWorld.addConstraint ( aConstraint, true );

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X