mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
feat: add utility function to convert coordinates from global to local space
This commit is contained in:
parent
b53fa93377
commit
15de3cc857
1 changed files with 15 additions and 1 deletions
16
src/main.c
16
src/main.c
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:14:30 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 <unistd.h>
|
#include <unistd.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdio.h> // BAD
|
||||||
|
|
||||||
void init_player(t_mapdata *mapdata, t_player *player)
|
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));
|
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)
|
int game_loop(t_cub3d_data *data)
|
||||||
{
|
{
|
||||||
mlx_destroy_image(data->mlx, data->img_data->img);
|
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)
|
if (player_cardinal_dir(data->player) == WEST)
|
||||||
ft_printf("west\n");
|
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 ray_angle = data->player.yaw - M_PI / 6;
|
||||||
float fraction = M_PI / 3 / WIDTH;
|
float fraction = M_PI / 3 / WIDTH;
|
||||||
int column = 0;
|
int column = 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue