-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_ambient_lighting.c
47 lines (43 loc) · 1.05 KB
/
build_ambient_lighting.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
#include <stdio.h>
#include "libft.h"
#include "print.h"
#include "builder_internal.h"
/*
A 0.2 255,255,255
∗ identifier: A
∗ ambient lighting ratio in range [0.0,1.0]: 0.2
∗ R,G,B colors in range [0-255]: 255, 255, 255
*/
t_bool is_ambient_lighting(const t_ptrarr *tokens)
{
static const int patternlen = 7;
static const int pattern[7] = {
TOKENTYPE_IDENTIFIER,
TOKENTYPE_NUMBER,
TOKENTYPE_NUMBER,
TOKENTYPE_COMMA,
TOKENTYPE_NUMBER,
TOKENTYPE_COMMA,
TOKENTYPE_NUMBER
};
if (is_in_pattern(IDENTIFIER_AMBIENTLIGHTING, pattern, patternlen, tokens))
return (TRUE);
return (FALSE);
}
int build_ambient_lighting(const t_ptrarr *tokens, t_scene *scene)
{
double ratio;
t_vec3 color;
ratio = ft_atof(tokens->data[1]);
if (is_invalid_ratio(ratio))
return (CODE_ERROR_DATA);
build_vector(&color, &tokens->data[2]);
if (is_invalid_color(&color))
return (CODE_ERROR_DATA);
map_color(&color);
vec3_mult_num(&scene->bg, &color, ratio);
printf("%s: background color ", __func__);
print_vec3(&scene->bg);
printf("\n");
return (CODE_OK);
}