mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 01:48:08 +01:00
feat: calculate distance to first horizontal line
This commit is contained in:
parent
76fba8fd8a
commit
d856a10ffc
2 changed files with 8 additions and 6 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/17 14:54:36 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 WIDTH 800
|
||||||
|
|
||||||
# define SIZE 64
|
# define SIZE 64
|
||||||
# define MAP_SIZE 10
|
# define MAP_SIZE 20
|
||||||
|
|
||||||
extern const float g_north;
|
extern const float g_north;
|
||||||
extern const float g_south;
|
extern const float g_south;
|
||||||
|
|
|
||||||
10
src/main.c
10
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));
|
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;
|
float fraction = M_PI / 3 / WIDTH;
|
||||||
int column = 0;
|
int column = 0;
|
||||||
while (column < WIDTH)
|
while (column < 1)
|
||||||
{
|
{
|
||||||
// hline check
|
float first_hline_distance = coord_global_to_local(data->player.y) / cos(ray_angle);
|
||||||
/* float ray_atan = atan(ray_angle); */
|
printf("first hline distance: %f\n", first_hline_distance);
|
||||||
draw_line(data, ray_angle);
|
draw_line(data, ray_angle);
|
||||||
column++;
|
column++;
|
||||||
ray_angle += fraction;
|
ray_angle += fraction;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue