feat: Intersect with TriangleSoup
This commit is contained in:
parent
38e185a3ef
commit
607590983c
1 changed files with 21 additions and 5 deletions
|
@ -4,12 +4,28 @@
|
||||||
#include "first_hit.h"
|
#include "first_hit.h"
|
||||||
|
|
||||||
bool TriangleSoup::intersect(
|
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
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////////////////////
|
bool hit = false;
|
||||||
// Replace with your code here:
|
/* Initialize to a value that will never be used. */
|
||||||
return false;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Reference in a new issue