-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_map.c
121 lines (110 loc) · 3.21 KB
/
draw_map.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbaela <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/19 15:16:00 by lbaela #+# #+# */
/* Updated: 2021/10/27 14:07:18 by lbaela ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
void draw_horizontal_line(int x, int y, t_fdf *fdf)
{
t_point start;
t_point fin;
init_tpoint(&start,
(x - fdf->map_i.map_w / 2) * fdf->map_i.z_depth,
(y - fdf->map_i.map_h / 2) * fdf->map_i.z_depth,
fdf->map_i.map[y][x] * fdf->map_i.z_depth);
init_tpoint(&fin,
((x + 1) - fdf->map_i.map_w / 2) * fdf->map_i.z_depth,
(y - fdf->map_i.map_h / 2) * fdf->map_i.z_depth,
fdf->map_i.map[y][x + 1] * fdf->map_i.z_depth);
start.color = fdf->map_i.color[y][x];
fin.color = fdf->map_i.color[y][x + 1];
if (start.color == -1)
start.color = COL_VIOLET;
if (fin.color == -1)
fin.color = COL_VIOLET;
rotate_point(&start, fdf);
rotate_point(&fin, fdf);
map_points(&start, fdf);
map_points(&fin, fdf);
draw_line(fdf, &start, &fin);
}
void draw_vertical_line(int x, int y, t_fdf *fdf)
{
t_point start;
t_point fin;
init_tpoint(&start,
(x - fdf->map_i.map_w / 2) * fdf->map_i.z_depth,
(y - fdf->map_i.map_h / 2) * fdf->map_i.z_depth,
fdf->map_i.map[y][x] * fdf->map_i.z_depth);
init_tpoint(&fin,
(x - fdf->map_i.map_w / 2) * fdf->map_i.z_depth,
((y + 1) - fdf->map_i.map_h / 2) * fdf->map_i.z_depth,
fdf->map_i.map[y + 1][x] * fdf->map_i.z_depth);
start.color = fdf->map_i.color[y][x];
fin.color = fdf->map_i.color[y + 1][x];
rotate_point(&start, fdf);
rotate_point(&fin, fdf);
map_points(&start, fdf);
map_points(&fin, fdf);
draw_line(fdf, &start, &fin);
}
static void print_in_order(t_fdf *fdf)
{
int x;
int y;
y = 0;
while (y < fdf->map_i.map_h)
{
x = 0;
while (x < fdf->map_i.map_w)
{
if (x < (fdf->map_i.map_w - 1))
draw_horizontal_line(x, y, fdf);
if (y < (fdf->map_i.map_h - 1))
draw_vertical_line(x, y, fdf);
x++;
}
y++;
}
}
static void print_backwards(t_fdf *fdf)
{
int x;
int y;
y = fdf->map_i.map_h - 1;
while (y >= 0)
{
x = fdf->map_i.map_w - 1;
while (x >= 0)
{
if (x < (fdf->map_i.map_w - 1))
draw_horizontal_line(x, y, fdf);
if (y < (fdf->map_i.map_h - 1))
draw_vertical_line(x, y, fdf);
x--;
}
y--;
}
}
void draw_map(t_fdf *fdf)
{
t_point start;
t_point fin;
fill_background(fdf);
init_tpoint(&start, 0, 0, 0);
init_tpoint(&fin, 0, fdf->map_i.map_h - 1, 0);
rotate_point(&start, fdf);
rotate_point(&fin, fdf);
map_points(&start, fdf);
map_points(&fin, fdf);
if (start.y < fin.y)
print_in_order(fdf);
else
print_backwards(fdf);
}