-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck_hits.c
70 lines (64 loc) · 2.15 KB
/
check_hits.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* ************************************************************************** */
/* */
/* :::::::: */
/* check_hits.c :+: :+: */
/* +:+ */
/* By: dnoom <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/04/06 11:25:30 by dnoom #+# #+# */
/* Updated: 2022/04/06 11:25:30 by dnoom ######## odam.nl */
/* */
/* ************************************************************************** */
#include "miniRT.h"
int check_hit(float hit, float *hit_min, int *num, int i)
{
if (hit > 0 && (hit < *hit_min || *hit_min == 0.))
{
*hit_min = hit;
*num = i;
return (1);
}
return (0);
}
float get_hit_distance(t_object object, t_ray r, int *hit_side)
{
float hit_distance;
if (object.base.type == PLANE)
hit_distance = hit_plane(object.plane.dir_base.dir, \
object.plane.dir_base.base.pos, r);
else if (object.base.type == SPHERE)
hit_distance = hit_sphere(object.sphere, r);
else if (object.base.type == CYLINDER)
hit_distance = hit_cylinder(object.cylinder, r, hit_side);
else
hit_distance = hit_paraboloid(object.paraboloid, r);
return (hit_distance);
}
void objects_loop(t_ray r, t_scene *scene, t_hits *hits, \
float distance_to_spot)
{
int i;
int hit_side;
float hit;
t_object *objects;
i = 0;
objects = scene->objects.data;
while (i < scene->objects.len)
{
hit = get_hit_distance(objects[i], r, &hit_side);
if (distance_to_spot > 0 && hit > 0 && \
hit < distance_to_spot)
{
hits->hit_min = 1;
return ;
}
if (!distance_to_spot && \
check_hit(hit, &hits->hit_min, &hits->object_index, i))
{
hits->hit_type = objects[i].base.type;
hits->material = objects[i].base.material;
hits->hit_side_cylinder = hit_side;
}
i++;
}
}