You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

103 lines
2.8 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* core.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: hroussea <hroussea@student.42lyon.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/07/05 11:09:45 by hroussea #+# #+# */
/* Updated: 2021/09/22 19:19:20 by hroussea ### ########lyon.fr */
/* */
/* ************************************************************************** */
#ifndef CORE_H
# define CORE_H
# include <unistd.h>
# include <libft/string.h>
# include <mlxglue/resources.h>
# include <mlxglue/math.h>
# include <fcntl.h>
# include "parsing/shellcolor.h"
# include "parsing/optionals.h"
# include "parsing/parsing_check.h"
# include "parsing/map.h"
# include "parsing/optionals.h"
# include "result.h"
# define PLAYER_ROT_SPEED 3.f
# define PLR_WLK_SPEED 0.15f
# define DEG_TO_RAD 0.0174533f
typedef struct s_cub_data {
t_win *window;
t_img *image;
t_map_info map;
t_resid north;
t_resid south;
t_resid east;
t_resid west;
t_resid sprite;
t_vec2f player_pos;
t_f32 player_angle;
t_f32 delta_angle;
t_f32 fov;
t_f32 health;
t_bool right_key;
t_bool left_key;
t_bool up_key;
t_bool strafeleft_key;
t_bool straferight_key;
t_bool down_key;
t_f32 tex_x_off;
} t_cub_data;
int main_prelude(int argc, char **argv);
t_bool handle_map_blocks(t_map_info *map, char *input, int off);
int ft_freeall(t_vector *vec, t_map_info *map, int ret, t_bool sexit);
int hook_exit(t_cub_data *data);
t_resid load_texture(char *path);
t_bool load_textures(t_cub_data *data);
t_f32 clamp(t_f32 v, t_f32 max);
struct s_norm_draw_column {
t_vec2i pos;
t_i32 limit;
t_i32 i;
t_color clr;
t_cub_data *data;
};
void draw_column(t_cub_data *data, t_u32 x, t_u32 size, t_img *img);
static inline t_f32 vec_length(t_vec2f vec)
{
return (sqrt(vec.x * vec.x + vec.y * vec.y));
}
static inline t_f32 vec_length_2(t_vec2f vec)
{
return (vec.x * vec.x + vec.y * vec.y);
}
struct s_raycast_norm {
t_vec2f off_y;
t_vec2f off_x;
t_f32 tan_angle;
t_f32 distance;
t_f32 test_x_off;
t_f32 test_y_off;
t_vec2f *off;
};
t_bool angle_too_steep(t_f32 angle);
t_img *prepare_texture(t_cub_data *data, t_vec2f *off);
void raycast(t_cub_data *data, unsigned int x, t_f32 angle);
t_f32 get_angle(t_u32 i, t_u32 w, t_f32 fov);
void raycasting(t_cub_data *data);
int loop(t_cub_data *data);
#endif