Code: Select all
create the ground body
{
btScalar mass(0.);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
groundShape->calculateLocalInertia(mass,localInertia);
//using motionstate is recommended, it provides interpolation capabilities, and only synchronizes 'active' objects
btDefaultMotionState* myMotionState = new btDefaultMotionState(groundTransform);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,groundShape,localInertia);
btRigidBody* body = new btRigidBody(rbInfo);
//add the body to the dynamics world
dynamicsWorld->addRigidBody(body);
}
for(int i = 0; i < (int)_feibiao.nNumMeshNode; ++i) {
SPODNode& Node = _feibiao.pNode;
NSString *tmp = [NSString stringWithCString:Node.pszName];
NSRange r = [tmp rangeOfString:@"yltz"];
// if (r.location == NSNotFound) {
// continue;
// }
SPODMesh& Mesh = _feibiao.pMesh[Node.nIdx];
PVRTModelPODToggleInterleaved(Mesh);
btConvexHullShape *hullShape = new btConvexHullShape((const btScalar*)Mesh.sVertex.pData, Mesh.sVertex.n, Mesh.sVertex.nStride);
btDefaultMotionState* fallMotionState =
new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1),btVector3(0,50,0)));
btScalar mass = 1;
btVector3 fallInertia(0,0,0);
hullShape->calculateLocalInertia(mass,fallInertia);
btRigidBody::btRigidBodyConstructionInfo fallRigidBodyCI(mass,fallMotionState,hullShape,fallInertia);
btRigidBody *fallRigidBody = new btRigidBody(fallRigidBodyCI);
btVector3 g = fallRigidBody->getGravity();
dynamicsWorld->addRigidBody(fallRigidBody);
}