From 607590983cd70331fdd15f31c346f654997f6d07 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Sat, 5 Oct 2024 21:22:07 +0200 Subject: [PATCH] feat: Intersect with TriangleSoup --- src/TriangleSoup.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/TriangleSoup.cpp b/src/TriangleSoup.cpp index d4987d1..bb86eec 100644 --- a/src/TriangleSoup.cpp +++ b/src/TriangleSoup.cpp @@ -4,12 +4,28 @@ #include "first_hit.h" bool TriangleSoup::intersect( - const Ray & ray, const double min_t, double & t, Eigen::Vector3d & n) const + const Ray & ray, const double min_t, double & t, Eigen::Vector3d & n) const { - //////////////////////////////////////////////////////////////////////////// - // Replace with your code here: - return false; - //////////////////////////////////////////////////////////////////////////// + bool hit = false; + /* Initialize to a value that will never be used. */ + t = -1; + /* Alternatively, use a max integer value, and remove the check t == -1. */ + + /* Store intermediate results that are not necessarily the first hit. */ + double t_temp; + Eigen::Vector3d n_temp; + + for (const auto & triangle : triangles) { + if (triangle->intersect(ray, min_t, t_temp, n_temp)) { + hit = true; + if (t == -1 || t_temp < t) { + t = t_temp; + n = n_temp; + } + } + } + + return hit; }