-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlimited_sphere.c
36 lines (33 loc) · 1.51 KB
/
limited_sphere.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* limited_sphere.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: qchevrin <qchevrin@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/03/18 17:18:46 by qchevrin #+# #+# */
/* Updated: 2014/03/26 20:35:32 by qchevrin ### ########.fr */
/* */
/* ************************************************************************** */
#include "raytracer.h"
double limited_sphere(t_sphere *obj, t_line line, double *dist)
{
t_coord pos;
if (dist[0] < 0 || !obj->is_limited)
return (dist[0]);
pos.x = line.pos.x + dist[0] * line.vec.x;
pos.y = line.pos.y + dist[0] * line.vec.y;
pos.z = line.pos.z + dist[0] * line.vec.z;
if (pos.x > obj->lim_h_x || pos.x < obj->lim_b_x)
dist[0] = -1;
else if (pos.y > obj->lim_h_y || pos.y < obj->lim_b_y)
dist[0] = -1;
else if (pos.z > obj->lim_h_z || pos.z < obj->lim_b_z)
dist[0] = -1;
if (dist[0] < 0 && dist[1] > 0)
{
swap_double(&(dist[0]), &(dist[1]));
return (limited_sphere(obj, line, dist));
}
return (dist[0]);
}