From 7a1e8c18df8a0c13325e5fc4b3f82002cea89e8f Mon Sep 17 00:00:00 2001 From: Theo Champion Date: Wed, 6 Aug 2025 14:04:44 +0200 Subject: [PATCH] dev: moved my_mlx_get_pixel function in draw utils for easier access --- src/draw/drawutils.c | 10 +++++++++- src/draw/drawutils.h | 3 ++- src/raycast/ray.c | 3 ++- src/raycast/walls.c | 10 ++-------- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/draw/drawutils.c b/src/draw/drawutils.c index c5950a3..145cdc1 100644 --- a/src/draw/drawutils.c +++ b/src/draw/drawutils.c @@ -6,13 +6,21 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:28:56 by kcolin #+# #+# */ -/* Updated: 2025/08/06 11:43:12 by kcolin ### ########.fr */ +/* Updated: 2025/08/06 14:02:08 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ #include "img_data.h" #include "../consts.h" +int my_mlx_pixel_get(t_img_data *img, int x, int y) +{ + char *dst; + + dst = img->addr + (y * img->line_length + x * (img->bits_per_pixel / 8)); + return (*(int *)dst); +} + void my_mlx_pixel_put(t_img_data *data, int x, int y, int color) { char *dst; diff --git a/src/draw/drawutils.h b/src/draw/drawutils.h index 31c5927..9b48afb 100644 --- a/src/draw/drawutils.h +++ b/src/draw/drawutils.h @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/17 14:30:04 by kcolin #+# #+# */ -/* Updated: 2025/07/17 15:57:47 by kcolin ### ########.fr */ +/* Updated: 2025/08/06 12:08:04 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -16,5 +16,6 @@ # include "img_data.h" void my_mlx_pixel_put(t_img_data *data, int x, int y, int color); +int my_mlx_pixel_get(t_img_data *img, int x, int y); #endif // DRAWUTILS_H diff --git a/src/raycast/ray.c b/src/raycast/ray.c index 25ebaad..d555267 100644 --- a/src/raycast/ray.c +++ b/src/raycast/ray.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/31 11:55:41 by kcolin #+# #+# */ -/* Updated: 2025/08/06 11:33:27 by kcolin ### ########.fr */ +/* Updated: 2025/08/06 14:02:40 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -109,6 +109,7 @@ void raycaster(t_cub3d_data *data, t_ray *ray) calculate_wall_dist(ray, data->map); calculate_wall_height(ray, &data->player); render_walls(data, ray, x); + data->zbuffer[x] = ray->wall_dist; x++; } } diff --git a/src/raycast/walls.c b/src/raycast/walls.c index 9616414..ae26477 100644 --- a/src/raycast/walls.c +++ b/src/raycast/walls.c @@ -6,7 +6,7 @@ /* By: kcolin +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2025/07/31 13:17:39 by kcolin #+# #+# */ -/* Updated: 2025/08/05 14:59:24 by kcolin ### ########.fr */ +/* Updated: 2025/08/06 12:08:33 by tchampio ### ########.fr */ /* */ /* ************************************************************************** */ @@ -14,6 +14,7 @@ #include "../consts.h" #include "ray.h" #include "../renderer/render.h" +#include "../draw/drawutils.h" t_cardinal_dir get_cardinal(t_ray *ray) { @@ -33,13 +34,6 @@ t_cardinal_dir get_cardinal(t_ray *ray) } } -static int my_mlx_pixel_get(t_img_data *img, int x, int y) -{ - char *dst; - - dst = img->addr + (y * img->line_length + x * (img->bits_per_pixel / 8)); - return (*(int *)dst); -} static int get_color(t_cub3d_data *data, t_ray *ray, int tex_y) {