Cub3D
Loading...
Searching...
No Matches
init_line.c
1/* ************************************************************************** */
2/* */
3/* ::: :::::::: */
4/* init_line.c :+: :+: :+: */
5/* +:+ +:+ +:+ */
6/* By: kamitsui <kamitsui@student.42tokyo.jp> +#+ +:+ +#+ */
7/* +#+#+#+#+#+ +#+ */
8/* Created: 2024/09/13 10:31:14 by kamitsui #+# #+# */
9/* Updated: 2024/09/13 10:36:23 by kamitsui ### ########.fr */
10/* */
11/* ************************************************************************** */
12
13#include "cub3d.h"
14
15void init_color(t_clr *color, int start_color, int end_color)
16{
17 color->start_r = (start_color >> 16) & 0xFF;
18 color->start_g = (start_color >> 8) & 0xFF;
19 color->start_b = start_color & 0xFF;
20 color->end_r = (end_color >> 16) & 0xFF;
21 color->end_g = (end_color >> 8) & 0xFF;
22 color->end_b = end_color & 0xFF;
23}
24
25static int less_than(int a, int b)
26{
27 if (a < b)
28 return (1);
29 else
30 return (-1);
31}
32
33void init_plot(t_plot *plot, t_line *line)
34{
35 plot->px = line->x_start;
36 plot->py = line->y_start;
37 plot->dx = ft_abs(line->x_end - line->x_start);
38 plot->dy = ft_abs(line->y_end - line->y_start);
39 plot->sx = less_than(line->x_start, line->x_end);
40 plot->sy = less_than(line->y_start, line->y_end);
41 plot->err = plot->dx - plot->dy;
42}