Fix not rendering the inside of objects correctly
authorLukas Jiriste <ljiriste@student.42prague.com>
Sat, 4 Jan 2025 12:36:28 +0000 (13:36 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Sat, 4 Jan 2025 12:36:28 +0000 (13:36 +0100)
The optimization of seeing whether the circumsphere would interact with
a ray contains a check for whether the circumsphere CENTER is behind the
ray origin instead of its furthest point. This is now rectified which
fixes the rendering when inside an object.

src/scene.c

index 44fb0b5ca223d544c549fc15b2b211888f9be1ad..6b35944024259cde07e4fdfb478b1abe42f81dd5 100644 (file)
@@ -83,7 +83,7 @@ int   intersects_circumsphere(const t_ray *ray, const t_object *object)
        double          distance;
 
        circumsphere = get_circumsphere(object);
-       if (is_behind_ray(ray, circumsphere.center))
+       if (is_behind_ray(ray, vec_add(circumsphere.center, vec_real_mul(ray->direction, circumsphere.radius))))
                return (0);
        distance = dist_point_from_line(ray, circumsphere.center);
        return (distance < circumsphere.radius);