I'm attempting to write a joint similar in function to ODE's "universal joint". For those not familar with the universal joint, it's like having two hinges perpendicular to eachother to form a joint between two bodies. Here's ODE's info on it:
http://opende.sourceforge.net/wiki/inde ... #Universal
I figured I could use a 6 DOF constraint set up such that the angular limits would represent the two perpendicular axes.
Here's the relevant code -- note that the function STB converts my matrix/vector types to bullet's.
Code: Select all
// create a matrix with x and y axes corresponding to universal joint parent/child axes
vec3 xAxis = normalize( parentAxis );
vec3 yAxis = normalize( childAxis );
vec3 zAxis = cross( xAxis, yAxis );
yAxis = cross( xAxis, zAxis );
mat4 pivot;
pivot.setRow(0, vec4( xAxis,0 ) );
pivot.setRow(1, vec4( yAxis,0 ) );
pivot.setRow(2, vec4( zAxis,0 ) );
// position it at "anchor" point
pivot.setCol(3, vec4( anchor, 0 ));
// create local reference frames for the pivot
btTransform frameInA = STB( parent->transform().inverse() * pivot );
btTransform frameInB = STB( child->transform().inverse() * pivot );
_constraint = new btGeneric6DofConstraint( *bulletParent->bulletRigidBody(), *bulletChild->bulletRigidBody(), frameInA, frameInB, true );
const btVector3 linearLimit = STB( child->position() - pivot.position() );
_constraint->setLinearLowerLimit( linearLimit );
_constraint->setLinearUpperLimit( linearLimit );
_constraint->setAngularLowerLimit( btVector3( -PI/4, -PI/4, 0 ) );
_constraint->setAngularUpperLimit( btVector3( +PI/4, +PI/4, 0 ) );
The way I see it, I could be screwing up the frameInA & frameInB, or I could be screwing up the application of angular/linear limits afterwards -- or both.
Am I barking up the wrong tree? Perhaps there's a constraint more suited to this purpose? Either way, I clearly don't get the 6 DOF constraint and any pointers as to how to use it would help me a lot.