-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintersection.c
More file actions
44 lines (41 loc) · 1.26 KB
/
Copy pathintersection.c
File metadata and controls
44 lines (41 loc) · 1.26 KB
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
40
41
42
43
44
#include "minirt.h"
t_intersection calc_intersection(t_ray ray, t_object object)
{
if (object.type == PLANE)
return (calc_plane_intersection(ray, object));
else if (object.type == SPHERE)
return (calc_sphere_intersection(ray, object));
else if (object.type == TRIANGLE)
return (calc_triangle_intersection(ray, object));
else if (object.type == SQUARE)
return (calc_square_intersection(ray, object));
else if (object.type == CYLINDER)
return (calc_cylinder_intersection(ray, object));
}
// レイがどのオブジェクトとも交点を持たない時にNULLを返す
t_object *get_nearest_object(t_world *world, t_ray ray)
{
t_object *nearest_object;
t_object *current_object;
double nearest_distance;
t_list *current_lst;
t_intersection intersection;
nearest_distance = INFINITY;
nearest_object = NULL;
current_lst = world->objects;
while (current_lst)
{
current_object = (t_object*)current_lst->content;
intersection = calc_intersection(ray, *current_object);
if (intersection.has_intersection)
{
if (intersection.distance >= 0 && intersection.distance <= nearest_distance)
{
nearest_object = current_object;
nearest_distance = intersection.distance;
}
}
current_lst = current_lst->next;
}
return (nearest_object);
}