The suspension in btRayCastVehicle has a variation of what I want, so I figured I would follow suit and implement btActionInterface. The problem is that when "updateAction" gets called (it really does get called) to apply the requisite forces to the nodes of a soft body through addForce and addVelocity, nothing happens.
You can just temporarily replace the "SoftDemo" source directory with the contents of the following zip to try my code.
http://www.cs.ucla.edu/~alexalex/SoftDemo.zip
I got it to work with rigid bodies, but I need soft bodies too. I suppose I could just move my code into the same place the mouse picking is done, but this would be a lot better I think.
::: My "Spring" class. Currently it just attempts to apply a random impulse to the 0th node :::
Code: Select all
class Spring4Soft : public btActionInterface
{
public:
btSoftBody* mBodyB;
btScalar mRestLength;
btScalar mStiffness;
btScalar mDamping;
int softBodyNodeA;
Spring4Soft()
{
mRestLength = btScalar(2.);
mStiffness= btScalar(50);
mDamping= btScalar(.5);
}
virtual void updateAction( btCollisionWorld* collisionWorld, btScalar step)
{
btVector3 forceVector = btVector3(-10,10,10);
mBodyB->addVelocity(-forceVector, 0); //try to apply a random impulse to the first soft body node.
}
void debugDraw (btIDebugDraw *debugDrawer){}
};
Code: Select all
//
// 100kg Stanford's bunny
//
static void Init_Bunny(SoftDemo* pdemo)
{
//TRACEDEMO
btSoftBody* psb=btSoftBodyHelpers::CreateFromTriMesh(pdemo->m_softBodyWorldInfo,gVerticesBunny,
&gIndicesBunny[0][0],
BUNNY_NUM_TRIANGLES);
btSoftBody::Material* pm=psb->appendMaterial();
pm->m_kLST = 0.5;
pm->m_flags -= btSoftBody::fMaterial::DebugDraw;
psb->generateBendingConstraints(2,pm);
psb->m_cfg.piterations = 2;
psb->m_cfg.kDF = 0.5;
psb->randomizeConstraints();
psb->scale(btVector3(6,6,6));
psb->setTotalMass(100,true);
Spring4Soft* springo = new Spring4Soft();
springo->mBodyB = psb;
pdemo->getSoftDynamicsWorld()->addAction(springo);
pdemo->getSoftDynamicsWorld()->addSoftBody(psb);
pdemo->m_cutting=true;
}