I've done some further investigation, and discovered that the problem only occurs when I set the kinematic rigid body's position after I create it, rather than in a MotionState passed to the constructor. That is to say, if I do:
Code: Select all
btCollisionShape* shape = new btBoxShape(btVector3(0.5, 0.5, 0.5));
btVector3 inertia(0, 0, 0);
double mass = 0.0;
btTransform trans;
trans.setIdentity();
trans.setOrigin(btVector3(0, 10, 0));
myMotionState* msFixed = new myMotionState(trans);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, msFixed, shape, inertia);
btRigidBody* fixedRB = new btRigidBody(rbInfo);
world->addRigidBody(fixedRB);
it works fine, but if I do:
Code: Select all
btTransform trans;
trans.setIdentity();
myMotionState* msFixed = new myMotionState(trans);
btRigidBody::btRigidBodyConstructionInfo rbInfo(mass, msFixed, shape, inertia);
btRigidBody* fixedRB = new btRigidBody(rbInfo);
world->addRigidBody(fixedRB);
trans.setOrigin(btVector3(0, 10, 0));
dynamic_cast<myMotionState*>(fixedRB->getMotionState())->setKinematicTransform(trans);
the dynamic rigid body constrained to fixedRB behaves oddly.
This only happens with kinematic objects, i.e. when I set
Code: Select all
fixedRB->setCollisionFlags(fixedRB->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- when it's set to
btCollisionObject::CF_KINEMATIC_OBJECT then it behaves the same way regardless of when I set the position.
The MotionState class I'm using is just a simple kinematic one, like the one
in the docs, but the same thing happens if I use the btDefaultMotionState and do
fixedRB->getMotionState()->setWorldTransform(trans) to set the position after creation, or if I don't use a motion state at all.
Can anyone tell me why this should be?? (Obviously, I can get round it for now, but it would make my code much nicer if I could set the transforms after creation!)
Thanks
Kate