66#include < cstdint>
77#include < limits>
88#include < memory>
9+ #include < memory_resource>
910#include < queue>
1011#include < utility>
1112#include < vector>
12- #include < memory_resource>
1313
1414namespace omath ::collision
1515{
@@ -23,16 +23,16 @@ namespace omath::collision
2323 { a / s } -> std::same_as<V>;
2424 };
2525
26- template <class ColliderType >
26+ template <class ColliderInterfaceType >
2727 class Epa final
2828 {
2929 public:
30- using VectorType = ColliderType ::VectorType;
30+ using VectorType = ColliderInterfaceType ::VectorType;
3131 static_assert (EpaVector<VectorType>, " VertexType must satisfy EpaVector concept" );
3232
3333 struct Result final
3434 {
35- VectorType normal{}; // outward normal ( from B to A)
35+ VectorType normal{}; // from A to B
3636 VectorType penetration_vector;
3737 float depth{0 .0f };
3838 int iterations{0 };
@@ -48,7 +48,7 @@ namespace omath::collision
4848
4949 // Precondition: simplex.size()==4 and contains the origin.
5050 [[nodiscard]]
51- static std::optional<Result> solve (const ColliderType & a, const ColliderType & b,
51+ static std::optional<Result> solve (const ColliderInterfaceType & a, const ColliderInterfaceType & b,
5252 const Simplex<VectorType>& simplex, const Params params = {},
5353 std::shared_ptr<std::pmr::memory_resource> mem_resource = {
5454 std::shared_ptr<void >{}, std::pmr::get_default_resource ()})
@@ -86,25 +86,22 @@ namespace omath::collision
8686 break ;
8787
8888 const int fidx = heap.top ().idx ;
89- const Face f = faces[fidx];
89+ const Face face = faces[fidx];
9090
9191 // Get the furthest point in face normal direction
92- const VectorType p = support_point (a, b, f .n );
93- const float p_dist = f .n .dot (p);
92+ const VectorType p = support_point (a, b, face .n );
93+ const float p_dist = face .n .dot (p);
9494
9595 // Converged if we can’t push the face closer than tolerance
96- if (p_dist - f .d <= params.tolerance )
96+ if (p_dist - face .d <= params.tolerance )
9797 {
98- out.normal = f .n ;
99- out.depth = f .d ; // along unit normal
98+ out.normal = face .n ;
99+ out.depth = face .d ; // along unit normal
100100 out.iterations = it + 1 ;
101101 out.num_vertices = static_cast <int >(vertexes.size ());
102102 out.num_faces = static_cast <int >(faces.size ());
103103
104- const auto centers = b.get_origin () - a.get_origin ();
105- const auto sign = out.normal .dot (centers) >= 0 ? 1 : -1 ;
106-
107- out.penetration_vector = out.normal * out.depth * sign;
104+ out.penetration_vector = out.normal * out.depth ;
108105 return out;
109106 }
110107
@@ -163,10 +160,7 @@ namespace omath::collision
163160 out.num_vertices = static_cast <int >(vertexes.size ());
164161 out.num_faces = static_cast <int >(faces.size ());
165162
166- const auto centers = b.get_origin () - a.get_origin ();
167- const auto sign = out.normal .dot (centers) >= 0 ? 1 : -1 ;
168-
169- out.penetration_vector = out.normal * out.depth * sign;
163+ out.penetration_vector = out.normal * out.depth ;
170164
171165 return out;
172166 }
@@ -251,9 +245,10 @@ namespace omath::collision
251245 }
252246
253247 [[nodiscard]]
254- static VectorType support_point (const ColliderType& a, const ColliderType& b, const VectorType& dir)
248+ static VectorType support_point (const ColliderInterfaceType& a, const ColliderInterfaceType& b,
249+ const VectorType& dir)
255250 {
256- return a.find_abs_furthest_vertex (dir). position - b.find_abs_furthest_vertex (-dir). position ;
251+ return a.find_abs_furthest_vertex_position (dir) - b.find_abs_furthest_vertex_position (-dir);
257252 }
258253
259254 template <class V >
0 commit comments