diff --git a/include/omath/collision/epa_algorithm.hpp b/include/omath/collision/epa_algorithm.hpp index 55a26a1..1b51396 100644 --- a/include/omath/collision/epa_algorithm.hpp +++ b/include/omath/collision/epa_algorithm.hpp @@ -258,51 +258,4 @@ namespace omath::collision return V{1, 0, 0}; } }; - - // Optional: the GJK that returns a simplex for EPA (unchanged) - template - class GjkAlgorithmWithSimplex final - { - using Vertex = ColliderType::VertexType; - - public: - struct Hit - { - bool hit{false}; - Simplex simplex; - }; - - [[nodiscard]] - static Vertex find_support_vertex(const ColliderType& a, const ColliderType& b, const Vertex& dir) - { - return a.find_abs_furthest_vertex(dir) - b.find_abs_furthest_vertex(-dir); - } - - [[nodiscard]] - static Hit collide(const ColliderType& a, const ColliderType& b) - { - auto support = find_support_vertex(a, b, {1, 0, 0}); - Simplex simplex; - simplex.push_front(support); - auto direction = -support; - - while (true) - { - support = find_support_vertex(a, b, direction); - if (support.dot(direction) <= 0.f) - return {}; - simplex.push_front(support); - if (simplex.handle(direction)) - { - if (simplex.size() == 4) - return {true, simplex}; - // rare degeneracy: reseed - support = find_support_vertex(a, b, {0, 1, 0}); - simplex.clear(); - simplex.push_front(support); - direction = -support; - } - } - } - }; } // namespace omath::collision diff --git a/tests/general/unit_test_epa.cpp b/tests/general/unit_test_epa.cpp index 3660d09..d79a8d9 100644 --- a/tests/general/unit_test_epa.cpp +++ b/tests/general/unit_test_epa.cpp @@ -1,13 +1,14 @@ -#include -#include "omath/linear_algebra/vector3.hpp" +#include "omath/collision/epa_algorithm.hpp" // Epa + GjkAlgorithmWithSimplex +#include "omath/collision/gjk_algorithm.hpp" #include "omath/collision/simplex.hpp" -#include "omath/collision/epa_algorithm.hpp" // Epa + GjkAlgorithmWithSimplex -#include "omath/engines/source_engine/mesh.hpp" #include "omath/engines/source_engine/collider.hpp" +#include "omath/engines/source_engine/mesh.hpp" +#include "omath/linear_algebra/vector3.hpp" +#include using Mesh = omath::source_engine::Mesh; using Collider = omath::source_engine::MeshCollider; -using GJK = omath::collision::GjkAlgorithmWithSimplex; +using GJK = omath::collision::GjkAlgorithm; using EPA = omath::collision::Epa; TEST(UnitTestEpa, TestCollisionTrue) @@ -29,7 +30,7 @@ TEST(UnitTestEpa, TestCollisionTrue) Collider A(a), B(b); // GJK - auto gjk = GJK::collide(A, B); + auto gjk = GJK::is_collide_with_simplex_info(A, B); ASSERT_TRUE(gjk.hit) << "GJK should report collision"; // EPA @@ -57,8 +58,8 @@ TEST(UnitTestEpa, TestCollisionTrue) Collider B_plus(b_plus), B_minus(b_minus); - const bool sep_plus = !GJK::collide(A, B_plus).hit; - const bool sep_minus = !GJK::collide(A, B_minus).hit; + const bool sep_plus = !GJK::is_collide_with_simplex_info(A, B_plus).hit; + const bool sep_minus = !GJK::is_collide_with_simplex_info(A, B_minus).hit; // Exactly one direction should separate EXPECT_NE(sep_plus, sep_minus) << "Exactly one of ±penetration must separate"; @@ -67,9 +68,9 @@ TEST(UnitTestEpa, TestCollisionTrue) const auto resolve = sep_plus ? ( pen * margin) : (-pen * margin); Mesh b_resolved = b; b_resolved.set_origin(b_resolved.get_origin() + resolve); - EXPECT_FALSE(GJK::collide(A, Collider(b_resolved)).hit) << "Resolved position should be non-colliding"; + EXPECT_FALSE(GJK::is_collide(A, Collider(b_resolved))) << "Resolved position should be non-colliding"; // Moving the other way should still collide Mesh b_wrong = b; b_wrong.set_origin(b_wrong.get_origin() - resolve); - EXPECT_TRUE(GJK::collide(A, Collider(b_wrong)).hit); + EXPECT_TRUE(GJK::is_collide(A, Collider(b_wrong))); } \ No newline at end of file