-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcub3d.h
executable file
·211 lines (201 loc) · 5.45 KB
/
cub3d.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fflores <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/02 14:29:00 by fflores #+# #+# */
/* Updated: 2020/11/02 14:29:09 by fflores ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# define TILE_SIZE 32
# define FOV_ANGLE 60 * M_PI / 180
# define STRIP_WIDTH 1
# include <errno.h>
# include <stdio.h>
# include <stdlib.h>
# include <stddef.h>
# include <fcntl.h>
# include <unistd.h>
# include <math.h>
# include "./libft/libft.h"
# include "./get_next_line/get_next_line.h"
# include "./mlx_dylib/mlx.h"
typedef struct s_list
{
char *content;
struct s_list *next;
} t_list;
typedef struct s_ray
{
float angel;
double wall_hit_x;
double wall_hit_y;
double h_w_h_x;
double h_w_h_y;
double v_w_h_x;
double v_w_h_y;
double distance;
int point_up;
int point_down;
int point_right;
int point_left;
int ray_hit_vertical_wall;
int f_h_w_h;
int f_v_w_h;
double hit_sprite;
double x_step;
double y_step;
double dx;
double dy;
double next_horz_y;
double next_horz_x;
double next_vert_y;
double next_vert_x;
} t_ray;
typedef struct s_player
{
double x;
double y;
double radius;
float rotation_angel;
double move_speed;
double rotation_speed;
} t_player;
typedef struct s_img
{
void *img_ptr;
char *img_addr;
int bits_per_pixel;
int line_length;
int endian;
int width;
int height;
} t_img;
typedef struct s_conf
{
double projected_wall_heigth;
double rm_wall_heigth;
char *path_north;
char *path_east;
char *path_south;
char *path_west;
char *path_sprite;
int double_key_r;
int double_key_n;
int double_key_e;
int double_key_s;
int double_key_w;
int double_key_sp;
int double_key_f;
int double_key_c;
int str_num;
int screen_size_x;
int screen_size_y;
int win_h;
int win_w;
int map_h;
double map_size;
int num_rays;
unsigned long ceill_color;
unsigned long floor_color;
char **world_map;
} t_conf;
typedef struct s_sprite
{
double spr_dir;
int i;
int j;
double step;
int count;
int color;
int x;
int y;
double x1;
double y1;
double x2;
double y2;
double dir;
double distance;
double ray_hit_x;
double ray_hit_y;
int sprite_w;
int sprite_h;
double h_offset;
double v_offset;
void *next;
} t_sprite;
typedef struct s_data
{
double depth_buffer[1920];
void *mlx;
void *mlx_win;
char **str;
int save;
t_conf conf;
t_player player;
t_ray **rays;
t_img img;
t_img tex[5];
t_sprite *sprite;
t_sprite *out;
t_sprite *q;
t_sprite *p;
t_sprite *pr;
} t_data;
t_sprite *sort_sprite(t_data *all, t_sprite **ph);
void sprites_conf(t_data *data);
void screen_shot(t_data *data);
void sprites_list(t_data *data);
void render_sprites(t_data *data);
void check_double_key(t_data *data);
void check_invalid_key(t_data *data, char **str);
int ft_min(int a, int b);
int ft_max(int a, int b);
int ft_numsize(int num);
float normalize_angle(double angle);
void mlx_pix_put(t_data *data, int x, int y, int color);
unsigned long rgb_hex(int r, int g, int b);
double calculate_distance(double x1, double y1,
double x2, double y2);
int point_in_vert_segment(t_data *data, t_ray *ray,
t_sprite *sprite, int column_id);
int point_in_horz_segment(t_data *data, t_ray *ray,
t_sprite *sprite, int column_id);
int point_in_segment(t_data *data, t_ray *ray,
t_sprite *sprite, int column_id);
void key_input(int keycode, t_data *data);
int safe_distance(t_data *data, double player_x, double player_y);
int mlx_close(t_data *data);
void render_ceilling_floor(t_data *data);
void render_rays(t_data *data);
void free_rays_array(t_data *data);
void ray_pointer(t_ray *ray);
void ray_vert_hit_wall(t_ray *ray, t_data *data);
void ray_horz_hit_wall(t_ray *ray, t_data *data);
int is_wall(t_data *data, double x, double y);
void render_walls(t_data *data);
void texture_walls(t_data *data, t_ray *ray, int column_id,
double scale);
t_img scale_textures(t_data *data, t_img tex,
double scale, int tex_x);
t_img choose_texture(t_data *data, t_ray *ray);
int wall_color(t_ray *ray);
void check_map(t_data *data);
int check_zeros(char **world_map, int j, int i);
void check_player(int detcted);
void check_error_save(t_data *data, int argc, char **argv, int fd);
void ft_put_error(char *s, int id);
void start(t_data *data);
size_t make_list(int fd, t_list **list);
void get_player_location(t_data *data);
void get_resolution(char **str, t_data *data, size_t elm_count);
void get_floor_ceilling(char **str, t_data *data, size_t elm_count);
void get_tex_path(char **str, t_data *data, size_t elm_count);
int get_map(char **ptr, t_data *data);
char **getinfo(t_list **list, size_t elm_count);
void get_textures(t_data *data);
#endif