-
Notifications
You must be signed in to change notification settings - Fork 0
/
camera.c
61 lines (55 loc) · 1.93 KB
/
camera.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* camera.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sboeuf <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/02/16 19:17:38 by sboeuf #+# #+# */
/* Updated: 2014/02/16 19:17:41 by sboeuf ### ########.fr */
/* */
/* ************************************************************************** */
#include "includes/rtv1.h"
t_camera *new_camera(t_vect *p, t_vect *di, t_vect *r, t_vect *dwn)
{
t_camera *c;
c = (t_camera*)malloc(sizeof(t_camera));
c->campos = p;
c->camdir = di;
c->camright = r;
c->camdown = dwn;
return (c);
}
void delete_camera(t_camera *c)
{
delete_vect(c->campos);
delete_vect(c->camdir);
delete_vect(c->camright);
delete_vect(c->camdown);
free(c);
}
t_camera *get_camera(int fd)
{
int r;
t_camera *c;
char *line;
t_vect *diff_btw;
t_vect *look_at;
c = new_camera(NULL, NULL, NULL, NULL);
while ((r = get_next_line(fd, &line)) > 0 && ft_strcmp(line, "----------"))
{
if (!ft_strcmp("pos:", line))
c->campos = get_vector(fd);
if (!ft_strcmp("dir:", line))
look_at = get_vector(fd);
}
if (r == -1)
exit(-1);
diff_btw = new_vector(c->campos->x - look_at->x,
c->campos->y - look_at->y,
c->campos->z - look_at->z);
c->camdir = normalize(negative(diff_btw));
c->camright = normalize(crossProduct(new_vector(0, 1, 0), c->camdir));
c->camdown = crossProduct(c->camright, c->camdir);
return (c);
}