From f9ed8f05ec95e530041d54921cdd17023cdfde6f Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Thu, 12 Dec 2024 14:59:59 +0100 Subject: make format --- src/crepe/system/PhysicsSystem.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'src/crepe/system/PhysicsSystem.cpp') diff --git a/src/crepe/system/PhysicsSystem.cpp b/src/crepe/system/PhysicsSystem.cpp index 78370d1..a1d35bb 100644 --- a/src/crepe/system/PhysicsSystem.cpp +++ b/src/crepe/system/PhysicsSystem.cpp @@ -22,11 +22,12 @@ void PhysicsSystem::update() { duration_t delta_time = loop_timer.get_scaled_fixed_delta_time(); float dt = duration(delta_time).count(); - + float gravity = Config::get_instance().physics.gravity; for (Rigidbody & rigidbody : rigidbodies) { if (!rigidbody.active) continue; - Transform & transform = mgr.get_components_by_id(rigidbody.game_object_id).front().get(); + Transform & transform + = mgr.get_components_by_id(rigidbody.game_object_id).front().get(); switch (rigidbody.data.body_type) { case Rigidbody::BodyType::DYNAMIC: @@ -43,43 +44,39 @@ void PhysicsSystem::update() { if (rigidbody.data.gravity_scale > 0) { rigidbody.data.linear_velocity.y - += (rigidbody.data.mass * rigidbody.data.gravity_scale - * gravity * dt); + += (rigidbody.data.mass * rigidbody.data.gravity_scale * gravity + * dt); } // Add coefficient rotation if (rigidbody.data.angular_velocity_coefficient > 0) { rigidbody.data.angular_velocity *= std::pow(rigidbody.data.angular_velocity_coefficient, dt); - } // Add coefficient movement horizontal - if (rigidbody.data.linear_velocity_coefficient.x > 0) - { + if (rigidbody.data.linear_velocity_coefficient.x > 0) { rigidbody.data.linear_velocity.x - *= std::pow(rigidbody.data.linear_velocity_coefficient.x, dt); + *= std::pow(rigidbody.data.linear_velocity_coefficient.x, dt); } // Add coefficient movement horizontal - if (rigidbody.data.linear_velocity_coefficient.y > 0) - { + if (rigidbody.data.linear_velocity_coefficient.y > 0) { rigidbody.data.linear_velocity.y - *= std::pow(rigidbody.data.linear_velocity_coefficient.y, dt); + *= std::pow(rigidbody.data.linear_velocity_coefficient.y, dt); } // Max velocity check if (rigidbody.data.angular_velocity > rigidbody.data.max_angular_velocity) { - rigidbody.data.angular_velocity - = rigidbody.data.max_angular_velocity; + rigidbody.data.angular_velocity = rigidbody.data.max_angular_velocity; } else if (rigidbody.data.angular_velocity - < -rigidbody.data.max_angular_velocity) { - rigidbody.data.angular_velocity - = -rigidbody.data.max_angular_velocity; + < -rigidbody.data.max_angular_velocity) { + rigidbody.data.angular_velocity = -rigidbody.data.max_angular_velocity; } - + // Set max velocity to maximum length - if(rigidbody.data.linear_velocity.length() > rigidbody.data.max_linear_velocity) { + if (rigidbody.data.linear_velocity.length() + > rigidbody.data.max_linear_velocity) { rigidbody.data.linear_velocity.normalize(); rigidbody.data.linear_velocity *= rigidbody.data.max_linear_velocity; } -- cgit v1.2.3