From d91a3ef90ba3975b7c3bd47b69ce7febda2a77a7 Mon Sep 17 00:00:00 2001 From: Rudy Bousset Date: Thu, 13 Feb 2020 18:30:37 +0100 Subject: Smooth --- src/ft_detect.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/ft_detect.c (limited to 'src/ft_detect.c') diff --git a/src/ft_detect.c b/src/ft_detect.c new file mode 100644 index 0000000..b83c9f1 --- /dev/null +++ b/src/ft_detect.c @@ -0,0 +1,67 @@ +#include +#include + +static void +ft_detection_init_y(t_cub *cl) +{ + cl->rlist.y_delta_dist = sqrt(1 + (cl->rlist.x_ray_dir * + cl->rlist.x_ray_dir) / (cl->rlist.y_ray_dir * + cl->rlist.y_ray_dir)); + if (cl->rlist.y_ray_dir < 0) + { + cl->y_step = -1; + cl->rlist.y_side_dist = (cl->rlist.y_ray_pos - + cl->rlist.sqy) * cl->rlist.y_delta_dist; + } + else + { + cl->y_step = 1; + cl->rlist.y_side_dist = (cl->rlist.sqy + 1.0 - + cl->rlist.y_ray_pos) * cl->rlist.y_delta_dist; + } +} + +static void +ft_detection_init_x(t_cub *cl) +{ + cl->rlist.x_delta_dist = sqrt(1 + (cl->rlist.y_ray_dir * + cl->rlist.y_ray_dir) / (cl->rlist.x_ray_dir * + cl->rlist.x_ray_dir)); + if (cl->rlist.x_ray_dir < 0) + { + cl->x_step = -1; + cl->rlist.x_side_dist = (cl->rlist.x_ray_pos - + cl->rlist.sqx) * cl->rlist.x_delta_dist; + } + else + { + cl->x_step = 1; + cl->rlist.x_side_dist = (cl->rlist.sqx + 1.0 - + cl->rlist.x_ray_pos) * cl->rlist.x_delta_dist; + } + ft_detection_init_y(cl); +} + +void +ft_detect(t_cub *cl) +{ + ft_detection_init_x(cl); + cl->rlist.hit = 0; + while (cl->rlist.hit == 0) + { + if (cl->rlist.x_side_dist < cl->rlist.y_side_dist) + { + cl->rlist.x_side_dist += cl->rlist.x_delta_dist; + cl->rlist.sqx += cl->x_step; + cl->rlist.side = 0; + } + else + { + cl->rlist.y_side_dist += cl->rlist.y_delta_dist; + cl->rlist.sqy += cl->y_step; + cl->rlist.side = 1; + } + if (cl->map[cl->rlist.sqx][cl->rlist.sqy] == '1') + cl->rlist.hit = 1; + } +} -- cgit v1.2.3