From acc24f84385790e14eab3b0549f77ed3cf44a730 Mon Sep 17 00:00:00 2001 From: Orange Date: Mon, 26 Jan 2026 18:54:36 +0300 Subject: [PATCH] WIP on feature/rotation_improved --- include/omath/collision/line_tracer.hpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/include/omath/collision/line_tracer.hpp b/include/omath/collision/line_tracer.hpp index fb40f24..29555a1 100644 --- a/include/omath/collision/line_tracer.hpp +++ b/include/omath/collision/line_tracer.hpp @@ -33,5 +33,25 @@ namespace omath::collision // https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm [[nodiscard]] static Vector3 get_ray_hit_point(const Ray& ray, const Triangle>& triangle) noexcept; + + template + [[nodiscard]] + static Vector3 get_ray_hit_point(const Ray& ray, const MeshType& mesh) noexcept + { + Vector3 mesh_hit = ray.end; + + auto begin = mesh.m_element_buffer_object.cbegin(); + auto end = mesh.m_element_buffer_object.cend(); + for (auto current = begin; current < end; current = std::next(current)) + { + auto face = mesh.make_face_in_world_space(current); + + auto ray_stop_point = get_ray_hit_point(ray, face); + if (ray_stop_point.distance_to(ray.start) < mesh_hit.distance_to(ray.start)) + mesh_hit = ray_stop_point; + } + + return mesh_hit; + } }; } // namespace omath::collision