-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_scene2.c
More file actions
88 lines (82 loc) · 3.08 KB
/
read_scene2.c
File metadata and controls
88 lines (82 loc) · 3.08 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* read_scene2.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: chorange <chorange@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/04/12 12:58:18 by chorange #+# #+# */
/* Updated: 2019/04/12 13:48:20 by chorange ### ########.fr */
/* */
/* ************************************************************************** */
#include "rtv1.h"
void set_obj_type(char *line, t_obj *obj)
{
if (ft_strstr(line, "sphere"))
obj->type = sphere;
else if (ft_strstr(line, "cylinder"))
obj->type = cylinder;
else if (ft_strstr(line, "cone"))
obj->type = cone;
else if (ft_strstr(line, "plane"))
obj->type = plane;
else
err_exit();
}
void set_light_type(char *line, t_light *light)
{
if (ft_strstr(line, "point"))
light->type = point;
else if (ft_strstr(line, "directional"))
light->type = directional;
else if (ft_strstr(line, "ambient"))
light->type = ambient;
else
err_exit();
}
t_obj *read_obj_parameters(char *line, t_obj **obj)
{
if (ft_strchr(line, '}'))
return (NULL);
else if (ft_strstr(line, "type"))
set_obj_type(line, *obj);
else if (ft_strstr(line, "position"))
(*obj)->center = read_vector(ft_strchr(line, '=') + 1);
else if (ft_strstr(line, "radius"))
(*obj)->radius = ft_atof(ft_strchr(line, '=') + 1);
else if (ft_strstr(line, "color"))
(*obj)->rgb = color_to_rgb(ft_atoi(ft_strchr(line, '=') + 1));
else if (ft_strstr(line, "angle"))
(*obj)->angle = ft_atof(ft_strchr(line, '=') + 1);
else if (ft_strstr(line, "direction"))
(*obj)->dir = vector_normalize(read_vector(ft_strchr(line, '=') + 1));
else if (ft_strstr(line, "specular"))
(*obj)->specular = ft_atof(ft_strchr(line, '=') + 1);
else if (ft_strstr(line, "reflective"))
(*obj)->reflective = ft_atof(ft_strchr(line, '=') + 1);
return (*obj);
}
t_light *read_light_parameters(char *line, t_light **light)
{
if (ft_strchr(line, '}'))
return (NULL);
else if (ft_strstr(line, "type"))
set_light_type(line, *light);
else if (ft_strstr(line, "position"))
(*light)->center = read_vector(ft_strchr(line, '=') + 1);
else if (ft_strstr(line, "direction"))
(*light)->dir = vector_normalize(read_vector(ft_strchr(line, '=') + 1));
else if (ft_strstr(line, "intensity"))
(*light)->intensity = ft_atof(ft_strchr(line, '=') + 1);
return (*light);
}
t_camera *camera_init(char *line, t_camera *camera)
{
if (ft_strchr(line, '}'))
return (NULL);
else if (ft_strstr(line, "position"))
camera->center = read_vector(ft_strchr(line, '=') + 1);
else if (ft_strstr(line, "direction"))
camera->dir = read_vector(ft_strchr(line, '=') + 1);
return (camera);
}