I'm trying to create a soft body sphere using code from the Soft Body Demo. I got it loaded and could see it in the debug drawer, but once I started stepping the simulation it vanished. I've tried disabling the simulation on "brush", my soft body variable, using setActivationState but that didn't seem to change anything.
I'm fairly certain that "brush" isn't moving anywhere since my simulation has no gravity and it's the only object in the world, but I'm not sure how to check its position since getWorldTransform().getOrigin() always returns btVector3(0, 0, 0).
Loading code
Code:
void loadObj(const char* fileName, btVector3 &position, btScalar scaling)
{
ConvexDecomposition::WavefrontObj wo;
int loadedWO = wo.loadObj(fileName);
if(loadedWO)
{
btVector3* d = new btVector3[wo.mTriCount * 3];
btVector3 localScaling(scaling, scaling, scaling);
int i;
for ( i = 0; i < wo.mTriCount;i++)
{
int index0 = wo.mIndices[i*3];
int index1 = wo.mIndices[i*3+1];
int index2 = wo.mIndices[i*3+2];
btVector3 vertex0(wo.mVertices[index0*3], wo.mVertices[index0*3+1],wo.mVertices[index0*3+2]);
btVector3 vertex1(wo.mVertices[index1*3], wo.mVertices[index1*3+1],wo.mVertices[index1*3+2]);
btVector3 vertex2(wo.mVertices[index2*3], wo.mVertices[index2*3+1],wo.mVertices[index2*3+2]);
vertex0 *= localScaling;
vertex1 *= localScaling;
vertex2 *= localScaling;
d[i * 3] = vertex0;
d[i * 3 + 1] = vertex1;
d[i * 3 + 2] = vertex2;
}
brush = btSoftBodyHelpers::CreateFromConvexHull(worldInfo, d, wo.mTriCount * 3);
brush->generateBendingConstraints(2);
btTransform trans;
trans.setIdentity();
trans.setOrigin(position);
brush->transform(trans);
dynamicsWorld->addSoftBody(brush);
}
}
Update method
Code:
void update(double elapsed)
{
dynamicsWorld->stepSimulation(elapsed);
btVector3 pos = brush->getWorldTransform().getOrigin();
std::cout << pos.x() << " " << pos.y() << " " << pos.z() << std::endl;
}