First I would try something easier, like a btPoint2PointConstraint (maybe with some CFM, ERP setting to simulate springiness) to see if everything works as expected, and just after it does would I move on to btGeneric6DofConstraint and btGeneric6DofSpringConstraint.
Theoretically speaking all you need to do is converting the anchor points from world space to local space. I would try something like this:
Code: Select all
void GenericJointDemo::link( btRigidBody* bodyA, btRigidBody* bodyB, const btVector3& anchorA, const btVector3& anchorB )
{
btTransform localA;
btTransform localB;
localA.setIdentity();
localB.setIdentity();
// Setting world space origin
localA.setOrigin( anchorA );
localB.setOrigin( anchorB );
// Calculating local space origin
localA = bodyA->getCenterOfMassTransform().inverse() * localA;
localB = bodyB->getCenterOfMassTransform().inverse() * localB;
// Creating constraint
btGeneric6DofConstraint* constraint = new btGeneric6DofConstraint( *bodyA, *bodyB, localA, localB, true );
// Rotation is free
constraint->setAngularLowerLimit( btVector3( 1, 1, 1 ) );
constraint->setAngularUpperLimit( btVector3( -1, -1, -1 ) );
// Adding constraint
m_dynamicsWorld->addConstraint( constraint );
bodyA->activate( true );
bodyB->activate( true );
}
I have tried it in GenericJointDemo, but it does not really matter, the only thing you need is a btDynamicsWorld.
Hope this helps.