2
\$\begingroup\$

I would like to transform a rigidbody after adding it to the btDiscreteDynamicsWorld. When I use the CF_KINEMATIC_OBJECT flag I am able to transform it but it's static (no collision response/gravity). When I don't use the CF_KINEMATIC_OBJECT flag the transform doesn't gets applied. So how to I transform non-static objects in bullet?


DemoCode:

btBoxShape* colShape = new btBoxShape(btVector3(SCALING*1,SCALING*1,SCALING*1));

/// Create Dynamic Objects
btTransform startTransform;
startTransform.setIdentity();

btScalar mass(1.f);

//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)
    colShape->calculateLocalInertia(mass,localInertia);

btDefaultMotionState* myMotionState = new btDefaultMotionState();
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass,myMotionState,colShape,localInertia);

btRigidBody* body = new btRigidBody(rbInfo);
body->setCollisionFlags(body->getCollisionFlags()|btCollisionObject::CF_KINEMATIC_OBJECT);
body->setActivationState(DISABLE_DEACTIVATION);

m_dynamicsWorld->addRigidBody(body);

startTransform.setOrigin(SCALING*btVector3( btScalar(0), btScalar(20), btScalar(0) ));

body->getMotionState()->setWorldTransform(startTransform);
\$\endgroup\$
2
\$\begingroup\$

I solved it by using body->setWorldTransform(startTransform); and not body->getMotionState()->setWorldTransform(startTransform);. I also removed the Kinematic flag and the deactivation.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .