mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-12 22:53:27 +00:00
WIP on feature/rotation_improved
This commit is contained in:
@@ -33,5 +33,25 @@ namespace omath::collision
|
||||
// https://en.wikipedia.org/wiki/M%C3%B6ller%E2%80%93Trumbore_intersection_algorithm
|
||||
[[nodiscard]]
|
||||
static Vector3<float> get_ray_hit_point(const Ray& ray, const Triangle<Vector3<float>>& triangle) noexcept;
|
||||
|
||||
template<class MeshType>
|
||||
[[nodiscard]]
|
||||
static Vector3<float> get_ray_hit_point(const Ray& ray, const MeshType& mesh) noexcept
|
||||
{
|
||||
Vector3<float> 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
|
||||
|
||||
Reference in New Issue
Block a user