Refactors collision detection with GJK and EPA

This commit refactors the collision detection pipeline to utilize a more standard GJK algorithm and simplifies the EPA implementation.

Removes the custom `GjkAlgorithmWithSimplex` in favor of the standalone `GjkAlgorithm`. This streamlines the collision detection process and enhances code clarity.

Updates unit tests to align with the new GJK implementation, ensuring continued functionality and correctness.
This commit is contained in:
2025-11-13 16:39:26 +03:00
parent 873bdd2036
commit fa91f21e39
2 changed files with 11 additions and 57 deletions

View File

@@ -258,51 +258,4 @@ namespace omath::collision
return V{1, 0, 0};
}
};
// Optional: the GJK that returns a simplex for EPA (unchanged)
template<class ColliderType>
class GjkAlgorithmWithSimplex final
{
using Vertex = ColliderType::VertexType;
public:
struct Hit
{
bool hit{false};
Simplex<Vertex> 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<Vertex> 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