main body.
Code: Select all
int main(int argc, char** argv)
{
btDefaultMotionState *motionState;
btBroadphaseInterface* broadphase;
btDefaultCollisionConfiguration* collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
btSoftBodyWorldInfo m_softBodyWorldInfo;
btCollisionDispatcher* dispatcher = new btCollisionDispatcher(collisionConfiguration);
m_softBodyWorldInfo.m_dispatcher = dispatcher;
btVector3 worldAabbMin(-1000,-1000,-1000);
btVector3 worldAabbMax(1000,1000,1000);
broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax);
m_softBodyWorldInfo.m_broadphase = broadphase;
btSequentialImpulseConstraintSolver* solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btSoftRigidDynamicsWorld (dispatcher, broadphase, solver,collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0,-0.1,0));
m_softBodyWorldInfo.m_gravity.setValue(0,-0.1,0);
m_softBodyWorldInfo.m_sparsesdf.Initialize();
//create Object
btScalar mass(0.010f);
bool isDynamic = (mass != 0.f);
btVector3 localInertia(1,1,1);
psb=btSoftBodyHelpers::CreateFromTriMesh(m_softBodyWorldInfo,gVerticesBunny, &gIndicesBunny[0][0], BUNNY_NUM_TRIANGLES);
btSoftBody::Material* pm=psb->appendMaterial();
pm->m_kLST = 0.01;
pm->m_kAST = 0.01;
pm->m_kVST = 0.01;
psb->generateBendingConstraints(2,pm);
psb->m_cfg.piterations = 2;
psb->m_cfg.kDF = 0.5;
psb->m_cfg.collisions |= btSoftBody::fCollision::VF_SS;
psb->randomizeConstraints();
btMatrix3x3 m;
m.setEulerZYX(0,-SIMD_PI/2,0);
psb->transform(btTransform(m,btVector3(2,4,0)));
psb->scale(btVector3(20,20,20));
psb->setTotalMass(0.02,true);
psb->setVelocity(btVector3(-10,0,0));
dynamicsWorld->addSoftBody(psb);
//OpenGL init
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(1024, 1024);
glutCreateWindow("PROJECT");
myInit();
glutReshapeFunc(myReshape);
glutDisplayFunc(draw);
glutIdleFunc(timer);
glutMainLoop();
}The only part I find question is the timestep, but I don't think that's the case. Here is the timer:
Code: Select all
void timer(void)
{
float dtime = time;
time = glutGet(GLUT_ELAPSED_TIME) / 500.0;
dtime = time - dtime;
if(dynamicsWorld)
dynamicsWorld->stepSimulation(dtime, 100);
}