return (get_intersection_arg_bounded(ray, object));
}
-const t_object *find_nearest_object(const t_ray *ray, const t_vec *objects)
+const t_object *find_nearest_object(const t_ray *ray, const t_vec *objects,
+ const t_object *ignored)
{
size_t i;
const t_object *object_found;
+ const t_object *object;
double distance_found;
double distance;
i = 0;
while (i < objects->size)
{
- distance = get_intersection_arg(ray, ft_vec_caccess(objects, i));
+ object = ft_vec_caccess(objects, i++);
+ if (object == ignored)
+ continue ;
+ distance = get_intersection_arg(ray, object);
if (0 < distance && distance < distance_found)
{
distance_found = distance;
- object_found = ft_vec_caccess(objects, i);
+ object_found = object;
}
- ++i;
}
return (object_found);
}
new_ray.start = point;
new_ray.direction = vec_diff(light->position, new_ray.start);
- obstruction = find_nearest_object(&new_ray, &scene->objects);
+ obstruction = find_nearest_object(&new_ray, &scene->objects, object);
normal = get_object_normal(object, point);
angle_multiplier = vec_scalar_mul(normal, new_ray.direction)
/ (vec_norm(normal) * vec_norm(new_ray.direction));
{
const t_object *object_found;
- object_found = find_nearest_object(ray, &scene->objects);
+ object_found = find_nearest_object(ray, &scene->objects, NULL);
if (object_found)
return (get_object_color(ray, object_found, scene));
else