mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 11:45:36 +02:00
protect physics against bad entity properties
This commit is contained in:
parent
937bd0c1be
commit
4c9ec7ca43
2 changed files with 30 additions and 23 deletions
|
@ -152,6 +152,11 @@ PhysicsMotionType EntityMotionState::computePhysicsMotionType() const {
|
|||
}
|
||||
assert(entityTreeIsLocked());
|
||||
|
||||
if (_entity->getShapeType() == SHAPE_TYPE_STATIC_MESH
|
||||
|| (_body && _body->getCollisionShape()->getShapeType() == TRIANGLE_MESH_SHAPE_PROXYTYPE)) {
|
||||
return MOTION_TYPE_STATIC;
|
||||
}
|
||||
|
||||
if (_entity->getDynamic()) {
|
||||
if (!_entity->getParentID().isNull()) {
|
||||
// if something would have been dynamic but is a child of something else, force it to be kinematic, instead.
|
||||
|
|
|
@ -203,35 +203,37 @@ void ObjectMotionState::handleEasyChanges(uint32_t& flags) {
|
|||
}
|
||||
}
|
||||
|
||||
if (flags & Simulation::DIRTY_LINEAR_VELOCITY) {
|
||||
btVector3 newLinearVelocity = glmToBullet(getObjectLinearVelocity());
|
||||
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
||||
float delta = (newLinearVelocity - _body->getLinearVelocity()).length();
|
||||
if (delta > ACTIVATION_LINEAR_VELOCITY_DELTA) {
|
||||
flags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
|
||||
if (_body->getCollisionShape()->getShapeType() != TRIANGLE_MESH_SHAPE_PROXYTYPE) {
|
||||
if (flags & Simulation::DIRTY_LINEAR_VELOCITY) {
|
||||
btVector3 newLinearVelocity = glmToBullet(getObjectLinearVelocity());
|
||||
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
||||
float delta = (newLinearVelocity - _body->getLinearVelocity()).length();
|
||||
if (delta > ACTIVATION_LINEAR_VELOCITY_DELTA) {
|
||||
flags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
|
||||
}
|
||||
}
|
||||
}
|
||||
_body->setLinearVelocity(newLinearVelocity);
|
||||
_body->setLinearVelocity(newLinearVelocity);
|
||||
|
||||
btVector3 newGravity = glmToBullet(getObjectGravity());
|
||||
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
||||
float delta = (newGravity - _body->getGravity()).length();
|
||||
if (delta > ACTIVATION_GRAVITY_DELTA ||
|
||||
(delta > 0.0f && _body->getGravity().length2() == 0.0f)) {
|
||||
flags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
|
||||
btVector3 newGravity = glmToBullet(getObjectGravity());
|
||||
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
||||
float delta = (newGravity - _body->getGravity()).length();
|
||||
if (delta > ACTIVATION_GRAVITY_DELTA ||
|
||||
(delta > 0.0f && _body->getGravity().length2() == 0.0f)) {
|
||||
flags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
|
||||
}
|
||||
}
|
||||
_body->setGravity(newGravity);
|
||||
}
|
||||
_body->setGravity(newGravity);
|
||||
}
|
||||
if (flags & Simulation::DIRTY_ANGULAR_VELOCITY) {
|
||||
btVector3 newAngularVelocity = glmToBullet(getObjectAngularVelocity());
|
||||
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
||||
float delta = (newAngularVelocity - _body->getAngularVelocity()).length();
|
||||
if (delta > ACTIVATION_ANGULAR_VELOCITY_DELTA) {
|
||||
flags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
|
||||
if (flags & Simulation::DIRTY_ANGULAR_VELOCITY) {
|
||||
btVector3 newAngularVelocity = glmToBullet(getObjectAngularVelocity());
|
||||
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
||||
float delta = (newAngularVelocity - _body->getAngularVelocity()).length();
|
||||
if (delta > ACTIVATION_ANGULAR_VELOCITY_DELTA) {
|
||||
flags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
|
||||
}
|
||||
}
|
||||
_body->setAngularVelocity(newAngularVelocity);
|
||||
}
|
||||
_body->setAngularVelocity(newAngularVelocity);
|
||||
}
|
||||
|
||||
if (flags & Simulation::DIRTY_MATERIAL) {
|
||||
|
|
Loading…
Reference in a new issue