65 lines
2.3 KiB
C
65 lines
2.3 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* render_utils.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: mcolonna <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */
|
|
/* Updated: 2024/11/18 14:33:01 by mcolonna ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include "render_utils.h"
|
|
|
|
#include "const.h"
|
|
#include "global.h"
|
|
|
|
void calculate_texdir_and_wallx(t_ray *ray)
|
|
{
|
|
if (ray->side && ray->dir.y < 0)
|
|
ray->texdir = NORTH;
|
|
if (ray->side && ray->dir.y >= 0)
|
|
ray->texdir = SOUTH;
|
|
if (!ray->side && ray->dir.x < 0)
|
|
ray->texdir = EAST;
|
|
if (!ray->side && ray->dir.x >= 0)
|
|
ray->texdir = WEST;
|
|
if (!ray->side)
|
|
ray->wallx = g_map.player.pos.y + ray->perpwalldist \
|
|
* ray->dir.y;
|
|
else
|
|
ray->wallx = g_map.player.pos.x + ray->perpwalldist \
|
|
* ray->dir.x;
|
|
if (ray->texdir == SOUTH || ray->texdir == EAST)
|
|
ray->wallx = -ray->wallx;
|
|
ray->wallx -= floor((ray->wallx));
|
|
}
|
|
|
|
void draw_vertical_line_end(t_ray *ray, int draw_start, int draw_end,
|
|
u_int32_t *img_data)
|
|
{
|
|
u_int32_t color;
|
|
u_int32_t *texture_data;
|
|
int texx;
|
|
int texy;
|
|
const t_texture texture = g_map.textures[ray->texdir];
|
|
|
|
ray->y = -1;
|
|
while (++ray->y < SCREEN_HEIGHT)
|
|
{
|
|
if (ray->y < draw_start)
|
|
img_data[ray->y * SCREEN_WIDTH + ray->x] = g_map.color_ceiling;
|
|
else if (ray->y < draw_end)
|
|
{
|
|
texy = ((ray->y - ((draw_start - draw_end) / 2 + SCREEN_HEIGHT / 2))
|
|
* texture.height) / (draw_end - draw_start);
|
|
texx = (int)(ray->wallx * (double)texture.width);
|
|
texture_data = get_data_addr(texture.image);
|
|
color = texture_data[texy * texture.width + texx];
|
|
img_data[ray->y * SCREEN_WIDTH + ray->x] = color;
|
|
}
|
|
else
|
|
img_data[ray->y * SCREEN_WIDTH + ray->x] = g_map.color_floor;
|
|
}
|
|
}
|