2025-07-30 16:25:12 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
2025-08-05 12:40:53 +02:00
|
|
|
/* walls.c :+: :+: :+: */
|
2025-07-30 16:25:12 +02:00
|
|
|
/* +:+ +:+ +:+ */
|
2025-07-31 13:17:27 +02:00
|
|
|
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
|
2025-07-30 16:25:12 +02:00
|
|
|
/* +#+#+#+#+#+ +#+ */
|
2025-07-31 13:17:27 +02:00
|
|
|
/* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */
|
2025-08-05 12:40:53 +02:00
|
|
|
/* Updated: 2025/08/05 12:49:26 by kcolin ### ########.fr */
|
2025-07-30 16:25:12 +02:00
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
|
|
#include "../cub3d_data.h"
|
|
|
|
|
#include "../consts.h"
|
|
|
|
|
#include "ray.h"
|
2025-07-31 13:17:27 +02:00
|
|
|
#include "../renderer/render.h"
|
2025-07-30 16:25:12 +02:00
|
|
|
|
2025-08-05 12:40:53 +02:00
|
|
|
t_cardinal_dir get_cardinal(t_ray *ray)
|
2025-07-30 16:25:12 +02:00
|
|
|
{
|
2025-08-05 12:40:53 +02:00
|
|
|
if (ray->side == NORTH)
|
2025-07-30 16:25:12 +02:00
|
|
|
{
|
|
|
|
|
if (ray->dir_x < 0)
|
2025-08-05 12:40:53 +02:00
|
|
|
return (WEST);
|
2025-07-30 16:25:12 +02:00
|
|
|
else
|
2025-08-05 12:40:53 +02:00
|
|
|
return (EAST);
|
2025-07-30 16:25:12 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ray->dir_y > 0)
|
2025-08-05 12:40:53 +02:00
|
|
|
return (SOUTH);
|
2025-07-30 16:25:12 +02:00
|
|
|
else
|
2025-08-05 12:40:53 +02:00
|
|
|
return (NORTH);
|
2025-07-30 16:25:12 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-05 12:40:53 +02:00
|
|
|
static int get_color(t_cardinal_dir dir)
|
2025-07-31 11:24:23 +02:00
|
|
|
{
|
|
|
|
|
int color;
|
|
|
|
|
|
2025-08-05 12:40:53 +02:00
|
|
|
if (dir == NORTH)
|
2025-07-31 11:24:23 +02:00
|
|
|
color = 0x0000ff;
|
2025-08-05 12:40:53 +02:00
|
|
|
else if (dir == SOUTH)
|
2025-07-31 11:24:23 +02:00
|
|
|
color = 0x00ff00;
|
2025-08-05 12:40:53 +02:00
|
|
|
else if (dir == WEST)
|
2025-07-31 11:24:23 +02:00
|
|
|
color = 0xff0000;
|
2025-08-05 12:40:53 +02:00
|
|
|
else if (dir == EAST)
|
2025-07-31 11:24:23 +02:00
|
|
|
color = 0xffeb3b;
|
|
|
|
|
else
|
|
|
|
|
color = 0xff53ff;
|
|
|
|
|
return (color);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 16:25:12 +02:00
|
|
|
void render_walls(t_cub3d_data *data, t_ray *ray, int x)
|
|
|
|
|
{
|
2025-08-05 12:40:53 +02:00
|
|
|
t_cardinal_dir dir;
|
2025-07-30 16:25:12 +02:00
|
|
|
int tex_x;
|
|
|
|
|
unsigned int color;
|
|
|
|
|
double step;
|
|
|
|
|
double pos;
|
|
|
|
|
|
|
|
|
|
dir = get_cardinal(ray);
|
2025-07-30 16:40:33 +02:00
|
|
|
tex_x = (int)(ray->wall_x * TEXTURE_SIZE);
|
2025-08-05 12:40:53 +02:00
|
|
|
if ((ray->side == NORTH && ray->dir_x < 0)
|
|
|
|
|
|| (ray->side == SOUTH && ray->dir_y > 0))
|
2025-07-30 16:40:33 +02:00
|
|
|
tex_x = TEXTURE_SIZE - tex_x - 1;
|
|
|
|
|
step = 1.0 * TEXTURE_SIZE / ray->wall_height;
|
2025-07-30 16:25:12 +02:00
|
|
|
pos = (ray->draw_start - HEIGHT / 2 + ray->wall_height / 2) * step;
|
|
|
|
|
while (ray->draw_start < ray->draw_end)
|
|
|
|
|
{
|
|
|
|
|
pos += step;
|
2025-07-31 11:24:23 +02:00
|
|
|
color = get_color(dir);
|
2025-07-30 16:40:33 +02:00
|
|
|
(void)pos;
|
2025-07-31 13:17:27 +02:00
|
|
|
matrix_set(data, x, ray->draw_start, color);
|
2025-07-30 16:25:12 +02:00
|
|
|
ray->draw_start++;
|
|
|
|
|
}
|
|
|
|
|
}
|