From 74dc2234f7b61a1489e3d89bc0eadc8c6b0389a4 Mon Sep 17 00:00:00 2001 From: orange Date: Thu, 26 Feb 2026 16:17:41 +0300 Subject: [PATCH] fixed collider when rotated --- include/omath/collision/mesh_collider.hpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/include/omath/collision/mesh_collider.hpp b/include/omath/collision/mesh_collider.hpp index a9a8870..ae28723 100644 --- a/include/omath/collision/mesh_collider.hpp +++ b/include/omath/collision/mesh_collider.hpp @@ -46,9 +46,16 @@ namespace omath::collision [[nodiscard]] const VertexType& find_furthest_vertex(const VectorType& direction) const { + // Compare vertices in world space so rotation and non-uniform scale are + // accounted for correctly. Without this the comparator uses local-space + // positions against a world-space direction, which yields the wrong support + // vertex whenever a non-identity transform is applied to the mesh. return *std::ranges::max_element( - m_mesh.m_vertex_buffer, [&direction](const auto& first, const auto& second) - { return first.position.dot(direction) < second.position.dot(direction); }); + m_mesh.m_vertex_buffer, [&](const auto& first, const auto& second) + { + return m_mesh.vertex_position_to_world_space(first.position).dot(direction) + < m_mesh.vertex_position_to_world_space(second.position).dot(direction); + }); } MeshType m_mesh; };