fix bug where kinematic objs pop on first step

This commit is contained in:
Andrew Meadows 2016-04-18 13:54:26 -07:00
parent c8f0b0501a
commit 8cbec06616
3 changed files with 10 additions and 0 deletions

View file

@ -45,6 +45,7 @@ void ObjectMotionState::setWorldSimulationStep(uint32_t step) {
worldSimulationStep = step;
}
// static
uint32_t ObjectMotionState::getWorldSimulationStep() {
return worldSimulationStep;
}
@ -298,6 +299,12 @@ void ObjectMotionState::updateBodyVelocities() {
_body->setActivationState(ACTIVE_TAG);
}
void ObjectMotionState::updateLastKinematicStep() {
// NOTE: we init to worldSimulationStep - 1 so that: when any object transitions to kinematic
// it will compute a non-zero dt on its first step.
_lastKinematicStep = ObjectMotionState::getWorldSimulationStep() - 1;
}
void ObjectMotionState::updateBodyMassProperties() {
float mass = getMass();
btVector3 inertia(0.0f, 0.0f, 0.0f);

View file

@ -86,6 +86,8 @@ public:
void updateBodyMaterialProperties();
void updateBodyVelocities();
void updateLastKinematicStep();
virtual void updateBodyMassProperties();
MotionStateType getType() const { return _type; }

View file

@ -86,6 +86,7 @@ void PhysicsEngine::addObjectToDynamicsWorld(ObjectMotionState* motionState) {
body->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
body->updateInertiaTensor();
motionState->updateBodyVelocities();
motionState->updateLastKinematicStep();
const float KINEMATIC_LINEAR_VELOCITY_THRESHOLD = 0.01f; // 1 cm/sec
const float KINEMATIC_ANGULAR_VELOCITY_THRESHOLD = 0.01f; // ~1 deg/sec
body->setSleepingThresholds(KINEMATIC_LINEAR_VELOCITY_THRESHOLD, KINEMATIC_ANGULAR_VELOCITY_THRESHOLD);