-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvert.c
60 lines (54 loc) · 1.8 KB
/
convert.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* convert.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rblondia <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/17 16:25:10 by rblondia #+# #+# */
/* Updated: 2021/12/17 16:25:29 by rblondia ### ########.fr */
/* */
/* ************************************************************************** */
#include "../../includes/fdf.h"
static t_point *create_point(int z, int color)
{
t_point *p;
p = malloc(sizeof(t_point));
if (!p)
return (NULL);
p->z = z;
p->color = color;
return (p);
}
void convert_vectors(t_map *map)
{
t_point **cords;
ssize_t i;
size_t arr_size;
size_t index;
arr_size = map->width * map->height;
cords = malloc(sizeof(t_point *) * (arr_size + 1));
if (!cords)
exit(EXIT_FAILURE);
i = map->width * map->height - 1;
index = v3f_length(map->vectors) - 1;
while (map->vectors[index])
{
cords[i] = create_point(map->vectors[index]->z,
map->vectors[index]->color);
if (cords[i]->z < map->z_min)
map->z_min = cords[i]->z;
if (cords[i]->z > map->z_max)
map->z_max = cords[i]->z;
i--;
index--;
}
cords[arr_size] = NULL;
map->cords = cords;
}
int get_point_color(t_point *point, t_fdf *fdf)
{
if (point->color == -1)
return (get_default_color(point->z, fdf->map));
return (point->color);
}