2025-07-30 16:25:12 +02:00
|
|
|
/* ************************************************************************** */
|
|
|
|
|
/* */
|
|
|
|
|
/* ::: :::::::: */
|
|
|
|
|
/* render.c :+: :+: :+: */
|
|
|
|
|
/* +:+ +:+ +:+ */
|
|
|
|
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
|
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
|
|
/* Created: 2025/07/30 12:50:10 by tchampio #+# #+# */
|
2025-07-30 16:40:33 +02:00
|
|
|
/* Updated: 2025/07/30 16:38:59 by tchampio ### ########.fr */
|
2025-07-30 16:25:12 +02:00
|
|
|
/* */
|
|
|
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
|
|
#include "../cub3d_data.h"
|
|
|
|
|
#include "../consts.h"
|
|
|
|
|
#include "ray.h"
|
|
|
|
|
|
|
|
|
|
int get_cardinal(t_ray *ray)
|
|
|
|
|
{
|
|
|
|
|
if (ray->side == 0)
|
|
|
|
|
{
|
|
|
|
|
if (ray->dir_x < 0)
|
|
|
|
|
return (2);
|
|
|
|
|
else
|
|
|
|
|
return (3);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (ray->dir_y > 0)
|
|
|
|
|
return (1);
|
|
|
|
|
else
|
|
|
|
|
return (0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* 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;
|
|
|
|
|
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);
|
|
|
|
|
if ((ray->side == 0 && ray->dir_x < 0)
|
|
|
|
|
|| (ray->side == 1 && ray->dir_y > 0))
|
|
|
|
|
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;
|
|
|
|
|
color = 0x0000ff;
|
2025-07-30 16:40:33 +02:00
|
|
|
(void)dir;
|
|
|
|
|
(void)pos;
|
2025-07-30 16:25:12 +02:00
|
|
|
data->screen_matrix[ray->draw_start][x] = color;
|
|
|
|
|
ray->draw_start++;
|
|
|
|
|
}
|
|
|
|
|
}
|