• Advertisement
Sign in to follow this  

[Bullet] Rigid Bodies penetrate static geometries?

This topic is 1134 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement

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
Sign in to follow this  

  • Advertisement