Fix some minor bugs in the RT calculations
authorLukas Jiriste <ljiriste@student.42prague.com>
Sat, 23 Nov 2024 12:07:09 +0000 (13:07 +0100)
committerLukas Jiriste <ljiriste@student.42prague.com>
Sat, 23 Nov 2024 12:07:09 +0000 (13:07 +0100)
src/scene.c

index 196ef43954455bed73b473c4cc3b2577f31795cf..841af39a2a0d8b33fdf7af74464400a6a056921f 100644 (file)
@@ -18,7 +18,7 @@ static int    is_bounded(const t_object *object)
        enum e_object_type      type;
 
        type = object->type;
-       return (type == PLANE);
+       return (type != PLANE);
 }
 
 double get_cylinder_circumsphere_radius(const t_cylinder *cylinder)
@@ -36,10 +36,10 @@ double      dist_point_from_line(const t_ray *ray, t_vec3 point)
        t_vec3  start;
        t_vec3  projection;
 
-       start = vec_diff(point, ray->start);
+       start = vec_diff(ray->start, point);
        projection = vec_real_mul(ray->direction,
                        vec_scalar_mul(ray->direction, start));
-       return (vec_norm(projection));
+       return (vec_norm(vec_diff(start, projection)));
 }
 
 int    is_behind_ray(const t_ray *ray, t_vec3 point)
@@ -240,6 +240,7 @@ t_color     get_object_color(const t_ray *ray, const t_object *object,
        t_ray                   new_ray;
        const t_object  *obstruction;
 
+       result = (t_color){.x = 0, .y = 0, .z = 0};
        i = 0;
        while (i < scene->lights.size)
        {