This repository has been archived on 2024-12-30. You can view files and clone it, but you cannot make any changes to it's state, such as pushing and creating new issues, pull requests or comments.
2024CG-project-render/lab1/first_hit.cpp
Tibo De Peuter d9cf26902e
Some checks failed
CMake / build (zip, zip, [self-hosted Linux], raytracing, ux) (push) Has been cancelled
CMake / build (zip, zip, [self-hosted Windows], Release/raytracing.exe, win) (push) Has been cancelled
chore: Cleanup
2024-10-25 17:50:44 +02:00

31 lines
807 B
C++

#include "first_hit.h"
bool first_hit(
const Ray &ray,
const double min_t,
const std::vector<std::shared_ptr<Object> > &objects,
int &hit_id,
double &t,
Eigen::Vector3d &n) {
double t_temp;
Eigen::Vector3d n_temp;
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. */
for (int i = 0; i < objects.size(); ++i) {
if (objects[i]->intersect(ray, min_t, t_temp, n_temp)) {
hit = true;
if (t == -1 || t_temp < t) {
hit_id = i;
t = t_temp;
n = n_temp;
}
}
}
return hit;
}