mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
Add automatic CCD activation to the physics engine
This commit is contained in:
parent
934575a78a
commit
001400908d
2 changed files with 19 additions and 0 deletions
|
@ -115,6 +115,21 @@ void ObjectMotionState::setMotionType(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) {
|
||||
// give the body a (void*) back-pointer to this ObjectMotionState
|
||||
if (_body != body) {
|
||||
|
@ -125,6 +140,7 @@ void ObjectMotionState::setRigidBody(btRigidBody* body) {
|
|||
if (_body) {
|
||||
_body->setUserPointer(this);
|
||||
}
|
||||
updateCCDConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -187,6 +203,8 @@ bool ObjectMotionState::handleHardAndEasyChanges(uint32_t flags, PhysicsEngine*
|
|||
if (_shape != newShape) {
|
||||
_shape = newShape;
|
||||
_body->setCollisionShape(_shape);
|
||||
|
||||
updateCCDConfiguration();
|
||||
} else {
|
||||
// huh... the shape didn't actually change, so we clear the DIRTY_SHAPE flag
|
||||
flags &= ~Simulation::DIRTY_SHAPE;
|
||||
|
|
|
@ -137,6 +137,7 @@ protected:
|
|||
virtual bool isReadyToComputeShape() = 0;
|
||||
virtual btCollisionShape* computeNewShape() = 0;
|
||||
void setMotionType(MotionType motionType);
|
||||
void updateCCDConfiguration();
|
||||
|
||||
// clearObjectBackPointer() overrrides should call the base method, then actually clear the object back pointer.
|
||||
virtual void clearObjectBackPointer() { _type = MOTIONSTATE_TYPE_INVALID; }
|
||||
|
|
Loading…
Reference in a new issue