-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_player.c
97 lines (90 loc) · 2.68 KB
/
print_player.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_player.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kkalinic <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/04 17:43:37 by kkalinic #+# #+# */
/* Updated: 2021/05/04 17:47:03 by kkalinic ### ########.fr */
/* */
/* ************************************************************************** */
#include "headers/cub_head.h"
static void ft_draw_right_line(t_data *mlx_s, double delta, t_line vector)
{
if (vector.y == vector.dy)
delta = 0;
while (vector.x++ <= vector.dx)
{
while (vector.y != vector.dy)
{
vector.y += delta;
break ;
}
my_mlx_pixel_put(mlx_s, vector.x, vector.y, mlx_s->map_s->color);
}
}
static void ft_draw_left_line(t_data *mlx_s, double delta, t_line vector)
{
if (vector.y == vector.dy)
delta = 0;
while (vector.x-- >= vector.dx)
{
while (vector.y != vector.dy)
{
vector.y -= delta;
break ;
}
my_mlx_pixel_put(mlx_s, vector.x, vector.y, mlx_s->map_s->color);
}
}
static void ft_draw_down_line(t_data *mlx_s, double delta, t_line vector)
{
my_mlx_pixel_put(mlx_s, vector.x, vector.y, mlx_s->map_s->color);
if (vector.x == vector.dx)
delta = 0;
while (vector.y-- >= vector.dy)
{
while (vector.x != vector.dx)
{
vector.x -= delta;
break ;
}
my_mlx_pixel_put(mlx_s, vector.x, vector.y, mlx_s->map_s->color);
}
}
static void ft_draw_up_line(t_data *mlx_s, double delta, t_line vector)
{
if (vector.x == vector.dx)
delta = 0;
while (vector.y++ <= vector.dy)
{
while (vector.x != vector.dx)
{
vector.x += delta;
break ;
}
my_mlx_pixel_put(mlx_s, vector.x, vector.y, mlx_s->map_s->color);
}
}
void print_v(t_data *mlx_s, t_line vector)
{
double delta;
delta = fabs(vector.y - vector.dy) - fabs(vector.x - vector.dx);
if (delta > 0)
{
delta = (vector.x - vector.dx) / (vector.y - vector.dy);
if (vector.y < vector.dy)
ft_draw_up_line(mlx_s, delta, vector);
else
ft_draw_down_line(mlx_s, delta, vector);
}
else
{
delta = (vector.y - vector.dy) / (vector.x - vector.dx);
if (vector.x < vector.dx)
ft_draw_right_line(mlx_s, delta, vector);
else if (vector.x >= vector.dx)
ft_draw_left_line(mlx_s, delta, vector);
}
}