mirror of
https://codeberg.org/ACME-Corporation/cub3d.git
synced 2025-12-06 09:58:09 +01:00
68 lines
1.9 KiB
C
68 lines
1.9 KiB
C
|
|
/* ************************************************************************** */
|
||
|
|
/* */
|
||
|
|
/* ::: :::::::: */
|
||
|
|
/* render.c :+: :+: :+: */
|
||
|
|
/* +:+ +:+ +:+ */
|
||
|
|
/* By: tchampio <tchampio@student.42lehavre.fr> +#+ +:+ +#+ */
|
||
|
|
/* +#+#+#+#+#+ +#+ */
|
||
|
|
/* Created: 2025/07/30 12:50:10 by tchampio #+# #+# */
|
||
|
|
/* Updated: 2025/07/30 16:22:42 by tchampio ### ########.fr */
|
||
|
|
/* */
|
||
|
|
/* ************************************************************************** */
|
||
|
|
|
||
|
|
#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;
|
||
|
|
static int texture_size = 64; // to be changed in favor of a const
|
||
|
|
|
||
|
|
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))
|
||
|
|
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;
|
||
|
|
while (ray->draw_start < ray->draw_end)
|
||
|
|
{
|
||
|
|
pos += step;
|
||
|
|
color = 0x0000ff;
|
||
|
|
(void)dir; // cc complains otherwise
|
||
|
|
(void)pos; // cc complains otherwise
|
||
|
|
data->screen_matrix[ray->draw_start][x] = color;
|
||
|
|
ray->draw_start++;
|
||
|
|
}
|
||
|
|
}
|