aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-12-06 12:39:03 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-12-06 12:39:03 +0100
commitf4a182547e02bafaf996b7f504344c2e28d19254 (patch)
treec2a7daae5d16b55372061ee63379fc4f3d27e4da /src
parentcc320c87372dfbcce5f1cee66397466d90a9ba0a (diff)
fixed float round issue
Diffstat (limited to 'src')
-rw-r--r--src/crepe/system/CollisionSystem.cpp10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp
index bde217f..9da08cb 100644
--- a/src/crepe/system/CollisionSystem.cpp
+++ b/src/crepe/system/CollisionSystem.cpp
@@ -509,10 +509,10 @@ bool CollisionSystem::get_box_circle_collision(const BoxCollider & box1,
// Calculate the distance squared between the circle's center and the closest point on the box
float distance_x = final_position2.x - closest_x;
float distance_y = final_position2.y - closest_y;
- float distance_squared = distance_x * distance_x + distance_y * distance_y;
+ float distance_squared = std::round(distance_x * distance_x + distance_y * distance_y);
// Compare distance squared with the square of the circle's radius
- return distance_squared <= circle2.radius * circle2.radius;
+ return distance_squared < std::round(circle2.radius * circle2.radius);
}
bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1,
@@ -527,13 +527,13 @@ bool CollisionSystem::get_circle_circle_collision(const CircleCollider & circle1
float distance_x = final_position1.x - final_position2.x;
float distance_y = final_position1.y - final_position2.y;
- float distance_squared = distance_x * distance_x + distance_y * distance_y;
+ float distance_squared = std::round(distance_x * distance_x + distance_y * distance_y);
// Calculate the sum of the radii
float radius_sum = circle1.radius + circle2.radius;
// Check if the distance between the centers is less than or equal to the sum of the radii
- return distance_squared <= radius_sum * radius_sum;
+ return distance_squared < std::round(radius_sum * radius_sum);
}
vec2 CollisionSystem::get_current_position(const vec2 & collider_offset,
@@ -554,3 +554,5 @@ vec2 CollisionSystem::get_current_position(const vec2 & collider_offset,
// Final positions considering scaling and rotation
return (transform.position + vec2(rotated_total_offset_x1, rotated_total_offset_y1));
}
+
+