I know that i have to use the btPoint2PointConstraint.
i have made this
Code: Select all
btVector3 pos;
btRigidBody* body[6]; //chain object
//***********************************************************************//
//main object the begin of the chain
btCollisionShape* boxShape = new btSphereShape(btScalar(1.));
m_collisionShapes.push_back(boxShape);
boxShape->setMargin(gCollisionMargin);
btTransform trans;
trans.setIdentity();
pos.setValue(btScalar(0.),btScalar(14.),btScalar(0.));//posiçao do topo da corrente
trans.setOrigin(pos);
body[0]=localCreateRigidBody(btScalar(0.),trans,boxShape);
//***********************************************************************//
//********************************chain******************************//
btCollisionShape* sphereShape = new btSphereShape(btScalar(1.));
//sphere
//***********************************************************************//
boxsize=1;
int i=1;
for(i=1;i<=1;i++){
sphereShape->setMargin(gCollisionMargin);
trans.setIdentity();
pos.setValue(btScalar(0.),btScalar(14.-i*2*boxsize),btScalar(0.));
trans.setOrigin(pos);
body[i] = localCreateRigidBody(btScalar(1.),trans,sphereShape);
btVector3 pivotInA(HALF_EXTENTS,-HALF_EXTENTS,-HALF_EXTENTS);
btVector3 pivotInB;
pivotInB=body[i]->getCenterOfMassTransform().inverse()(body[i-1]->getCenterOfMassTransform()(pivotInA));
btTypedConstraint* p2p = new btPoint2PointConstraint(*body[i-1],*body[i],pivotInA,pivotInB);
m_dynamicsWorld->addConstraint(p2p);
}
btVector3 pivotInB;
pivotInB=body->getCenterOfMassTransform().inverse()(body[i-1]->getCenterOfMassTransform()(pivotInA));
and another question, how can i make the chain act like a chain , i mean make the balls (in my case stick together)