This repository was archived by the owner on Dec 8, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_read_objects.cpp
More file actions
102 lines (93 loc) · 3.14 KB
/
Copy pathft_read_objects.cpp
File metadata and controls
102 lines (93 loc) · 3.14 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_read_objects.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rserban <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/03/07 15:30:24 by rserban #+# #+# */
/* Updated: 2015/03/11 16:16:39 by rserban ### ########.fr */
/* */
/* ************************************************************************** */
#include "raytracer.h"
void read_planes(FILE *f, t_env *e, int *i)
{
char **nums;
char line[256];
while (fgets(line, 256, f) && !strstr(line, "****"))
{
if (populate_array(line, &nums))
{
if (!strcmp(nums[0], "normal:"))
e->objs[*i] = new_object(plane, get_vector(nums), NULL, NULL);
else if (!strcmp(nums[0], "distance:"))
e->objs[*i]->obj = new_plane(atof(nums[1]));
free_char_array(&nums);
}
else if (e->objs[*i] && strstr(line, "material:"))
e->objs[(*i)++]->mat = read_material(f);
}
}
void read_spheres(FILE *f, t_env *e, int *i)
{
char **nums;
char line[256];
while (fgets(line, 256, f) && !strstr(line, "****"))
{
if (populate_array(line, &nums))
{
if (!strcmp(nums[0], "center:"))
e->objs[*i] = new_object(sphere, get_vector(nums), NULL, NULL);
else if (!strcmp(nums[0], "radius:"))
e->objs[*i]->obj = new_sphere(atof(nums[1]));
free_char_array(&nums);
}
else if (e->objs[*i] && strstr(line, "material:"))
e->objs[(*i)++]->mat = read_material(f);
}
}
void read_cylinders(FILE *f, t_env *e, int *i)
{
char **nums;
char line[256];
t_vec3 *dir;
float radius;
while (fgets(line, 256, f) && !strstr(line, "****"))
{
if (populate_array(line, &nums))
{
if (!strcmp(nums[0], "center:"))
e->objs[*i] = new_object(cyl, get_vector(nums), NULL, NULL);
else if (!strcmp(nums[0], "direction:"))
dir = get_vector(nums);
else if (!strcmp(nums[0], "radius:"))
radius = atof(nums[1]);
else if (!strcmp(nums[0], "length:"))
e->objs[*i]->obj = new_cylinder(dir, radius, atof(nums[1]));
free_char_array(&nums);
}
else if (e->objs[*i] && strstr(line, "material:"))
e->objs[(*i)++]->mat = read_material(f);
}
}
void read_cones(FILE *f, t_env *e, int *i)
{
char **nums;
char line[256];
t_vec3 *dir;
while (fgets(line, 256, f) && !strstr(line, "****\n"))
{
if (populate_array(line, &nums))
{
if (!strcmp(nums[0], "center:"))
e->objs[*i] = new_object(cone, get_vector(nums), NULL, NULL);
else if (!strcmp(nums[0], "direction:"))
dir = get_vector(nums);
else if (!strcmp(nums[0], "angle:"))
e->objs[*i]->obj = new_cone(dir, atof(nums[1]));
free_char_array(&nums);
}
else if (e->objs[*i] && strstr(line, "material:"))
e->objs[(*i)++]->mat = read_material(f);
}
}