-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_map.c
78 lines (72 loc) · 2.14 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_map.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mmoumni <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/12/22 11:21:35 by mmoumni #+# #+# */
/* Updated: 2022/01/04 16:56:23 by mmoumni ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
t_point *projection(t_point *p, t_fdf *fdf)
{
p->x *= fdf->zoom;
p->y *= fdf->zoom;
x_rotation(&p->x, &p->y, &p->z, fdf->alpha);
y_rotation(&p->x, &p->y, &p->z, fdf->beta);
z_rotation(&p->x, &p->y, &p->z, fdf->teta);
if (fdf->project == 1)
iso(&p->x, &p->y, p->z, fdf->def_ang);
p->x += fdf->x_pos;
p->y += fdf->y_pos;
return (p);
}
void set_xpixel(t_fdf *fdf, int x, int y)
{
if (fdf->matrix[y][x].z.color == -1)
{
if (fdf->matrix[y][x].z.altitude != 0)
fdf->color = 0xff0000;
else
fdf->color = 0xffffff;
}
else
fdf->color = fdf->matrix[y][x].z.color;
bresnham(fdf, projection(point_init(x, y, fdf), fdf) \
, projection(point_init(x + 1, y, fdf), fdf));
}
void set_ypixel(t_fdf *fdf, int x, int y)
{
if (fdf->matrix[y][x].z.color == -1)
{
if (fdf->matrix[y][x].z.altitude != 0)
fdf->color = 0xff0000;
else
fdf->color = 0xffffff;
}
else
fdf->color = fdf->matrix[y][x].z.color;
bresnham(fdf, projection(point_init(x, y, fdf), fdf) \
, projection(point_init(x, y + 1, fdf), fdf));
}
void ft_draw(t_fdf *fdf)
{
int x;
int y;
y = 0;
while (y < fdf->height)
{
x = 0;
while (x < fdf->width)
{
if (x < fdf->width - 1)
set_xpixel(fdf, x, y);
if (y < fdf->height - 1)
set_ypixel(fdf, x, y);
x++;
}
y++;
}
}