From 03a19491f705b6519daecc3fe3191a222333fdbe Mon Sep 17 00:00:00 2001 From: Raphael Date: Tue, 12 Nov 2024 12:38:43 +0100 Subject: [PATCH] feat: starting to work on the raycast algorithm --- includes/raycast.h | 26 +++++++++++++++++++++++ raycast/rc_utils.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 includes/raycast.h create mode 100644 raycast/rc_utils.c diff --git a/includes/raycast.h b/includes/raycast.h new file mode 100644 index 0000000..2c8966f --- /dev/null +++ b/includes/raycast.h @@ -0,0 +1,26 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* raycast.h :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/12 12:27:30 by rparodi #+# #+# */ +/* Updated: 2024/11/12 12:29:51 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#ifndef RAYCAST_H +# define RAYCAST_H + +#include + +/** + * @brief Convert the degrees to radian + * + * @param degrees the value to convert + * @return the value converted in radian + */ +double cub_convert_rad_to_deg(double degrees); + +#endif diff --git a/raycast/rc_utils.c b/raycast/rc_utils.c new file mode 100644 index 0000000..ecec33a --- /dev/null +++ b/raycast/rc_utils.c @@ -0,0 +1,51 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* rc_utils.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: rparodi +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2024/11/12 12:24:35 by rparodi #+# #+# */ +/* Updated: 2024/11/12 12:38:14 by rparodi ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "cub3d.h" +#include "cub3d_struct.h" +#include "mlx_functions.h" +#include "raycast.h" + +double cub_convert_rad_to_deg(double degrees) +{ + return (degrees * (M_PI / 180.0)); +} + +void rc_launch(double angle) +{ + return ; +} + +/** + * @brief Launches algorithm over a specified width with angle adjustments. + * + * @param delta The initial angle offset for the ray. + * @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) +{ + int x; + double angle; + + x = 0; + angle = 0; + while (x < width) + { + angle = delta + atan((spacing / 2 - x * spacing / (width - 1)) / focal); + rc_launch(angle); + x++; + } +}