mirror of
https://github.com/rwengine/openrw.git
synced 2024-09-18 16:32:32 +02:00
Tidy up code in object physics handling
This commit is contained in:
parent
1c57fb5d98
commit
4f0109b17e
@ -50,8 +50,6 @@ void InstanceObject::tick(float dt) {
|
|||||||
if (dynamics && body) {
|
if (dynamics && body) {
|
||||||
if (_enablePhysics) {
|
if (_enablePhysics) {
|
||||||
if (body->getBulletBody()->isStaticObject()) {
|
if (body->getBulletBody()->isStaticObject()) {
|
||||||
// Apparently bodies must be removed and re-added if their mass
|
|
||||||
// changes.
|
|
||||||
body->changeMass(dynamics->mass);
|
body->changeMass(dynamics->mass);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,7 +155,6 @@ void InstanceObject::changeModel(BaseModelInfo* incoming) {
|
|||||||
if (collision) {
|
if (collision) {
|
||||||
body = std::make_unique<CollisionInstance>();
|
body = std::make_unique<CollisionInstance>();
|
||||||
body->createPhysicsBody(this, collision, dynamics.get());
|
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;
|
smash = dynamics->collDamageFlags == 80;
|
||||||
|
|
||||||
if (dmg.impulse >= dynamics->uprootForce &&
|
if (dmg.impulse >= dynamics->uprootForce &&
|
||||||
(body->getBulletBody()->getCollisionFlags() &
|
body->getBulletBody()->isStaticObject()) {
|
||||||
btRigidBody::CF_STATIC_OBJECT) != 0) {
|
|
||||||
_enablePhysics = true;
|
_enablePhysics = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,7 @@ VehicleObject::VehicleObject(GameWorld* engine, const glm::vec3& pos,
|
|||||||
, physVehicle(nullptr) {
|
, physVehicle(nullptr) {
|
||||||
collision->createPhysicsBody(this, modelinfo->getCollision(), nullptr,
|
collision->createPhysicsBody(this, modelinfo->getCollision(), nullptr,
|
||||||
&info->handling);
|
&info->handling);
|
||||||
|
collision->getBulletBody()->forceActivationState(DISABLE_DEACTIVATION);
|
||||||
physRaycaster = new VehicleRaycaster(this, engine->dynamicsWorld.get());
|
physRaycaster = new VehicleRaycaster(this, engine->dynamicsWorld.get());
|
||||||
btRaycastVehicle::btVehicleTuning tuning;
|
btRaycastVehicle::btVehicleTuning tuning;
|
||||||
|
|
||||||
@ -115,7 +116,6 @@ VehicleObject::VehicleObject(GameWorld* engine, const glm::vec3& pos,
|
|||||||
physVehicle =
|
physVehicle =
|
||||||
new btRaycastVehicle(tuning, collision->getBulletBody(), physRaycaster);
|
new btRaycastVehicle(tuning, collision->getBulletBody(), physRaycaster);
|
||||||
physVehicle->setCoordinateSystem(0, 2, 1);
|
physVehicle->setCoordinateSystem(0, 2, 1);
|
||||||
// physBody->setActivationState(DISABLE_DEACTIVATION);
|
|
||||||
engine->dynamicsWorld->addAction(physVehicle);
|
engine->dynamicsWorld->addAction(physVehicle);
|
||||||
|
|
||||||
float kC = 0.5f;
|
float kC = 0.5f;
|
||||||
@ -242,10 +242,6 @@ void VehicleObject::tickPhysics(float dt) {
|
|||||||
// todo: a real engine function
|
// todo: a real engine function
|
||||||
float velFac = info->handling.maxVelocity;
|
float velFac = info->handling.maxVelocity;
|
||||||
float engineForce = info->handling.acceleration * throttle * velFac;
|
float engineForce = info->handling.acceleration * throttle * velFac;
|
||||||
if (std::fabs(engineForce) >= 0.001f) {
|
|
||||||
collision->getBulletBody()->activate(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
float brakeF = getBraking();
|
float brakeF = getBraking();
|
||||||
|
|
||||||
if (handbrake) {
|
if (handbrake) {
|
||||||
|
Loading…
Reference in New Issue
Block a user