mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 10:07:58 +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());
|
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->getDynamic()) {
|
||||||
if (!_entity->getParentID().isNull()) {
|
if (!_entity->getParentID().isNull()) {
|
||||||
// if something would have been dynamic but is a child of something else, force it to be kinematic, instead.
|
// 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) {
|
if (_body->getCollisionShape()->getShapeType() != TRIANGLE_MESH_SHAPE_PROXYTYPE) {
|
||||||
btVector3 newLinearVelocity = glmToBullet(getObjectLinearVelocity());
|
if (flags & Simulation::DIRTY_LINEAR_VELOCITY) {
|
||||||
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
btVector3 newLinearVelocity = glmToBullet(getObjectLinearVelocity());
|
||||||
float delta = (newLinearVelocity - _body->getLinearVelocity()).length();
|
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
||||||
if (delta > ACTIVATION_LINEAR_VELOCITY_DELTA) {
|
float delta = (newLinearVelocity - _body->getLinearVelocity()).length();
|
||||||
flags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
|
if (delta > ACTIVATION_LINEAR_VELOCITY_DELTA) {
|
||||||
|
flags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
_body->setLinearVelocity(newLinearVelocity);
|
||||||
_body->setLinearVelocity(newLinearVelocity);
|
|
||||||
|
|
||||||
btVector3 newGravity = glmToBullet(getObjectGravity());
|
btVector3 newGravity = glmToBullet(getObjectGravity());
|
||||||
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
||||||
float delta = (newGravity - _body->getGravity()).length();
|
float delta = (newGravity - _body->getGravity()).length();
|
||||||
if (delta > ACTIVATION_GRAVITY_DELTA ||
|
if (delta > ACTIVATION_GRAVITY_DELTA ||
|
||||||
(delta > 0.0f && _body->getGravity().length2() == 0.0f)) {
|
(delta > 0.0f && _body->getGravity().length2() == 0.0f)) {
|
||||||
flags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
|
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_ANGULAR_VELOCITY) {
|
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
||||||
btVector3 newAngularVelocity = glmToBullet(getObjectAngularVelocity());
|
float delta = (newAngularVelocity - _body->getAngularVelocity()).length();
|
||||||
if (!(flags & Simulation::DIRTY_PHYSICS_ACTIVATION)) {
|
if (delta > ACTIVATION_ANGULAR_VELOCITY_DELTA) {
|
||||||
float delta = (newAngularVelocity - _body->getAngularVelocity()).length();
|
flags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
|
||||||
if (delta > ACTIVATION_ANGULAR_VELOCITY_DELTA) {
|
}
|
||||||
flags |= Simulation::DIRTY_PHYSICS_ACTIVATION;
|
|
||||||
}
|
}
|
||||||
|
_body->setAngularVelocity(newAngularVelocity);
|
||||||
}
|
}
|
||||||
_body->setAngularVelocity(newAngularVelocity);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags & Simulation::DIRTY_MATERIAL) {
|
if (flags & Simulation::DIRTY_MATERIAL) {
|
||||||
|
|
Loading…
Reference in a new issue