-
Notifications
You must be signed in to change notification settings - Fork 0
/
tools.c
51 lines (46 loc) · 1.58 KB
/
tools.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* tools.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ahajji <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/03 11:52:59 by ahajji #+# #+# */
/* Updated: 2023/11/04 14:21:42 by ahajji ### ########.fr */
/* */
/* ************************************************************************** */
#include "cub3d.h"
float to_rad(float degree)
{
return (degree * (M_PI / 180));
}
void draw_line_dda(t_cub3d *data, float x2, float y2, uint32_t color)
{
float dx;
float dy;
float x1;
float y1;
int i;
i = 0;
x1 = data->px;
y1 = data->py;
dx = x2 - x1;
dy = y2 - y1;
if (fabs(dx) > fabs(dy))
data->steps = fabs(dx);
else
data->steps = fabs(dy);
data->increamentx = dx / data->steps;
data->increamenty = dy / data->steps;
while (i <= data->steps)
{
mlx_put_pixel(data->img_map, round(x1), round(y1), color);
x1 += data->increamentx;
y1 += data->increamenty;
i++;
}
}
float distance_between_points(float x1, float y1, float x2, float y2)
{
return (sqrt(pow((x2 - x1), 2) + pow((y1 - y2), 2)));
}