/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* utils.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: erey-bet +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2023/05/11 14:19:16 by erey-bet #+# #+# */ /* Updated: 2023/05/11 14:19:19 by erey-bet ### ########.fr */ /* */ /* ************************************************************************** */ #include "game.h" double ft_abs(double nb) { if (nb < 0) return (-nb); return (nb); } unsigned int get_rgba(int r, int g, int b, int a) { return (r << 24 | g << 16 | b << 8 | a); } static uint32_t switch_color_bytes(uint32_t color) { return (((color & 0xff) << 24) | (((color >> 8) & 0xff) << 16) | (((color >> 16) & 0xff) << 8) | color >> 24); } uint32_t get_pixel_color(mlx_texture_t *texture, uint32_t x, uint32_t y) { return (switch_color_bytes(*(uint32_t *)(texture->pixels + (y * texture->width + x) * texture->bytes_per_pixel))); } int get_texture_side(t_dda *dda) { if (dda->side == 0 && dda->step_x < 0) return (0); if (dda->side == 0 && dda->step_x > 0) return (1); if (dda->side == 1 && dda->step_y < 0) return (2); if (dda->side == 1 && dda->step_y > 0) return (3); return (0); }