-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_nearest.c
39 lines (36 loc) · 1.52 KB
/
get_nearest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get_nearest.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: shongou <shongou@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/04 23:33:40 by shongou #+# #+# */
/* Updated: 2023/01/04 23:33:41 by shongou ### ########.fr */
/* */
/* ************************************************************************** */
#include "minirt.h"
t_nearest get_nearest(t_config config, t_ray ray, double max_d, bool shadow)
{
bool hit_flag;
t_nearest nearest;
t_intersection i_point;
nearest.flag = false;
nearest.i_point.distance = max_d;
config.shape_list = config.shape_list->next;
while (config.shape_list != NULL)
{
hit_flag = is_hittable(*(config.shape_list), ray, &i_point);
if (hit_flag && i_point.distance > 0 \
&& i_point.distance < nearest.i_point.distance)
{
nearest.shape = *(config.shape_list);
nearest.i_point = i_point;
nearest.flag = true;
if (shadow)
break ;
}
config.shape_list = config.shape_list->next;
}
return (nearest);
}