Fix constraint

pkk007
Posts: 2
Joined: Fri Aug 10, 2012 10:13 am

Fix constraint

Post by pkk007 »

Hi everyone,

I am a student and using bullet for doing some self-assembly simulation like this: http://youtu.be/0CcJTgPgxvw

What I need is when two components arrive at the right positions, combine them to make them become a new structure. I usd constraint for connecting two components (btGeneric6DofConstraint or btPoint2PointConstraint). However, it seems that it will merge islands and bounce when one object is being squeezed by others.
I have seted the CFM and ERP parameter like this:

Code: Select all

p2p=new btGeneric6DofConstraint(*molecules[IDs[1]].link,*molecules[IDs[2]].link,frameInA,frameInB,true);
m_dynamicsWorld->addConstraint(p2p);
p2p ->setBreakingImpulseThreshold(n_breakingImpulseThreshold);

for(p=0;p<6;p++)
{
     p2p->setParam(BT_CONSTRAINT_STOP_CFM, 0.0, p);
     p2p->setParam(BT_CONSTRAINT_STOP_ERP, 0.2, p);
}
But it is still useless. How can I get a fix constraint?
Or should I used btCompoundShape instead of constraint?

Many thanks.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Fix constraint

Post by Erwin Coumans »

The Bullet/Demos/VoronoiFractureDemo glues objects together using a btGeneric6DofConstraint, here is some code snippet:

Code: Select all

      btGeneric6DofConstraint* dof6 = new btGeneric6DofConstraint(*body0,*body1,trA,trB,true);
      dof6->setOverrideNumSolverIterations(100);

     float totalMass = 1.f/body0->getInvMass() + 1.f/body1->getInvMass();

     dof6->setBreakingImpulseThreshold(BREAKING_THRESHOLD*totalMass);

     for (int i=0;i<6;i++)
           dof6->setLimit(i,0,0);
     getDynamicsWorld()->addConstraint(dof6,true);


Can you check the demo? You might be missing the 'setLimit' part?
Hope this helps,
Erwin