how to create bullet rigid body from pod models?

This topic contains 2 replies, has 3 voices, and was last updated by  warmi 8 years ago.

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #29930

    crazyazol
    Member

    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!

    #33400

    Gordon
    Moderator

    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: http://www.oolongengine.com

    #33401

    warmi
    Member

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

Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic.