-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_material_dielectric.c
63 lines (57 loc) · 1.49 KB
/
build_material_dielectric.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
#include <stdlib.h>
#include <stdio.h>
#include "libft.h"
#include "print.h"
#include "msgdef.h"
#include "builder_internal.h"
/*
mt_dielectric <name> <IOR>
0 1 2
∗ identifier: mt_dielectric
∗ name: arbitary given name of the material
∗ IOR: IOR value
*/
t_bool is_material_dielectric(const t_ptrarr *tokens)
{
static const int patternlen = 3;
static const int pattern[3] = {
TOKENTYPE_IDENTIFIER,
TOKENTYPE_WORD,
TOKENTYPE_WORD
};
if (is_in_pattern(IDENTIFIER_MATERIAL_DIELECTRIC,
pattern, patternlen, tokens))
return (TRUE);
return (FALSE);
}
static int add_material_dielectric(t_scene *scene,
const char *name, double ior)
{
t_material *dielectric;
dielectric = material_dielectric_create(name, ior);
if (!dielectric)
return (CODE_ERROR_MALLOC);
if (ptrarr_append(scene->res.materials, dielectric))
{
dielectric->destroy(dielectric);
return (CODE_ERROR_MALLOC);
}
return (CODE_OK);
}
int build_material_dielectric(const t_ptrarr *tokens, t_scene *scene)
{
const char *name = tokens->data[1];
const double ior = ft_atof(tokens->data[2]);
t_material_dielectric *dielectric;
if (ior < 1)
{
printf("%s: IOR "MSG_OUTOFRANGE"\n", EXEC_NAME,
ior, 1.0, DOUBLE_INF);
}
if (add_material_dielectric(scene, name, ior))
return (CODE_ERROR_MALLOC);
dielectric = (t_material_dielectric *)ptrarr_getlast(scene->res.materials);
printf("%s: dielectric material (%s, IOR %.2f)\n", __func__,
dielectric->name, dielectric->ior);
return (CODE_OK);
}