aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system/CollisionSystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/system/CollisionSystem.cpp')
-rw-r--r--src/crepe/system/CollisionSystem.cpp28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/crepe/system/CollisionSystem.cpp b/src/crepe/system/CollisionSystem.cpp
index f0f1fa8..0b9ea61 100644
--- a/src/crepe/system/CollisionSystem.cpp
+++ b/src/crepe/system/CollisionSystem.cpp
@@ -168,7 +168,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern
// Get resolution vector from box-box collision detection
resolution = this->get_box_box_detection(BOX1, BOX2);
// If no collision (NaN values), return false
- if (std::isnan(resolution.x) && std::isnan(resolution.y)) return false;
+ if(resolution.is_nan()) return false;
break;
}
case CollisionInternalType::BOX_CIRCLE: {
@@ -184,7 +184,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern
// Get resolution vector from box-circle collision detection
resolution = this->get_box_circle_detection(BOX1, CIRCLE2);
// If no collision (NaN values), return false
- if (std::isnan(resolution.x) && std::isnan(resolution.y)) return false;
+ if(resolution.is_nan()) return false;
// Invert the resolution vector for proper collision response
resolution = -resolution;
break;
@@ -202,7 +202,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern
// Get resolution vector from circle-circle collision detection
resolution = this->get_circle_circle_detection(CIRCLE1, CIRCLE2);
// If no collision (NaN values), return false
- if (std::isnan(resolution.x) && std::isnan(resolution.y)) return false;
+ if(resolution.is_nan()) return false;
break;
}
case CollisionInternalType::CIRCLE_BOX: {
@@ -218,7 +218,7 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern
// Get resolution vector from box-circle collision detection (order swapped)
resolution = this->get_box_circle_detection(BOX2, CIRCLE1);
// If no collision (NaN values), return false
- if (std::isnan(resolution.x) && std::isnan(resolution.y)) return false;
+ if(resolution.is_nan()) return false;
break;
}
case CollisionInternalType::NONE:
@@ -239,9 +239,8 @@ bool CollisionSystem::detect_collision(CollisionInternal & self, CollisionIntern
return true;
}
-vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1,
- const BoxColliderInternal & box2) const {
- vec2 resolution{std::nanf(""), std::nanf("")};
+vec2 CollisionSystem::get_box_box_detection(const BoxColliderInternal & box1, const BoxColliderInternal & box2) const {
+ vec2 resolution{NAN, NAN};
// Get current positions of colliders
vec2 pos1 = AbsolutePosition::get_position(box1.transform, box1.collider.offset);
vec2 pos2 = AbsolutePosition::get_position(box2.transform, box2.collider.offset);
@@ -320,14 +319,11 @@ vec2 CollisionSystem::get_box_circle_detection(const BoxColliderInternal & box,
= std::sqrt(closest_delta.x * closest_delta.x + closest_delta.y * closest_delta.y);
vec2 collision_normal = closest_delta / distance;
- // Compute penetration depth
- float penetration_depth = scaled_circle_radius - distance;
-
- // Compute the resolution vector
- return vec2{collision_normal * penetration_depth};
- }
- // No collision
- return vec2{std::nanf(""), std::nanf("")};
+ // Compute the resolution vector
+ return vec2{collision_normal * penetration_depth};
+ }
+ // No collision
+ return vec2{NAN, NAN};;
}
vec2 CollisionSystem::get_circle_circle_detection(
@@ -371,7 +367,7 @@ vec2 CollisionSystem::get_circle_circle_detection(
return resolution;
}
// No collision
- return vec2{std::nanf(""), std::nanf("")};
+ return vec2{NAN, NAN};;
}
CollisionSystem::Direction