From d5474546ca9f8971188456f6cf338011c3be3ca7 Mon Sep 17 00:00:00 2001 From: Camden Dixie O'Brien Date: Sun, 21 Sep 2025 13:30:36 +0100 Subject: [PATCH] Simplify hit detection logic --- src/camera.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/camera.c b/src/camera.c index c9c9047..d225961 100644 --- a/src/camera.c +++ b/src/camera.c @@ -10,13 +10,10 @@ static const vec3_t white = { 1.0, 1.0, 1.0 }; static vec3_t trace(ray_t ray, const obj_t *scene, unsigned scene_count) { - bool got_hit = false; hit_t hit = { .t = DBL_MAX }; - for (unsigned i = 0; i < scene_count; ++i) { - if (scene[i].intersect(scene[i].params, ray, &hit, 0.0, hit.t)) - got_hit = true; - } - if (got_hit) + for (unsigned i = 0; i < scene_count; ++i) + scene[i].intersect(scene[i].params, ray, &hit, 0.0, hit.t); + if (hit.t != DBL_MAX) return vec3_scale(vec3_add(hit.normal, white), 0.5); const double a = (ray.dir.y + 1.0) / 2.0;