hello, i’ am writting a 3d game demo, use pod model and bullet physics engine, i want to create physics from my pod models. i’am using btConvexHullShape to create rigid from mesh:
// 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);
}
these code can run, but i think it’s does not right, because when run the demo, the fallRigidBody it’s does not collide with the ground body…help!
I’m not sure we can really help you with this here as we don’t work with Bullet. It’s possible that the guys at the Oolong engine list will be better equipped to answer this question.
You can find this here: www.oolongengine.com
You should enable bullet’s own debugging display which will show you exactly how your shapes are being created and how they are placed in relation to your models.
The only thing you need to do is derive a simple class from btIDebugDraw and implement
a single method :
virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color);