I tried to find similar question but could not find. I am trying to render the bunny soft body (one that comes with the demo application) in my own code base. It runs fine however, there is an offset between where the plane is and where the collision takes place. Here is the output that I get
This is how I render the mesh
Code: Select all
int cnt=0;
for(size_t i=0;i< bunny->m_nodes.size();i++) {
gVerticesBunny[cnt++] = bunny->m_nodes[i].m_x.x();
gVerticesBunny[cnt++] = bunny->m_nodes[i].m_x.y();
gVerticesBunny[cnt++] = bunny->m_nodes[i].m_x.z();
}
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, sizeof(float)*3, gVerticesBunny);
glDrawElements(GL_TRIANGLES, BUNNY_NUM_TRIANGLES*3, GL_UNSIGNED_INT , gIndicesBunny);
glDisableClientState(GL_VERTEX_ARRAY);
Code: Select all
gVerticesBunny[cnt++] = bunny->m_nodes[i].m_x.y()-0.35;
My question is why is this 0.35 offset in the rendered output ?
Am i rendering the mesh wrongly.
Here is the scene setup code.
Code: Select all
void InitBullet() {
const int maxProxies = 32766;
collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
solver = new btSequentialImpulseConstraintSolver;
btVector3 worldAabbMin(-1000,-1000,-1000);
btVector3 worldAabbMax(1000,1000,1000);
broadphase = new btAxisSweep3(worldAabbMin,worldAabbMax,maxProxies);
softBodyWorldInfo.m_broadphase = broadphase;
dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,broadphase,solver,collisionConfiguration);
btVector3 gravity = btVector3(0,-9.8f,0);
dynamicsWorld->getDispatchInfo().m_enableSPU = true;
dynamicsWorld->setGravity(gravity);
groundShape = new btStaticPlaneShape(btVector3(0,1,0),0.0);
btDefaultMotionState* groundMotionState = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,0,0)));
btRigidBody::btRigidBodyConstructionInfo groundRigidBodyCI(0,groundMotionState,groundShape,btVector3(0,0,0));
groundRigidBody = new btRigidBody(groundRigidBodyCI);
dynamicsWorld->addRigidBody(groundRigidBody);
softBodyWorldInfo.m_dispatcher = dispatcher;
softBodyWorldInfo.m_gravity=gravity;
softBodyWorldInfo.m_sparsesdf.Initialize();
bunny=btSoftBodyHelpers::CreateFromTriMesh(softBodyWorldInfo, gVerticesBunny, &gIndicesBunny[0][0], BUNNY_NUM_TRIANGLES);
bunny->m_cfg.kDF = 0.75f;
bunny->m_cfg.kMT = 0.25f;
bunny->m_cfg.kVC = 0.5f;
bunny->m_cfg.piterations = 5;
bunny->m_cfg.collisions = btSoftBody::fCollision::CL_RS;
bunny->randomizeConstraints();
bunny->generateClusters(5);
bunny->setTotalMass(100,true);
bunny->setPose(false,true);
bunny->translate(btVector3(0,10,0));
dynamicsWorld->addSoftBody(bunny);
}
Mobeen