-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw_map_utils.c
76 lines (68 loc) · 1.92 KB
/
draw_map_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* draw_map_utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbaela <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/26 14:10:29 by lbaela #+# #+# */
/* Updated: 2021/10/27 14:03:14 by lbaela ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
static int offscreen(int x, int y)
{
if (x <= 0 || x >= WIN_WIDTH)
return (1);
if (y <= 0 || y >= WIN_HEIGHT)
return (1);
return (0);
}
void my_mlx_pixel_put(t_fdf *fdf, int x, int y, int color)
{
char *dst;
if (offscreen(x, y))
return ;
dst = fdf->addr + (y * fdf->line_length + x * (fdf->bits_per_pixel / 8));
*(unsigned int *)dst = color;
}
void map_points(t_point *this, t_fdf *fdf)
{
double x_upd;
double y_upd;
t_point tmp;
init_tpoint(&tmp, this->x, this->y, this->z);
if (fdf->camera.iso == 1)
{
x_upd = (tmp.x - tmp.y) * cos(RAD_ANGLE);
y_upd = -(tmp.z) + (tmp.x + tmp.y) * sin(RAD_ANGLE);
}
else if (fdf->camera.iso == 2)
{
x_upd = tmp.x;
y_upd = tmp.y;
}
else
{
x_upd = tmp.x;
y_upd = -(tmp.z);
}
this->x = (int)round(x_upd) + fdf->camera.x_offset;
this->y = (int)round(y_upd) + fdf->camera.y_offset;
}
void fill_background(t_fdf *fdf)
{
int x;
int y;
y = 0;
while (y < WIN_HEIGHT)
{
x = 0;
while (x < WIN_WIDTH)
{
my_mlx_pixel_put(fdf, x, y, COL_BLACK);
x++;
}
y++;
}
}