From c515dc89a915bb69aedd60c0c626a2552ade992c Mon Sep 17 00:00:00 2001 From: Orange Date: Thu, 13 Nov 2025 13:33:18 +0300 Subject: [PATCH] Adds GjkHitInfo and refactors collision detection Introduces `GjkHitInfo` to encapsulate collision results, including the simplex. Refactors `is_collide` to return the `GjkHitInfo` struct, providing more detailed collision data. This prepares the codebase for integrating the EPA algorithm (as per the feature branch) which requires simplex information. --- include/omath/collision/gjk_algorithm.hpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/include/omath/collision/gjk_algorithm.hpp b/include/omath/collision/gjk_algorithm.hpp index c115f23..81a648c 100644 --- a/include/omath/collision/gjk_algorithm.hpp +++ b/include/omath/collision/gjk_algorithm.hpp @@ -7,6 +7,13 @@ namespace omath::collision { + template + struct GjkHitInfo final + { + bool hit{false}; + Simplex simplex; // valid only if hit == true and size==4 + }; + template class GjkAlgorithm final { @@ -23,7 +30,13 @@ namespace omath::collision [[nodiscard]] static bool is_collide(const ColliderType& collider_a, const ColliderType& collider_b) { - // Get initial support point in any direction + return is_collide_with_simplex_info(collider_a, collider_b).hit; + } + + [[nodiscard]] + static GjkHitInfo is_collide_with_simplex_info(const ColliderType& collider_a, + const ColliderType& collider_b) + { auto support = find_support_vertex(collider_a, collider_b, {1, 0, 0}); Simplex simplex; @@ -36,12 +49,12 @@ namespace omath::collision support = find_support_vertex(collider_a, collider_b, direction); if (support.dot(direction) <= 0.f) - return false; + return {false, simplex}; simplex.push_front(support); if (simplex.handle(direction)) - return true; + return {true, simplex}; } } };