img_put_line.c
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* img_put_line.c :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: ll-hotel <ll-hotel@student.42.fr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2024/09/08 20:33:50 by ll-hotel #+# #+# */ 9 /* Updated: 2024/09/08 20:33:52 by ll-hotel ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include "cub3D.h" 14 #include "ft_basics.h" 15 #include "img_put_pixel.h" 16 #include <math.h> 17 18 void img_put_line(t_img *img, t_point p1, t_point p2, const int colour) 19 { 20 const t_vec2f d = (t_vec2f){p2.x - p1.x, p2.y - p1.y}; 21 t_vec2f slope; 22 int steps; 23 float x; 24 float y; 25 26 x = p1.x; 27 y = p1.y; 28 steps = roundf(ft_maxf(ft_absf(d.x), ft_absf(d.y))); 29 slope = (t_vec2f){d.x / steps, d.y / steps}; 30 img_put_pixel(img, y, x, colour); 31 while (steps-- > 0) 32 { 33 x += slope.x; 34 y += slope.y; 35 img_put_pixel(img, roundf(y), roundf(x), colour); 36 } 37 }