feat: calculate distance to first horizontal line

This commit is contained in:
Khaïs COLIN 2025-07-29 10:45:03 +02:00
parent 76fba8fd8a
commit d856a10ffc
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
2 changed files with 8 additions and 6 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* 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;

View file

@ -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;