-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcub3d.h
179 lines (168 loc) · 4.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cub3d.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aarbaoui <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/29 00:34:22 by aarbaoui #+# #+# */
/* Updated: 2023/06/11 15:29:00 by aarbaoui ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef CUB3D_H
# define CUB3D_H
# include "../MLX42/MLX42.h"
# include "get_next_line.h"
# include "libft.h"
# include <math.h>
# include <stdbool.h>
# include <stdio.h>
# include <stdlib.h>
# define PI 3.14159265358979323846
# define ERROR 0
# define SUCCESS 1
# define WIDTH 1440
# define HEIGHT 1080
# define FOV 1.0472 // Field of View (60 degrees in radians)
# define NUM_RAYS WIDTH // Number of rays to cast
# define VIEW_ANGLE 1.0472 // Viewing angle (60 degrees in radians)
# define WALL_SCALE 30 // Wall scale factor
# define MAX_RENDER_DISTANCE 1000
# define MAXWIDTH 64
# define MAXHEIGHT 64
# define SENSE 0.7
typedef struct s_line
{
int x0;
int x1;
int x2;
int x3;
int y0;
int y1;
int y2;
int y3;
int size;
} t_line;
typedef struct s_var
{
int dx;
int dy;
int sx;
int sy;
int err;
int e2;
int i;
int j;
int l;
int x;
int y;
float speed;
float new_px;
float new_py;
int cell_x;
int cell_y;
} t_var;
typedef struct s_player
{
float px;
float py;
float pdx;
float pdy;
float pa;
mlx_image_t *img;
} t_player;
typedef struct s_engine
{
float ray_angle_step;
float start_angle;
float ray_angle;
float ray_x;
float ray_y;
float delta_dist_x;
float delta_dist_y;
float side_dist_x;
float side_dist_y;
float perp_dist;
int map_x;
int map_y;
float step_x;
float step_y;
int hit;
float line_end_x;
float line_end_y;
int wall_height;
int wall_top;
int wall_bottom;
int i;
float player_x;
float player_y;
float player_angle;
int offset_x;
int offset_y;
mlx_texture_t *img;
unsigned int *tex;
int stat;
int dis_from_top;
int color;
} t_engine;
typedef struct s_world
{
char *no;
char *so;
char *we;
char *ea;
char *floor_c;
char *ceil_c;
int map_width;
int map_height;
mlx_image_t *walls;
mlx_image_t *minim;
mlx_image_t *skybox;
char **map;
} t_world;
typedef struct s_data
{
void *mlx;
t_engine eng;
t_player pl;
t_world world;
t_var vr;
mlx_texture_t *NO;
mlx_texture_t *SO;
mlx_texture_t *WE;
mlx_texture_t *EA;
unsigned int tex_NO[10000000];
unsigned int tex_SO[10000000];
unsigned int tex_WE[10000000];
unsigned int tex_EA[10000000];
} t_data;
//engine
void raycast(t_data *data, float player_x, float player_y,
float player_angle);
void init_player(t_data *data);
void minimap(t_data *data);
void skybox(t_data *data);
void check_movment(t_data *data, float new_px, float new_py);
void move_player(t_data *data, t_var *p);
void calculate_ray_step(t_engine *p, float player_x,
float player_y);
void perform_dda(t_engine *p, t_data *data);
void draw_wall_segment(t_engine *p, t_data *data, int wall_top,
int wall_bottom);
void correct_distortion(t_engine *p, float player_x,
float player_y);
void calculate_wall_height(t_engine *p, int *wall_height,
int *wall_top, int *wall_bottom);
// parsing
void init_parse(t_data *data, char *map_fi);
// utils
int is_map(char *line);
int get_step(float x);
void mlx_draw_line(mlx_image_t *image, t_line t, int color);
int get_rgba(int r, int g, int b, int a);
int get_rgb(int r, int g, int b);
void free_all(char **s);
int ft_strcmp(char *s1, char *s2);
void calculate_map_dimensions(t_data *data);
void ft_error(char *str);
#endif