42_cube3D/game/utils.c

51 lines
1.7 KiB
C
Raw Normal View History

2023-05-11 10:25:29 -04:00
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: erey-bet <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/11 14:19:16 by erey-bet #+# #+# */
2023-06-16 11:49:22 -04:00
/* Updated: 2023/06/16 17:45:58 by erey-bet ### ########.fr */
2023-05-11 10:25:29 -04:00
/* */
/* ************************************************************************** */
#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)
2023-06-16 11:49:22 -04:00
return (3);
2023-05-11 10:25:29 -04:00
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)
2023-06-16 11:49:22 -04:00
return (0);
2023-05-11 10:25:29 -04:00
return (0);
}