From bd5ed03b27918a517671012eb3161b8db23286a9 Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 12 Nov 2024 15:09:27 +0100 Subject: [PATCH] feat: adding the raycasting launch ray --- includes/cub3d_struct.h | 3 +-- includes/raycast.h | 7 +++++-- raycast/rc_utils.c | 31 ++++++++++++++++++++++++------- 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/includes/cub3d_struct.h b/includes/cub3d_struct.h index ad3cda3..0e4e659 100644 --- a/includes/cub3d_struct.h +++ b/includes/cub3d_struct.h @@ -6,7 +6,7 @@ /* By: bgoulard +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/08 23:55:29 by bgoulard #+# #+# */ -/* Updated: 2024/11/12 11:05:49 by bgoulard ### ########.fr */ +/* Updated: 2024/11/12 15:03:39 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -109,7 +109,6 @@ typedef enum e_error typedef struct s_info { t_error last_error; - t_xvar *mlx_ptr; t_win_list *win_ptr; t_map map; diff --git a/includes/raycast.h b/includes/raycast.h index 2c8966f..195e413 100644 --- a/includes/raycast.h +++ b/includes/raycast.h @@ -6,14 +6,17 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/12 12:27:30 by rparodi #+# #+# */ -/* Updated: 2024/11/12 12:29:51 by rparodi ### ########.fr */ +/* Updated: 2024/11/12 15:04:37 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ #ifndef RAYCAST_H # define RAYCAST_H -#include +# include + +# define MAX_RANGE 100.0 +# define STEP_SIZE 0.1 /** * @brief Convert the degrees to radian diff --git a/raycast/rc_utils.c b/raycast/rc_utils.c index ecec33a..11386d0 100644 --- a/raycast/rc_utils.c +++ b/raycast/rc_utils.c @@ -6,7 +6,7 @@ /* By: rparodi +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/11/12 12:24:35 by rparodi #+# #+# */ -/* Updated: 2024/11/12 12:38:14 by rparodi ### ########.fr */ +/* Updated: 2024/11/12 15:08:08 by rparodi ### ########.fr */ /* */ /* ************************************************************************** */ @@ -20,22 +20,39 @@ double cub_convert_rad_to_deg(double degrees) return (degrees * (M_PI / 180.0)); } -void rc_launch(double angle) +double rc_launch(t_info *info, double angle) { - return ; + double distance; + t_dpoint direction; + t_dpoint rayon; + + distance = 0; + direction.x = 0; + direction.y = 0; + rayon.x = 0; + rayon.y = 0; + while (distance < MAX_RANGE) + { + rayon.x += direction.x * STEP_SIZE; + rayon.y += direction.y * STEP_SIZE; + distance += STEP_SIZE; + if (info->map.map(info->map.fraw[(int)rayon.x][(int)rayon.y]) == WALL) + return (distance); + } + return (MAX_RANGE); } /** * @brief Launches algorithm over a specified width with angle adjustments. * - * @param delta The initial angle offset for the ray. + * @param info The structure of the game (for the view) * @param spacing The spacing between rays. * @param focal The focal length affecting the angle adjustment. * @param width The total width (number of columns) to iterate over. * * @note The function assumes `rc_launch` is defined elsewhere to handle the angle. */ -void shelves_launch(double delta, double spacing, double focal, int width) +void shelves_launch(t_info *info, double spacing, double focal, int width) { int x; double angle; @@ -44,8 +61,8 @@ void shelves_launch(double delta, double spacing, double focal, int width) angle = 0; while (x < width) { - angle = delta + atan((spacing / 2 - x * spacing / (width - 1)) / focal); - rc_launch(angle); + angle = info->player.view + atan((spacing / 2 - x * spacing / (width - 1)) / focal); + rc_launch(info, angle); x++; } }