From 853fb39c84cb90d3fe325b919ca81c990f62443f Mon Sep 17 00:00:00 2001 From: hugogogo Date: Sun, 1 May 2022 09:49:41 +0200 Subject: [PATCH] changed all equations of wall height calculation to resolve pixelisation, but dead axis rays re-appeared --- headers/cube3d_struct.h | 1 - maps/map_valid_14.cub | 4 ++-- srcs/draw/raycast.c | 34 ++++++++++------------------------ 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/headers/cube3d_struct.h b/headers/cube3d_struct.h index 83502cf..170d745 100644 --- a/headers/cube3d_struct.h +++ b/headers/cube3d_struct.h @@ -55,7 +55,6 @@ typedef struct s_rcast int ray_step_y; int is_x; int ray_nb; - int ray_len; double ratio; } t_rcast; diff --git a/maps/map_valid_14.cub b/maps/map_valid_14.cub index b3cb4e8..c9c222b 100644 --- a/maps/map_valid_14.cub +++ b/maps/map_valid_14.cub @@ -8,10 +8,10 @@ F 220 , 100, 30 C 225 , 30 , 0 1111111111111111111111111111 -1N00000000000000011100000001 +1000000000000000011100000001 1111000000000000100000110001 1111001000000000000110000111 -1000000000000000010101000001 +100000000N000000010101000001 1111110000000000000000001111 1000000000000000000000000001 1000000000000000000000000001 diff --git a/srcs/draw/raycast.c b/srcs/draw/raycast.c index 0b84b90..50ffa74 100644 --- a/srcs/draw/raycast.c +++ b/srcs/draw/raycast.c @@ -30,36 +30,23 @@ } // tmp end -static void wall_length(t_rcast *rcast) +static void wall_height(t_rcast *rcast) { - int len; + int height; + int delta; rcast->wall.start.x = rcast->ray_nb; rcast->wall.end.x = rcast->ray_nb; if (rcast->is_x == 1) - { - len = rcast->next_x - rcast->ray_step_x; - if (rcast->slope_y) - len /= rcast->slope_y; - len = rcast->screen_dist * len / rcast->slope_x; - } + delta = rcast->next_x - rcast->ray_step_x; else if (rcast->is_x == 0) - { - len = rcast->next_y - rcast->ray_step_y; - if (rcast->slope_x) - len /= rcast->slope_x; - len = rcast->screen_dist * len / rcast->slope_y; - } - rcast->ray_len = ft_abs(len); -} - -static void wall_height(t_rcast *rcast) -{ - int height; - + delta = rcast->next_y - rcast->ray_step_y; height = rcast->screen_height * rcast->cell; - if (rcast->ray_len) - height /= rcast->ray_len; + height *= rcast->slope_y * rcast->slope_x; + if (delta && rcast->screen_dist) + height /= (delta * rcast->screen_dist); + + height = ft_abs(height); if (height < 0) height = 0; if (height > rcast->screen_height) @@ -107,7 +94,6 @@ void raycast(t_game *game, t_rcast *rcast) draw_line(&game->map_img, &ray, 0x00FF00FF); // tmp end - wall_length(rcast); wall_height(rcast); draw_column(game, rcast); (rcast->ray_nb)++;