Advertisement

Object falling thru when specifying motion state in btRigidBody

Started by December 26, 2015 07:17 AM
0 comments, last by Steve_Segreto 9 years, 1 month ago

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

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

This topic is closed to new replies.

Advertisement