Jump to content
  • Advertisement
Sign in to follow this  
lucky6969b

Object falling thru when specifying motion state in btRigidBody

This topic is 1001 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

Sorry, Got nothing to do in holidays. So flipping the work again.
Hello Merry Christmas first,

void cPhysics::addMesh(CObject* pObj) {
   
    
   D3DXVECTOR3 vMin, vMax;
   pObj->GetMesh()->GetBox(&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);   
   AgentMotionState* motionState = new AgentMotionState(pObj);
   pObj->SetSimMotionState(motionState);
   btTransform transform;
   motionState->getWorldTransform(transform);
   localCreateRigidBody(10.0f, motionState, transform, shape);
    
}



    

btRigidBody* cPhysics::localCreateRigidBody(float mass, AgentMotionState* ms, const btTransform& startTransform,btCollisionShape* shape)
{
    btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE));

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

    btRigidBody* body = new btRigidBody(mass,0,shape,localInertia);    
    body->setWorldTransform(startTransform);
    body->setContactProcessingThreshold(m_defaultContactProcessingThreshold);
    m_dynamicsWorld->addRigidBody(body);

    return body;
}
When I specify the second parameter in btRigidBody, all movable objects fall thru the
non-movable ones.
But If I don't, no effects are observed in GameObjects about physics.
Any ideas?
Thanks
Jack

Share this post


Link to post
Share on other sites
Advertisement

Maybe you need to set collision flags or set activation state to disable de-activation? Here is my helper routine ... 

 

btRigidBody* CPhysicsEngine::CreateRigidBody( float mass, const btTransform& startTransform, btCollisionShape* shape, COLLISION_DATA *pCD )
{
    btAssert((!shape || shape->getShapeType() != INVALID_SHAPE_PROXYTYPE));
 
    //
    // 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);
 
    //
    // Using motionstate is recommended, it provides interpolation capabilities,
    // and only synchronizes 'active' objects.
    //
#if 1
    btDefaultMotionState* myMotionState = new btDefaultMotionState(startTransform);
    btRigidBody::btRigidBodyConstructionInfo cInfo(mass,myMotionState,shape,localInertia);
    btRigidBody* body = new btRigidBody(cInfo);
#else
    btRigidBody* body = new btRigidBody(mass,0,shape,localInertia); 
    body->setWorldTransform(startTransform);
#endif
 
    pCD->m_pRigidBody = body;
    body->setUserPointer( (void *)pCD );
    if (isDynamic)
    {
        body->setContactProcessingThreshold(0.0f);
    }
    body->setGravity( btVector3( 0.0f, -30.0f, 0.0f ) );
    body->setCollisionFlags( btCollisionObject::CF_KINEMATIC_OBJECT );
    body->setActivationState(DISABLE_DEACTIVATION);
 
    m_dynamicsWorld->addRigidBody(body);
 
    return body;
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!