From d856a10ffccd40d9499aef038138357562e4b557 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 29 Jul 2025 10:45:03 +0200 Subject: [PATCH] feat: calculate distance to first horizontal line --- src/consts.h | 4 ++-- src/main.c | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/consts.h b/src/consts.h index 329e3f9..c1a9a3c 100644 --- a/src/consts.h +++ b/src/consts.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:54:36 by kcolin #+# #+# */ -/* Updated: 2025/07/28 15:03:19 by kcolin ### ########.fr */ +/* Updated: 2025/07/29 11:42:20 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -17,7 +17,7 @@ # define WIDTH 800 # define SIZE 64 -# define MAP_SIZE 10 +# define MAP_SIZE 20 extern const float g_north; extern const float g_south; diff --git a/src/main.c b/src/main.c index 0e97ca7..3343554 100644 --- a/src/main.c +++ b/src/main.c @@ -139,13 +139,15 @@ int game_loop(t_cub3d_data *data) printf("local coord: %f, %f\n", coord_global_to_local(data->player.x), coord_global_to_local(data->player.y)); - float ray_angle = data->player.yaw - M_PI / 6; + + /* float ray_angle = data->player.yaw - M_PI / 6; // 30 deg clockwise from player */ + float ray_angle = data->player.yaw; // straight ahead float fraction = M_PI / 3 / WIDTH; int column = 0; - while (column < WIDTH) + while (column < 1) { - // hline check - /* float ray_atan = atan(ray_angle); */ + float first_hline_distance = coord_global_to_local(data->player.y) / cos(ray_angle); + printf("first hline distance: %f\n", first_hline_distance); draw_line(data, ray_angle); column++; ray_angle += fraction;