/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* walls.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */ /* Updated: 2025/10/01 14:12:44 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ #include "../cub3d_data.h" #include "../consts.h" #include "ray.h" #include "../renderer/render.h" #include "../draw/drawutils.h" #include "../../libft/includes/libft.h" t_cardinal_dir get_cardinal(t_ray *ray) { if (ray->side == NORTH) { if (ray->dir_x < 0) return (WEST); else return (EAST); } else { if (ray->dir_y > 0) return (SOUTH); else return (NORTH); } } t_img_data *get_right_barricade(t_cub3d_data *data, char c) { if (c == '2') return (data->barricades_texture[0]); if (c == '3') return (data->barricades_texture[1]); if (c == '4') return (data->barricades_texture[2]); if (c == '5') return (data->barricades_texture[3]); if (c == '6') return (data->barricades_texture[4]); if (c == '7') return (data->barricades_texture[5]); return (data->so_texture); } static int get_color(t_cub3d_data *data, t_ray *ray, int tex_y) { t_cardinal_dir dir; int tex_x; t_img_data *texture; tex_x = (int)(ray->wall_x * TEXTURE_SIZE); if ((ray->side == NORTH && ray->dir_x < 0) || (ray->side == SOUTH && ray->dir_y > 0)) tex_x = TEXTURE_SIZE - tex_x - 1; dir = get_cardinal(ray); if (ft_strchr("234567", data->map->map[ray->map_y][ray->map_x])) return (my_mlx_pixel_get(get_right_barricade(data, data->map->map[ray->map_y][ray->map_x]), tex_x, tex_y)); if (data->map->map[ray->map_y][ray->map_x] == 'd' || data->map->map[ray->map_y][ray->map_x] == 'P') return (my_mlx_pixel_get(data->door_texture, tex_x, tex_y)); if (dir == NORTH) texture = data->no_texture; else if (dir == SOUTH) texture = data->so_texture; else if (dir == WEST) texture = data->we_texture; else if (dir == EAST) texture = data->ea_texture; else return (0xff53ff); return (my_mlx_pixel_get(texture, tex_x, tex_y)); } void render_walls(t_cub3d_data *data, t_ray *ray, int x) { unsigned int color; double step; double tex_y; int y; step = 1.0 * TEXTURE_SIZE / ray->wall_height; tex_y = (ray->draw_start - HEIGHT / 2 + ray->wall_height / 2) * step; y = 0; while (y < ray->draw_start) { matrix_set(data, x, y, data->map->c_color); y++; } while (y < ray->draw_end - 1) { tex_y += step; color = get_color(data, ray, (int)tex_y); matrix_set(data, x, y, color); y++; } while (y < HEIGHT) { matrix_set(data, x, y, data->map->f_color); y++; } }