Add automatic CCD activation to the physics engine

This commit is contained in:
Ryan Huffman 2015-10-23 13:37:49 -07:00
parent 934575a78a
commit 001400908d
2 changed files with 19 additions and 0 deletions

View file

@ -115,6 +115,21 @@ void ObjectMotionState::setMotionType(MotionType motionType) {
_motionType = motionType; _motionType = motionType;
} }
void ObjectMotionState::updateCCDConfiguration() {
if (_body) {
if (_shape) {
btVector3 center;
btScalar radius;
_shape->getBoundingSphere(center, radius);
_body->setCcdMotionThreshold(radius * 2.0f);
_body->setCcdSweptSphereRadius(radius);
} else {
// Disable CCD
_body->setCcdMotionThreshold(0);
}
}
}
void ObjectMotionState::setRigidBody(btRigidBody* body) { void ObjectMotionState::setRigidBody(btRigidBody* body) {
// give the body a (void*) back-pointer to this ObjectMotionState // give the body a (void*) back-pointer to this ObjectMotionState
if (_body != body) { if (_body != body) {
@ -125,6 +140,7 @@ void ObjectMotionState::setRigidBody(btRigidBody* body) {
if (_body) { if (_body) {
_body->setUserPointer(this); _body->setUserPointer(this);
} }
updateCCDConfiguration();
} }
} }
@ -187,6 +203,8 @@ bool ObjectMotionState::handleHardAndEasyChanges(uint32_t flags, PhysicsEngine*
if (_shape != newShape) { if (_shape != newShape) {
_shape = newShape; _shape = newShape;
_body->setCollisionShape(_shape); _body->setCollisionShape(_shape);
updateCCDConfiguration();
} else { } else {
// huh... the shape didn't actually change, so we clear the DIRTY_SHAPE flag // huh... the shape didn't actually change, so we clear the DIRTY_SHAPE flag
flags &= ~Simulation::DIRTY_SHAPE; flags &= ~Simulation::DIRTY_SHAPE;

View file

@ -137,6 +137,7 @@ protected:
virtual bool isReadyToComputeShape() = 0; virtual bool isReadyToComputeShape() = 0;
virtual btCollisionShape* computeNewShape() = 0; virtual btCollisionShape* computeNewShape() = 0;
void setMotionType(MotionType motionType); void setMotionType(MotionType motionType);
void updateCCDConfiguration();
// clearObjectBackPointer() overrrides should call the base method, then actually clear the object back pointer. // clearObjectBackPointer() overrrides should call the base method, then actually clear the object back pointer.
virtual void clearObjectBackPointer() { _type = MOTIONSTATE_TYPE_INVALID; } virtual void clearObjectBackPointer() { _type = MOTIONSTATE_TYPE_INVALID; }