adding the correction helped by maiboyer and bgoulard

This commit is contained in:
Raphael 2024-11-18 16:27:02 +01:00
commit 761178fcae
6 changed files with 249 additions and 13 deletions

View file

@ -6,7 +6,7 @@
/* By: rparodi <rparodi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 12:24:35 by rparodi #+# #+# */
/* Updated: 2024/11/12 15:08:08 by rparodi ### ########.fr */
/* Updated: 2024/11/18 15:41:34 by rparodi ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,11 +15,29 @@
#include "mlx_functions.h"
#include "raycast.h"
double cub_convert_rad_to_deg(double degrees)
/**
* @brief convert a angle in degrees to radian
*
* @param degrees the angle in degrees
* @return the angle in radian
*/
double cub_convert_deg_to_rad(double degrees)
{
return (degrees * (M_PI / 180.0));
}
/**
* @brief Launches a ray for raycasting to determine the distance to the first wall.
*
* This function calculates the distance of a ray cast in a specified angle
* until it either hits a wall or reaches the maximum range.
*
* @param info A pointer to the `t_info` structure containing the map and other relevant data.
* @param angle The angle of the ray being cast, in radians.
*
* @return The distance from the starting position to the first wall hit.
* If no wall is hit within `MAX_RANGE`, the function returns `MAX_RANGE`.
*/
double rc_launch(t_info *info, double angle)
{
double distance;
@ -33,11 +51,11 @@ double rc_launch(t_info *info, double angle)
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)
rayon.x = direction.x * distance;
rayon.y = direction.y * distance;
if (info->map.map[info->map.fraw[(int)rayon.x][(int)rayon.y]] == WALL)
return (distance);
distance += STEP_SIZE;
}
return (MAX_RANGE);
}
@ -61,7 +79,8 @@ void shelves_launch(t_info *info, double spacing, double focal, int width)
angle = 0;
while (x < width)
{
angle = info->player.view + atan((spacing / 2 - x * spacing / (width - 1)) / focal);
angle = info->player.view + atan(\
(spacing / 2 - x * spacing / (width - 1)) / focal);
rc_launch(info, angle);
x++;
}