I've been doing some stuff with the library it's great! I'm new to C++, but i've have programmed in C my hole life, I tell you that because maybe there's something I'm not doing properly!
The project I'm working on is an Hexapod (hexapod hexample).
So I've started with a basic leg which is 3DOF. This is what it should look like IRL:

And this is how I code it:
Code: Select all
btRigidBody *boxF = new btRigidBody ( 100.0 , //dat mass
new btDefaultMotionState( btTransform(btQuaternion(0,0,0,1),btVector3(0,0,5))),
new btBoxShape( btVector3(1,1,1)) ,
btVector3 (0,0,0) );
btRigidBody *box0 = new btRigidBody ( 1.0 , //dat mass
new btDefaultMotionState( btTransform(btQuaternion(0,0,0,1),btVector3(0,0,10))),
new btSphereShape( (1)) , //technically not a box
btVector3 (0,0,0) );
btRigidBody *box1 = new btRigidBody ( 1.0, //dat mass
new btDefaultMotionState( btTransform(btQuaternion(0,0,0,1),btVector3(-5,0,10))),
new btBoxShape( btVector3(2.5,0.75,0.75)) ,
btVector3 (0,0,0) );
btRigidBody *box2 = new btRigidBody ( 1.0 , //dat mass
new btDefaultMotionState( btTransform(btQuaternion(0,0,0,1),btVector3(-19,0,10))),
new btBoxShape( btVector3(10,0.25,0.25)) ,
btVector3 (0,0,0) );
btHingeConstraint *q0 = new btHingeConstraint ( *box0, btVector3(0,0,0) , btVector3(0,0,1) ) ;
box0->addConstraintRef(q0);
btHingeConstraint *q1 = new btHingeConstraint ( *box0, *box1,
btVector3(-1.5,0,0) , btVector3(3,0,0),
btVector3(0,1,0) , btVector3(0,1,0) );
box0->addConstraintRef(q1);
box1->addConstraintRef(q1);
btHingeConstraint *q2 = new btHingeConstraint( *box1, *box2,
btVector3(-3,0,0) , btVector3(10.5,0,0),
btVector3(0,1,0) , btVector3(0,1,0) );
box1->addConstraintRef(q2);
box2->addConstraintRef(q2);
dynamicsWorld->addRigidBody(box0);
dynamicsWorld->addRigidBody(box1);
dynamicsWorld->addRigidBody(box2);
dynamicsWorld->addConstraint(q0);
dynamicsWorld->addConstraint(q1);
dynamicsWorld->addConstraint(q2);
dynamicsWorld->addRigidBody(boxF);

And I've tried not adding the first hinge (q0) and this is what happens:

Is there anything I'm doing wrong? I don't get it... why doesn't the leg "falls" and bends in the hinges?