From 15de3cc8573195dac90c1b31e5114f5e22e8efa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 29 Jul 2025 10:26:52 +0200 Subject: [PATCH] feat: add utility function to convert coordinates from global to local space --- src/main.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main.c b/src/main.c index 44355a8..96b9c10 100644 --- a/src/main.c +++ b/src/main.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:14:30 by kcolin #+# #+# */ -/* Updated: 2025/07/28 15:21:17 by kcolin ### ########.fr */ +/* Updated: 2025/07/29 10:30:41 by kcolin ### ########.fr */ /* */ /* ************************************************************************** */ @@ -27,6 +27,7 @@ #include #include #include +#include // BAD void init_player(t_mapdata *mapdata, t_player *player) { @@ -102,6 +103,17 @@ t_intercardinal_dir player_intercardinal_dir(t_player player) return (angle_intercardinal_dir(player.yaw)); } +/* +** Converts a coordinate from global map space to local tile space. +** +** input coordinate is in the full map +** output coordinate is in the current tile +*/ +float coord_global_to_local(float coord) +{ + return (coord - floor(coord / SIZE) * SIZE); +} + int game_loop(t_cub3d_data *data) { mlx_destroy_image(data->mlx, data->img_data->img); @@ -125,6 +137,8 @@ int game_loop(t_cub3d_data *data) if (player_cardinal_dir(data->player) == WEST) ft_printf("west\n"); + 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 fraction = M_PI / 3 / WIDTH; int column = 0;