-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_param.c
91 lines (80 loc) · 2.15 KB
/
ft_param.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_param.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anain <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/06/21 17:00:02 by anain #+# #+# */
/* Updated: 2017/06/22 17:01:45 by anain ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
t_env ft_a_init(t_env a, t_coord tab, t_point screen, int i)
{
int bpp;
int s_l;
int endian;
a.screen = screen;
a.tab = tab;
a.p = mlx_new_image(a.mlx, screen.x, screen.y);
a.image = mlx_get_data_addr(a.p, &(bpp), &(s_l), &(endian));
a.pos = i;
a.tile = ft_tile(a);
return (a);
}
t_point ft_screen(t_coord tab)
{
t_point screen;
screen.x = TILEWIDTH * (tab.c * 2 + tab.c / 2) + 2 * MARGIN;
if (screen.x > 2560)
screen.x = 2560;
screen.y = TILEWIDTH * tab.c + (tab.max - tab.min + tab.l) * TILEHEIGHT
* 2 + MARGIN * 2;
if (screen.y > 1440)
screen.y = 1440;
return (screen);
}
void ft_free_tab(t_coord *tab)
{
int j;
j = -1;
while (++j < tab->l)
free(tab->ftab[j]);
free(tab->ftab);
}
void ft_free_str(t_coord tab)
{
int j;
int i;
i = 0;
j = 0;
while (j < tab.l)
{
while (i < tab.c)
{
ft_strclr(tab.str[j][i]);
free(tab.str[j][i]);
i++;
}
free(tab.str[j]);
j++;
i = 0;
}
free(tab.str);
}
t_param ft_param(t_point f, t_point i, t_coord tab)
{
t_param param;
param.dx = abs(f.x - i.x);
param.dy = abs(f.y - i.y);
param.incx = (i.x < f.x) ? 1 : -1;
param.incy = (i.y < f.y) ? 1 : -1;
if (f.z == tab.max && i.z == tab.max)
param.tab = 1;
else if (f.z == tab.min)
param.tab = 2;
else
param.tab = 0;
return (param);
}