aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-12 14:59:59 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-12 14:59:59 +0100
commitf9ed8f05ec95e530041d54921cdd17023cdfde6f (patch)
tree8c746a502b1dea0a805ed1b0a95829c8b95c9bff /src/crepe
parent7a931b354f6ef6615049771bce32335bb049723b (diff)
make format
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/system/AISystem.cpp1
-rw-r--r--src/crepe/system/PhysicsSystem.cpp33
2 files changed, 15 insertions, 19 deletions
diff --git a/src/crepe/system/AISystem.cpp b/src/crepe/system/AISystem.cpp
index a20e28c..6578ecb 100644
--- a/src/crepe/system/AISystem.cpp
+++ b/src/crepe/system/AISystem.cpp
@@ -44,7 +44,6 @@ void AISystem::update() {
vec2 acceleration = force / rigidbody.data.mass;
// Finally, update Rigidbody's velocity
rigidbody.data.linear_velocity += acceleration * duration<float>(dt).count();
-
}
}
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<float>(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<Transform>(rigidbody.game_object_id).front().get();
+ Transform & transform
+ = mgr.get_components_by_id<Transform>(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;
}