mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
fix: prevent zero-division in rare cases
This commit is contained in:
parent
6fe6eb0a9a
commit
ca5fa86d10
1 changed files with 6 additions and 3 deletions
|
|
@ -3,10 +3,10 @@
|
||||||
/* ::: :::::::: */
|
/* ::: :::::::: */
|
||||||
/* ray.c :+: :+: :+: */
|
/* ray.c :+: :+: :+: */
|
||||||
/* +:+ +:+ +:+ */
|
/* +:+ +:+ +:+ */
|
||||||
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/07/30 12:10:17 by tchampio #+# #+# */
|
/* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */
|
||||||
/* Updated: 2025/07/30 16:06:19 by tchampio ### ########.fr */
|
/* Updated: 2025/07/31 11:58:02 by kcolin ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#include "../player/player.h"
|
#include "../player/player.h"
|
||||||
#include "../consts.h"
|
#include "../consts.h"
|
||||||
#include "../cub3d_data.h"
|
#include "../cub3d_data.h"
|
||||||
|
#include <float.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
void init_ray(t_ray *ray, int pos_x, t_player *player)
|
void init_ray(t_ray *ray, int pos_x, t_player *player)
|
||||||
|
|
@ -79,6 +80,8 @@ void calculate_wall_dist(t_ray *ray, char **map)
|
||||||
|
|
||||||
void calculate_wall_height(t_ray *ray, t_player *player)
|
void calculate_wall_height(t_ray *ray, t_player *player)
|
||||||
{
|
{
|
||||||
|
if (ray->wall_dist <= FLT_EPSILON)
|
||||||
|
ray->wall_dist = 0.1;
|
||||||
ray->wall_height = (int)(HEIGHT / ray->wall_dist);
|
ray->wall_height = (int)(HEIGHT / ray->wall_dist);
|
||||||
ray->draw_start = -ray->wall_height / 2 + HEIGHT / 2;
|
ray->draw_start = -ray->wall_height / 2 + HEIGHT / 2;
|
||||||
if (ray->draw_start < 0)
|
if (ray->draw_start < 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue