I am having a little trouble getting some bowling pins to fall over. Here is a video showing what happens.
http://www.youtube.com/watch?v=GM44YyIvNdI
As you can see the pins fly into the air ok when they are hit by the ball but they just all bounce back upright.
The pins themselves are created like so
Code: Select all
btTriangleMesh *trimesh = new btTriangleMesh(false,false);
//get mesh data
for(unsigned int i=0;i < mSubMeshes.size();++i)
{
btVector3 vertexPos[3];
const unsigned idxcnt = mSubMeshes[i]->num_triangles*3;
const unsigned short* idx = &mSubMeshes[i]->Indices[0];
for ( unsigned p=0; p<idxcnt; p+=3)
{
Vec3 p0 = mSubMeshes[i]->Vertices[idx[p+0]];
Vec3 p1 = mSubMeshes[i]->Vertices[idx[p+1]];
Vec3 p2 = mSubMeshes[i]->Vertices[idx[p+2]];
vertexPos[0] = btVector3(p0.x,p0.y,p0.z);
vertexPos[1] = btVector3(p1.x,p1.y,p1.z);
vertexPos[2] = btVector3(p2.x,p2.y,p2.z);
trimesh->addTriangle(vertexPos[0], vertexPos[1], vertexPos[2]);
}
}
btConvexShape* tmpConvexShape = new btConvexTriangleMeshShape(trimesh);
//create a hull approximation
btShapeHull* hull = new btShapeHull(tmpConvexShape);
btScalar margin = tmpConvexShape->getMargin();
hull->buildHull(margin);
tmpConvexShape->setUserPointer(hull);
btConvexHullShape* convexShape = new btConvexHullShape();
for (unsigned b=0;b<hull->numVertices();b++)
{
convexShape->addPoint(hull->getVertexPointer()[b]);
}
delete tmpConvexShape;
delete hull;
mCollisionShape = convexShape;
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(pos.x,pos.y,pos.z));
btScalar mass(2.f);
mMotionState = new btDefaultMotionState(startTransform);
mBody = mPhysicsMgr->createBody(mCollisionShape,mass,0,mMotionState);
mBody->setFriction(0.21f);
mBody->setDamping(0.1f,0.8f);
Code: Select all
mDynamicsWorld->stepSimulation(dt,10,1.0/200);
Any clues as to what i am doing wrong?
Thanks,
Tim