-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget.c
90 lines (81 loc) · 2.32 KB
/
get.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* get.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gphilips <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/29 17:11:45 by gphilips #+# #+# */
/* Updated: 2017/12/22 16:16:34 by gphilips ### ########.fr */
/* */
/* ************************************************************************** */
#include "rtv1.h"
int get_clrpos(t_obj *obj, const char **tab, int *i)
{
int j;
double check;
if (ft_strncmp("\t\tclr(", tab[*i], 6))
return (0);
j = 6;
if (((check = ft_atof(tab[*i], &j)) < 0) || check > 255)
return (0);
obj->color.r = (int)check;
if (((check = ft_atof(tab[*i], &j)) < 0) || check > 255)
return (0);
obj->color.g = (int)check;
if (((check = ft_atof(tab[*i], &j)) < 0) || check > 255)
return (0);
obj->color.b = (int)check;
if (tab[*i][j] != ')' || tab[*i][j + 1]
|| ft_strncmp("\t\tpos(", tab[++(*i)], 6))
return (0);
j = 6;
SAFEMALL0((input_vector(tab[*i], &j, &obj->pos)));
++(*i);
return (1);
}
int get_size(t_obj *obj, const char **tab, int *i)
{
int j;
if (ft_strncmp("\t\tsize(", tab[*i], 7))
return (0);
j = 7;
obj->size = ft_atof(tab[*i], &j);
while (ft_isdigit(tab[*i][j]))
++j;
if (tab[*i][j] != ')' || tab[*i][j + 1])
return (0);
++(*i);
return (1);
}
int get_normal(t_obj *obj, const char **tab, int *i)
{
int j;
if (ft_strncmp("\t\tnml(", tab[*i], 6))
return (0);
j = 6;
SAFEMALL0((input_vector(tab[*i], &j, &obj->normal)));
++(*i);
return (1);
}
void get_light(t_env *e)
{
t_list *tmp;
t_obj *obj;
int i;
tmp = e->obj;
e->total_light = 0;
while (tmp)
{
obj = (t_obj*)tmp->content;
i = -1;
if (obj && obj->name == LIGHT)
{
e->light[e->total_light] = obj;
e->total_light++;
}
tmp = tmp->next;
}
if (e->total_light < MAX_LIGHT)
e->light[e->total_light] = NULL;
}