how to create bullet rigid body from pod models?

crazyazreal
Posts: 1
Joined: Tue Sep 22, 2009 2:41 am

how to create bullet rigid body from pod models?

Post by crazyazreal »

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:

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); 
     } 

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!