-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsing_cylinder.c
81 lines (73 loc) · 2.62 KB
/
parsing_cylinder.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* parsing_cylinder.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tmillenn <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/09 16:11:06 by tmillenn #+# #+# */
/* Updated: 2022/01/09 16:11:07 by tmillenn ### ########.fr */
/* */
/* ************************************************************************** */
#include "minirt.h"
static void ft_new_cylinder(t_cylinder **cylinder)
{
*cylinder = (t_cylinder *)malloc(sizeof(t_cylinder));
if (!(*cylinder))
ft_error_sys_call();
(*cylinder)->coord = NULL;
(*cylinder)->dir = NULL;
(*cylinder)->r = 0;
(*cylinder)->h = 0;
(*cylinder)->color = NULL;
(*cylinder)->next = NULL;
}
static void ft_add_back_cylinder(t_cylinder **cylinder, t_cylinder *new)
{
t_cylinder *tmp;
tmp = *cylinder;
while (tmp->next != NULL)
tmp = tmp->next;
tmp->next = new;
}
static void ft_get_cylinder_radius(char *diameter, t_cylinder **cylinder)
{
ft_str_is_valid_float(diameter, "Unacceptable cylinder diameter\n");
(*cylinder)->r = ft_get_float(diameter) * 0.5;
if ((*cylinder)->r < 0)
ft_error("Invalid cylinder diameter!\nUse d > 0\n");
}
static void ft_get_cylinder_height(char *height, t_cylinder **cylinder)
{
ft_str_is_valid_float(height, "Unacceptable cylinder height\n");
(*cylinder)->h = ft_get_float(height);
if ((*cylinder)->h < 0)
ft_error("Invalid cylinder height!\nUse h > 0\n");
}
void ft_add_cylinder(char **params, t_scene *scene)
{
int count;
t_cylinder *cylinder;
t_cylinder *tmp;
count = ft_count_params(params);
if (count == 6)
{
ft_new_cylinder(&cylinder);
if (!scene->cy)
scene->cy = cylinder;
else
ft_add_back_cylinder(&(scene->cy), cylinder);
tmp = scene->cy;
while (tmp->next != NULL)
tmp = tmp->next;
ft_get_coord(params[1], &(tmp->coord), "cylinder");
ft_get_norm_vector(params[2], &(tmp->dir), "cylinder");
ft_get_cylinder_radius(params[3], &tmp);
ft_get_cylinder_height(params[4], &tmp);
ft_get_color(params[5], &(tmp->color), "cylinder");
}
else if (count < 6)
ft_error("Too little information about cylinder\n");
else
ft_error("Too much information about cylinder\n");
}