Sign in to follow this  
lucky6969b

[Bullet] Rigid Bodies penetrate static geometries?

Recommended Posts

void Physics::addStaticMesh(CObjects* pObj) {
   m_pObj = pObj;   
     
   D3DXVECTOR3 vMin, vMax;
   pObj->m_Mesh->GetBoundingBox(vMin, vMax);
   float width = vMax.x - vMin.x;
   float length = vMax.y - vMin.y;
   float height = vMax.z - vMin.z;

   btBoxShape *shape = new btBoxShape(btVector3(width / 2.0f, length / 2.0f, height / 2.0f));

   m_collisionShapes.push_back(shape);
   {
      btScalar mass(0.0f);      

      //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)
         shape->calculateLocalInertia(mass,localInertia);
       
      btTransform trans;
      trans.setIdentity();

      btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,0,shape,localInertia);   
      btRigidBody* body = new btRigidBody(rbInfo);   
      body->setWorldTransform(trans);
      body->setCollisionFlags(body->getCollisionFlags() | btCollisionObject::CF_STATIC_OBJECT);
      

      //add the body to the dynamics world
      m_dynamicsWorld->addRigidBody(body);

      
   }
}

void Physics::addMesh(CObjects* pObj) {
   m_pObj = pObj;   
         
   D3DXVECTOR3 vMin, vMax;
   pObj->m_Mesh->GetBoundingBox(vMin, vMax);
   float width = vMax.x - vMin.x;
   float length = vMax.y - vMin.y;
   float height = vMax.z - vMin.z;

   btBoxShape *shape = new btBoxShape(btVector3(width / 2.0f, length / 2.0f, height / 2.0f));   

   m_collisionShapes.push_back(shape);
   {
      btScalar mass(10.0f);     
 
      bool isDynamic = (mass != 0.f);

      btVector3 localInertia(0,0,0);
      if (isDynamic)
         shape->calculateLocalInertia(mass,localInertia);
 
      // Object and MotionState get back pointers both ways
      MyMotionState* ms = new MyMotionState(pObj);
      pObj->SetSimMotionState(ms);   

      btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,ms,shape,localInertia);   
      btRigidBody* body = new btRigidBody(rbInfo);         

      //add the body to the dynamics world
      m_dynamicsWorld->addRigidBody(body);
   }
}

I add background static geometry using the first method, and dynamic objects using the second.

But they don't seem to interact with each other during the simulation steps?

I wonder why this is the case?

Thanks

Jack

Edited by lucky6969b

Share this post


Link to post
Share on other sites

Have you tried calculating local inertia regardless if it is static or not?

It looks like I am doing pretty much the same thing as you except the only difference that I have between static and dynamic is that static objects have a mass of 0

 

Ryan.

HTH

Share this post


Link to post
Share on other sites

My guess would be its your collision flags. Try it without modifying the static ones flags.

I think i would just set the mass to 0 or not for a static object. But would have to verify the exact usage of the collision flags.

 

And i guess you have verified with debug drawing your shapes are where you think they are?

Same space etc.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this