feat: add utility function to convert coordinates from global to local space

This commit is contained in:
Khaïs COLIN 2025-07-29 10:26:52 +02:00
parent b53fa93377
commit 15de3cc857
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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 <unistd.h>
#include <fcntl.h>
#include <math.h>
#include <stdio.h> // 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;