/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* render2.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: grobledo +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/10/24 14:26:22 by grobledo #+# #+# */ /* Updated: 2024/10/24 14:27:37 by grobledo ### ########.fr */ /* */ /* ************************************************************************** */ #include "algo.h" void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex) { if (ray->side == 0 && ray->dir.x < 0) tex->tex_dir = 0; if (ray->side == 0 && ray->dir.x >= 0) tex->tex_dir = 1; if (ray->side == 1 && ray->dir.y < 0) tex->tex_dir = 2; if (ray->side == 1 && ray->dir.y >= 0) tex->tex_dir = 3; if (ray->side == 0) ray->wallx = g_map.player.pos.y + perpwalldist \ * ray->dir.y; else ray->wallx = g_map.player.pos.x + perpwalldist \ * ray->dir.x; ray->wallx -= floor((ray->wallx)); } void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x, int y, u_int32_t *img_data) { u_int32_t color; u_int32_t *texture_data; tex->tex_y = ((y - (-line_height / 2 + SCREEN_HEIGHT / 2)) \ * tex->tex_height) / line_height; tex->tex_x = (int)(ray->wallx * (double)tex->tex_width); if (ray->side == 0 && ray->dir.x > 0) tex->tex_x = tex->tex_width - tex->tex_x - 1; if (ray->side == 1 && ray->dir.y < 0) tex->tex_x = tex->tex_height - tex->tex_x - 1; texture_data = (u_int32_t *)mlx_get_data_addr(tex->textures[tex->tex_dir], &tex->bpp, &tex->size_line, &tex->endian); color = texture_data[tex->tex_x * tex->tex_width + tex->tex_y]; img_data[y * SCREEN_WIDTH + x] = color; }