-
Notifications
You must be signed in to change notification settings - Fork 0
/
limited_cylinder.c
47 lines (42 loc) · 1.66 KB
/
limited_cylinder.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* limited_cylinder.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qchevrin <qchevrin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/03/26 16:40:55 by qchevrin #+# #+# */
/* Updated: 2014/03/26 21:16:35 by qchevrin ### ########.fr */
/* */
/* ************************************************************************** */
#include <raytracer.h>
double limited_cylinder(t_cylinder *obj, t_line line, double *dist)
{
t_coord pos;
if (dist[0] < 0 || !obj->is_limited)
return (dist[0]);
pos.y = line.pos.y + dist[0] * line.vec.y;
if (pos.y > obj->lim_h || pos.y < obj->lim_b)
dist[0] = -1;
if (dist[0] < 0 && dist[1] > 0)
{
swap_double(&(dist[0]), &(dist[1]));
return (limited_cylinder(obj, line, dist));
}
return (dist[0]);
}
double limited_cone(t_cone *obj, t_line line, double *dist)
{
t_coord pos;
if (dist[0] < 0 || !obj->is_limited)
return (dist[0]);
pos.y = line.pos.y + dist[0] * line.vec.y;
if (pos.y > obj->lim_h || pos.y < obj->lim_b)
dist[0] = -1;
if (dist[0] < 0 && dist[1] > 0)
{
swap_double(&(dist[0]), &(dist[1]));
return (limited_cone(obj, line, dist));
}
return (dist[0]);
}