42_cub3d/include/algo.h
2024-10-31 16:06:33 +01:00

90 lines
2.6 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* algo.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mc <mc@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/30 15:45:59 by grobledo #+# #+# */
/* Updated: 2024/10/31 16:03:42 by mc ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef ALGO_H
# define ALGO_H
# include <unistd.h>
# include <math.h>
# include <linux/types.h>
# include <stdbool.h>
# include <stdlib.h>
# include <X11/X.h>
# include "mlx.h"
# include "libft.h"
# include "stream.h"
# include "read_all_text.h"
# include "map.h"
# include "map_mapping.h"
# define MAP_WIDTH 24 // cases (TODO test)
# define MAP_HEIGHT 24 // cases (TODO test)
# define TEX_WIDTH 64
# define TEX_HEIGHT 64
# define MOVE_SPEED 0.05 // cases
# define PI 3.1415926535
# define ROT_SPEED_DIVIDE_PI 64 // pi/n rad
# define COLOR_WALL 0xFF0000 // 0xRRGGBB
# define COLOR_CEILING 0x29f8ff // 0xRRGGBB
# define COLOR_FLOOR 0xFF985C // 0xRRGGBB
# define SCREEN_WIDTH 640 // px
# define SCREEN_HEIGHT 480 // px
# define FOV 0.66 // ? TODO unit
# define HITBOX 0.25 // cases. should be more than MOVE_SPEED
typedef struct s_tex
{
void *textures[4];
void *current_tex;
int tex_height;
int tex_width;
int tex_dir;
int tex_x;
int tex_y;
int bpp;
int size_line;
int endian;
} t_tex;
typedef struct s_ray
{
// pos player on map (cases)
t_point_double dir;
bool side;
double wallx;
} t_ray;
extern void *g_mlx;
extern void *g_win;
extern t_player g_player;
extern t_map g_map;
// extern t_tex g_tex;
/// @brief Write an error message on stderr.
///
/// @param str... All the strings to write. The last parameter MUST BE NULL.
void write_err(const char *str, ...);
void vector_from_rotation(t_point_double *vec, double angle, double norm);
int render(u_int32_t *img_data, t_tex *tex);
void draw_screen(void);
void move(void);
void ft_init_texture(const double perpwalldist, t_ray *ray, t_tex *tex);
void draw_wall(t_tex *tex, t_ray *ray, const int line_height, int x,
int y, u_int32_t *img_data);
#endif