dev: Added a matrix image set function

- Amended for adding support of transparency, works the same as sprites
This commit is contained in:
Theo Champion 2025-08-20 16:52:35 +02:00
parent 70f6a36aad
commit 242cbe3c7c
2 changed files with 24 additions and 2 deletions

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 13:18:17 by kcolin #+# #+# */
/* Updated: 2025/08/12 14:31:04 by kcolin ### ########.fr */
/* Updated: 2025/08/20 16:53:53 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -50,3 +50,24 @@ void matrix_to_image(t_cub3d_data *data)
y++;
}
}
void matrix_image_put(t_cub3d_data *data, t_img_data *img, int x, int y)
{
int i;
int j;
if (x < 0 || x > WIDTH || y < 0 || y > HEIGHT)
return ;
i = y;
while (i - y < img->height)
{
j = x;
while (j - x < img->width)
{
if (j < WIDTH && my_mlx_pixel_get(img, j - x, i - y) != SPRITE_TRANPARENCY_COLOR)
matrix_set(data, j, i, my_mlx_pixel_get(img, j - x, i - y));
j++;
}
i++;
}
}

View file

@ -6,7 +6,7 @@
/* By: kcolin <kcolin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/07/31 13:36:36 by kcolin #+# #+# */
/* Updated: 2025/07/31 13:36:43 by kcolin ### ########.fr */
/* Updated: 2025/08/20 16:51:31 by tchampio ### ########.fr */
/* */
/* ************************************************************************** */
@ -18,5 +18,6 @@
void reset_matrix(t_cub3d_data *data);
void matrix_to_image(t_cub3d_data *data);
void matrix_set(t_cub3d_data *data, int x, int y, int color);
void matrix_image_put(t_cub3d_data *data, t_img_data *img, int x, int y);
#endif // RENDER_H