-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplan.c
40 lines (35 loc) · 1.41 KB
/
plan.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* plan.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bmikaeli <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/02/16 19:29:55 by tdemay #+# #+# */
/* Updated: 2014/03/17 11:13:27 by bmikaeli ### ########.fr */
/* */
/* ************************************************************************** */
#include "plan.h"
t_plan *new_plan(t_vect *pos, t_vect *dir, t_color *c)
{
t_plan *new;
new = NEW(t_plan);
new->pos = pos;
new->dir = dir;
new->color = c;
return (new);
}
float intersect_plan(t_vect *point, t_cam *cam, t_plan *p)
{
float t;
float dv;
t_vect *dir_norm;
dir_norm = copy_vect(p->dir);
vector_normalize(dir_norm);
dv = - (dir_norm->x * p->pos->x) - (dir_norm->y * p->pos->y)
- (dir_norm->z * p->pos->z);
t = ((DOTPROD(dir_norm, cam->pos) - dv) / DOTPROD(dir_norm, point));
if (t > 0)
return (t);
return (-1);
}