Refactors GJK algorithm vertex type

Simplifies the GJK algorithm by using a type alias for the vertex type, improving code readability and reducing redundancy. Removes unnecessary includes.
This commit is contained in:
2025-11-11 23:37:56 +03:00
parent 28ef194586
commit 66919af46a

View File

@@ -3,8 +3,6 @@
// //
#pragma once #pragma once
#include "mesh_collider.hpp"
#include "omath/linear_algebra/vector3.hpp"
#include "simplex.hpp" #include "simplex.hpp"
namespace omath::collision namespace omath::collision
@@ -12,11 +10,12 @@ namespace omath::collision
template<class ColliderType> template<class ColliderType>
class GjkAlgorithm final class GjkAlgorithm final
{ {
using VertexType = typename ColliderType::VertexType;
public: public:
[[nodiscard]] [[nodiscard]]
static ColliderType::VertexType find_support_vertex(const ColliderType& collider_a, static VertexType find_support_vertex(const ColliderType& collider_a, const ColliderType& collider_b,
const ColliderType& collider_b, const VertexType& direction)
const ColliderType::VertexType& direction)
{ {
return collider_a.find_abs_furthest_vertex(direction) - collider_b.find_abs_furthest_vertex(-direction); return collider_a.find_abs_furthest_vertex(direction) - collider_b.find_abs_furthest_vertex(-direction);
} }
@@ -27,7 +26,7 @@ namespace omath::collision
// Get initial support point in any direction // Get initial support point in any direction
auto support = find_support_vertex(collider_a, collider_b, {1, 0, 0}); auto support = find_support_vertex(collider_a, collider_b, {1, 0, 0});
Simplex<typename ColliderType::VertexType> simplex; Simplex<VertexType> simplex;
simplex.push_front(support); simplex.push_front(support);
auto direction = -support; auto direction = -support;