From c45331d79d187210adcac2bdd6a84dde78a4b07d Mon Sep 17 00:00:00 2001 From: Eryn Wells Date: Sat, 7 Sep 2013 18:41:46 -0700 Subject: [PATCH] Initial interesection test for ray tracing --- src/scene.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/scene.c b/src/scene.c index 38b979e..948d908 100644 --- a/src/scene.c +++ b/src/scene.c @@ -143,5 +143,26 @@ _scene_trace(Scene *scene, const Ray ray, const int depth) { Color out_color = {0, 0, 0}; + // Find intersections of this ray with objects in the scene. + Object *intersected_obj = NULL; + float *t = NULL; + float nearest_t; + int nints; + ObjectList *ptr = scene->objects; + while (ptr != NULL) { + nints = object_does_intersect(ptr->object, ray, &t); + for (int i = 0; i < nints; i++) { + if (t[i] < nearest_t) { + intersected_obj = ptr->object; + nearest_t = t[i]; + } + } + ptr = ptr->next; + } + + if (intersected_obj == NULL) { + return out_color; + } + return out_color; }