diff --git a/srcs/draw/ray_intersect.c b/srcs/draw/ray_intersect.c index ed7d409..3896445 100644 --- a/srcs/draw/ray_intersect.c +++ b/srcs/draw/ray_intersect.c @@ -60,6 +60,7 @@ static void next_cell(t_rcast *rcast) static void calcul_ray_end(t_rcast *rcast, t_vec *ray) { + /* if (rcast->is_x) { ray->end.x = rcast->cell_x * rcast->cell; @@ -82,6 +83,43 @@ static void calcul_ray_end(t_rcast *rcast, t_vec *ray) ray->end.x = ray->start.x + (double)rcast->slope_x * rcast->ratio; } } + */ + int *nd1; + int *cell1; + int *sign1; + int *st1; + int *slp1; + int *nd2; + int *st2; + int *slp2; + + if (rcast->is_x) + { + nd1 = &(ray->end.x); + cell1 = &(rcast->cell_x); + sign1 = &(rcast->ray_sign_x); + st1 = &(ray->start.x); + slp1 = &(rcast->slope_x); + nd2 = &(ray->end.y); + st2 = &(ray->start.y); + slp2 = &(rcast->slope_y); + } + else + { + nd1 = &(ray->end.y); + cell1 = &(rcast->cell_y); + sign1 = &(rcast->ray_sign_y); + st1 = &(ray->start.y); + slp1 = &(rcast->slope_y); + nd2 = &(ray->end.x); + st2 = &(ray->start.x); + slp2 = &(rcast->slope_x); + } + *nd1 = *cell1 * rcast->cell; + if (*sign1 == 1) + *nd1 += rcast->cell; + if (*slp1) + *nd2 = *st2 + (double)(*slp2) * (double)(*nd1 - *st1) / (double)(*slp1); } void ray_intersect(t_game *game, t_rcast *rcast, t_vec *ray)