-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdf.h
239 lines (181 loc) · 4.89 KB
/
fdf.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fvonsovs <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/06 15:12:54 by fvonsovs #+# #+# */
/* Updated: 2023/03/22 14:27:45 by fvonsovs ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FDF_H
# define FDF_H
# include "./libft/libft.h"
# include "./minilibx-linux/mlx.h"
# include <fcntl.h>
# include <errno.h>
# include <math.h>
# include <stdio.h>
# include <unistd.h>
# include <X11/X.h>
# include <X11/keysym.h>
// 4:3 is god's chosen aspect ratio
# define WINDOW_WIDTH 1280
# define WINDOW_HEIGHT 1024
# ifndef M_PI
# define M_PI 3.14159265358979323846
# endif
// map holding struct
typedef struct s_map
{
int height;
int width;
int **array;
int z_max;
int z_min;
} t_map;
// struct for transformations (camera etc.)
typedef struct s_transform
{
int scale;
int x_angle;
int y_angle;
int z_angle;
int x_offset;
int y_offset;
} t_transform;
// main data holding struct
typedef struct s_data
{
void *mlx;
void *win;
void *img;
char *addr;
int bits_per_pixel;
int line_length;
int endian;
int project;
int wu_tang;
t_map *map;
t_transform transform;
} t_data;
// color holding struct for wu's line alg
typedef struct s_color
{
int r_base;
int g_base;
int b_base;
int r_whole;
int g_whole;
int b_whole;
int r_fractional;
int g_fractional;
int b_fractional;
} t_color;
// struct for x y z
typedef struct s_3d
{
int x;
int y;
int z;
} t_3d;
// structs for 2d points and bresenham line increments
typedef struct s_2d
{
int x;
int y;
} t_2d;
// i forgot why we have the same struct twice
typedef struct s_increment
{
int x;
int y;
} t_increment;
// gradient and intensity structs for wu's line algorithm
typedef struct s_gradient
{
double x;
double y;
} t_gradient;
typedef struct s_intensity
{
int whole;
int fractional;
} t_intensity;
// because norminette sucks
typedef struct s_transform_vars
{
int i;
int j;
t_2d proj;
t_2d prev_proj;
t_2d off;
t_2d p_a;
t_3d p;
t_3d p_abv;
float a;
float s;
} t_transform_vars;
// line holding struct
typedef struct s_line
{
int x1;
int x2;
int y1;
int y2;
int dx;
int dy;
t_increment inc;
int error;
} t_line;
// fdf.c
int handle_destroy_notify(t_data *data);
void print_controls(t_data *data);
int handle_keypress(int keysym, t_data *data);
int render(t_data *data);
// fdf_map_utils.c
// int test_map_read(t_map *map);
t_map *map_init(void);
void free_map_array(t_map *map);
void free_split(char **str);
// fdf_map_parser.c
int get_height(char *filename);
int count_words(char *str, char c);
int *parse_line(char *line, t_map *map);
t_map *parse_map(t_map *map, char *filename);
// fdf_draw_utils.c
t_3d xyz_from_map(t_map *map, int x, int y);
t_2d _3d_2d(t_3d p, float scale, float angle, t_2d offset);
t_2d _3d_2d_p(t_3d p, float scale, float angle, t_2d offset);
t_transform init_transform(void);
t_transform_vars init_transform_vars(t_transform *transform);
// fdf_draw_utils_2.c
void initialize_wu_vars(t_line *line, \
t_increment *inc, double *x, double *y);
t_gradient wu_gradient(t_line *line);
t_intensity wu_intensity(int base_color, double weight);
void swap_points(t_line *line);
int you_fucked_up(char *msg);
// fdf_draw_bresenham_line.c
t_increment calculate_increment(t_line *line);
void update_error(t_line *line, int *coord, \
int error_diff, int coord_diff);
void initialize_line_vars(t_line *line, \
t_increment *inc, int *x, int *y);
void bresenham_line(t_data *data, t_line line, int color);
// void test_bresenham_line(t_data *data);
// fdf_draw_wu_line.c
void wu_line_horizontal(t_data *data, t_line line, int color);
void wu_line_vertical(t_data *data, t_line line, int color);
void wu_line(t_data *data, t_line line, int color);
// fdf_draw_wireframe.c
int render_background(t_data *data, int color, \
int start_x, int end_x);
void draw_line_wrapper(t_data *data, t_2d projection, \
t_2d prev_projection, int color);
void draw_wireframe(t_data *data, t_transform_vars v, \
t_transform *transform, int color);
void draw_wireframe_parallel(t_data *data, t_transform_vars v, \
t_transform *transform, int color);
#endif