-
Notifications
You must be signed in to change notification settings - Fork 0
/
object.c
99 lines (90 loc) · 3.06 KB
/
object.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* ************************************************************************** */
/* */
/* :::::::: */
/* object.c :+: :+: */
/* +:+ */
/* By: jandre-d <[email protected]> +#+ */
/* +#+ */
/* Created: 2019/03/02 10:46:06 by jandre-d #+# #+# */
/* Updated: 2019/03/21 11:56:03 by jandre-d ######## odam.nl */
/* */
/* ************************************************************************** */
#include "object.h"
static t_object_elem *vector_array_alloc(t_input *input)
{
t_object_elem *to_return;
uint32_t i;
i = 0;
if (input->heightmap_size_y == 0 || input->heightmap_size_x == 0 ||
input->list == NULL || input->list->line_list == NULL ||
input->list->line_list->point_list == NULL)
return (NULL);
to_return = NEW(t_object_elem);
if (to_return == NULL)
return (NULL);
to_return->size_y = input->heightmap_size_y;
to_return->size_x = input->heightmap_size_x;
to_return->vectors =
ft_memalloc(to_return->size_y * sizeof(t_object_point *));
if (to_return->vectors == NULL)
return (NULL);
while (i < to_return->size_y)
{
if ((to_return->vectors
[i] = ft_memalloc(to_return->size_x * sizeof(t_object_point))) == NULL)
return (NULL);
i++;
}
return (to_return);
}
static void move_input_to(t_input *input, t_object_elem *obj)
{
t_input_list_line *use_me_line;
t_input_list_point *use_me_point;
int32_t offset_x;
int32_t offset_y;
use_me_line = input->list->line_list;
offset_y = 0;
while (offset_y < obj->size_y)
{
offset_x = 0;
use_me_point = use_me_line->point_list;
while (offset_x < obj->size_x)
{
obj->vectors[offset_y][offset_x].r_loc.x =
(offset_x + input->heightmap_size_x / 2 * -1) * POINT_SPACEING;
obj->vectors[offset_y][offset_x].r_loc.y =
(offset_y + input->heightmap_size_y / 2 * -1) * POINT_SPACEING;
obj->vectors[offset_y][offset_x].r_loc.z = use_me_point->height;
obj->vectors[offset_y][offset_x].r_loc.color.g = 200;
offset_x++;
use_me_point = use_me_point->next;
}
use_me_line = use_me_line->next;
offset_y++;
}
}
void object_free(t_object_elem *obj)
{
int32_t offset_y;
offset_y = 0;
while (offset_y < obj->size_y)
{
ft_memdel((void**)&(obj->vectors[offset_y]));
offset_y++;
}
ft_memdel((void **)&(obj->vectors));
ft_memdel((void **)&obj);
}
t_object_elem *object_elem_from_input(t_input *input)
{
t_object_elem *to_return;
to_return = vector_array_alloc(input);
if (to_return == NULL)
return (NULL);
to_return->size_y = input->heightmap_size_y;
to_return->size_x = input->heightmap_size_x;
to_return->filename = input->filename;
move_input_to(input, to_return);
return (to_return);
}