-
Notifications
You must be signed in to change notification settings - Fork 0
/
inter_plane.c
70 lines (62 loc) · 2.12 KB
/
inter_plane.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* inter_plane.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qchevrin <qchevrin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/03/13 12:17:47 by qchevrin #+# #+# */
/* Updated: 2014/03/26 18:06:42 by qchevrin ### ########.fr */
/* */
/* ************************************************************************** */
#include "raytracer.h"
static void update_info(t_info *info, double dist, void *obj, t_line new)
{
t_plane *plane;
info->distance = dist;
info->obj_type = PLANE;
info->obj = obj;
plane = (t_plane *)obj;
info->color = plane->color;
info->s_line.pos.x = new.pos.x;
info->s_line.pos.y = new.pos.y;
info->s_line.pos.z = new.pos.z;
info->s_line.vec.x = new.vec.x;
info->s_line.vec.y = new.vec.y;
info->s_line.vec.z = new.vec.z;
}
static double delta(t_plane *plane, t_line new)
{
(void)plane;
if (new.vec.y > -0.0001 && new.vec.y < 0.0001)
return (-1);
return (-(new.pos.y / new.vec.y));
}
static t_line get_new_equa(t_plane *obj, t_line line)
{
t_line new;
new.pos.x = line.pos.x;
new.pos.y = line.pos.y;
new.pos.z = line.pos.z;
new.vec.x = line.vec.x;
new.vec.y = line.vec.y;
new.vec.z = line.vec.z;
apply_trans(obj->m_i, &new.pos);
apply_rot(obj->m_i, &new.vec);
return (new);
}
void inter_plane(t_info *info, t_list *plane)
{
t_plane *obj;
t_line new;
double dist;
while (plane)
{
obj = (t_plane *)plane->content;
new = get_new_equa(obj, info->r_line);
dist = delta(obj, new);
if (dist > 0.001 && (info->distance < 0 || dist < info->distance))
update_info(info, dist, plane->content, new);
plane = plane->next;
}
}