fix: use t_cardinal_dir instead of an int to represent direction

This commit is contained in:
Khaïs COLIN 2025-08-05 12:40:53 +02:00
parent c4a867b054
commit f21e1e56fb
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo
4 changed files with 43 additions and 47 deletions

View file

@ -1,12 +1,12 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* render.c :+: :+: :+: */
/* walls.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */
/* Updated: 2025/07/31 13:38:07 by kcolin ### ########.fr */
/* Updated: 2025/08/05 12:49:26 by kcolin ### ########.fr */
/* */
/* ************************************************************************** */
@ -15,51 +15,44 @@
#include "ray.h"
#include "../renderer/render.h"
int get_cardinal(t_ray *ray)
t_cardinal_dir get_cardinal(t_ray *ray)
{
if (ray->side == 0)
if (ray->side == NORTH)
{
if (ray->dir_x < 0)
return (2);
return (WEST);
else
return (3);
return (EAST);
}
else
{
if (ray->dir_y > 0)
return (1);
return (SOUTH);
else
return (0);
return (NORTH);
}
}
static int get_color(int dir)
static int get_color(t_cardinal_dir dir)
{
int color;
if (dir == 0)
if (dir == NORTH)
color = 0x0000ff;
else if (dir == 1)
else if (dir == SOUTH)
color = 0x00ff00;
else if (dir == 2)
else if (dir == WEST)
color = 0xff0000;
else if (dir == 3)
else if (dir == EAST)
color = 0xffeb3b;
else
color = 0xff53ff;
return (color);
}
/*
* Dir values are:
* 0: North
* 1: South
* 2: West
* 3: East
*/
void render_walls(t_cub3d_data *data, t_ray *ray, int x)
{
int dir;
t_cardinal_dir dir;
int tex_x;
unsigned int color;
double step;
@ -67,8 +60,8 @@ void render_walls(t_cub3d_data *data, t_ray *ray, int x)
dir = get_cardinal(ray);
tex_x = (int)(ray->wall_x * TEXTURE_SIZE);
if ((ray->side == 0 && ray->dir_x < 0)
|| (ray->side == 1 && ray->dir_y > 0))
if ((ray->side == NORTH && ray->dir_x < 0)
|| (ray->side == SOUTH && ray->dir_y > 0))
tex_x = TEXTURE_SIZE - tex_x - 1;
step = 1.0 * TEXTURE_SIZE / ray->wall_height;
pos = (ray->draw_start - HEIGHT / 2 + ray->wall_height / 2) * step;