From 4f0109b17e4a6adbd280a973d00bbc0658f8fb8a Mon Sep 17 00:00:00 2001 From: Daniel Evans Date: Fri, 12 Jan 2018 04:31:49 +0000 Subject: [PATCH] Tidy up code in object physics handling --- rwengine/src/objects/InstanceObject.cpp | 6 +----- rwengine/src/objects/VehicleObject.cpp | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/rwengine/src/objects/InstanceObject.cpp b/rwengine/src/objects/InstanceObject.cpp index 88a753c7..8a5f640a 100644 --- a/rwengine/src/objects/InstanceObject.cpp +++ b/rwengine/src/objects/InstanceObject.cpp @@ -50,8 +50,6 @@ void InstanceObject::tick(float dt) { if (dynamics && body) { if (_enablePhysics) { if (body->getBulletBody()->isStaticObject()) { - // Apparently bodies must be removed and re-added if their mass - // changes. body->changeMass(dynamics->mass); } } @@ -157,7 +155,6 @@ void InstanceObject::changeModel(BaseModelInfo* incoming) { if (collision) { body = std::make_unique(); body->createPhysicsBody(this, collision, dynamics.get()); - body->getBulletBody()->setActivationState(ISLAND_SLEEPING); } } } @@ -190,8 +187,7 @@ bool InstanceObject::takeDamage(const GameObject::DamageInfo& dmg) { smash = dynamics->collDamageFlags == 80; if (dmg.impulse >= dynamics->uprootForce && - (body->getBulletBody()->getCollisionFlags() & - btRigidBody::CF_STATIC_OBJECT) != 0) { + body->getBulletBody()->isStaticObject()) { _enablePhysics = true; } } diff --git a/rwengine/src/objects/VehicleObject.cpp b/rwengine/src/objects/VehicleObject.cpp index 32fbbd98..fecdedc1 100644 --- a/rwengine/src/objects/VehicleObject.cpp +++ b/rwengine/src/objects/VehicleObject.cpp @@ -104,6 +104,7 @@ VehicleObject::VehicleObject(GameWorld* engine, const glm::vec3& pos, , physVehicle(nullptr) { collision->createPhysicsBody(this, modelinfo->getCollision(), nullptr, &info->handling); + collision->getBulletBody()->forceActivationState(DISABLE_DEACTIVATION); physRaycaster = new VehicleRaycaster(this, engine->dynamicsWorld.get()); btRaycastVehicle::btVehicleTuning tuning; @@ -115,7 +116,6 @@ VehicleObject::VehicleObject(GameWorld* engine, const glm::vec3& pos, physVehicle = new btRaycastVehicle(tuning, collision->getBulletBody(), physRaycaster); physVehicle->setCoordinateSystem(0, 2, 1); - // physBody->setActivationState(DISABLE_DEACTIVATION); engine->dynamicsWorld->addAction(physVehicle); float kC = 0.5f; @@ -242,10 +242,6 @@ void VehicleObject::tickPhysics(float dt) { // todo: a real engine function float velFac = info->handling.maxVelocity; float engineForce = info->handling.acceleration * throttle * velFac; - if (std::fabs(engineForce) >= 0.001f) { - collision->getBulletBody()->activate(true); - } - float brakeF = getBraking(); if (handbrake) {