-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfdf.h
418 lines (385 loc) · 9.81 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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* fdf.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jjacobso <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/03/15 13:43:46 by jjacobso #+# #+# */
/* Updated: 2019/05/21 16:21:06 by jjacobso ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FDF_H
# define FDF_H
# include "libft.h"
# include "mlx.h"
# define COORD(x, y, z, w, clr) (t_coord){x, y, z, w, clr}
# define C(x, y, z) (t_coord){x, y, z, 0, 0}
# define PAIR(x, y) (t_pair){x, y}
# define RECT(x, y, z, w) (t_rect){x, y, z, w}
# define LINE(x, y) (t_line){x, y, x, y}
# define K 30.0f
# define KEY_ESC 53
# define KEY_ENTER 36
# define KEY_LMK 1
# define KEY_RMK 2
# define KEY_R 15
# define KEY_MOUSE_UP 5
# define KEY_MOUSE_DOWN 4
# define KEY_W 13
# define KEY_S 1
# define KEY_H 4
# define KEY_M 46
# define KEY_1 18
# define KEY_2 19
# define KEY_3 20
# define KEY_4 21
# define KEY_5 23
# define KEY_6 22
# define KEY_7 26
# define KEY_8 28
# define KEY_9 25
# define KEY_0 29
# define LINE_CLR 1
# define BG_CLR 2
# define LAMP_COORD 3
# define WRONG_NUM 1
# define WRONG_INPUT 2
# define SMOOTH 1
# define UGLY 0
# define INT_SENS 1
# define DOUBLE_SENS 0
# define CONIC 1
# define ISO 0
# define FIRST_LOAD 1
# define LINE_TYPE 0
# define USE_SHADER 1
# define MENU_BG 2
# define INTERPOLATION 4
# define PROJ_TYPE 5
# define PERSPECTIVE 6
# define DRAW_MODE 7
# define Z_MOD 9
# define PERSP_MOD 10
# define WHEEL_SPEED 12
# define ROTATIO_SPEED 13
# define ROTATION_SENS 14
# define BACKGROUND 16
# define L_COLOR 17
# define LIGHT_BRIGHTNESS 18
# define BRIGHTNESS 19
# define LAMP_POS 21
# define DARKNESS_BORDER 23
# define PITCH 25
# define YAW 26
# define SCALE 27
# define RST 29
# define X(v) v[0]
# define Y(v) v[1]
# define Z(v) v[2]
# define DOT(x,y) view->map.dot[x][y]
# define PROJECTION(x,y) view->map.projection[x][y]
# define MOUSE view->mouse
# define OPTIONS view->options
# define IMAGE view->image
# define MENU view->menu
# define PROPS view->props
# define MAP view->map
# define IO view->io
# define LAMP view->lamp
# define TO_RADIANS(x) (x * M_PI / 180)
# define TO_DEGREES(x) (x * 180 / M_PI)
# define XOR(x, y) ((x + y) % 2)
typedef struct s_coord
{
double x;
double y;
double z;
double w;
int clr;
} t_coord;
typedef struct s_tetra
{
int x;
int y;
int z;
int w;
} t_tetra;
typedef struct s_pair
{
double x;
double y;
} t_pair;
typedef struct s_line
{
t_coord s;
t_coord e;
t_coord not_clipped_s;
t_coord not_clipped_e;
} t_line;
typedef struct s_rect
{
t_coord a;
t_coord b;
t_coord c;
t_coord d;
} t_rect;
typedef struct s_mouse
{
int x;
int y;
int lmk_pressed;
int rmk_pressed;
} t_mouse;
typedef struct s_image
{
void *id;
char *data;
int bpp;
int line_size;
int endian;
int maxw;
int maxh;
int w;
int h;
} t_image;
typedef struct s_options
{
char rotation_global_sens;
char use_image;
char open_menu;
char line_mode;
char menu_draw_mode;
char print_menu_bg;
char priority_draw;
char interpolation;
char perspective;
} t_options;
typedef struct s_props
{
double fscale;
double alpha;
double beta;
double gamma;
int rotation_speed;
int z_modifier;
int perspective_modifier;
int brightness;
char projection_type;
int bg_clr;
int line_clr;
int darkness_border;
} t_props;
typedef struct s_map
{
t_coord center;
t_pair offset;
t_pair last_offset;
int max_x;
int max_y;
int max_z;
int min_z;
t_coord **dot;
t_coord **projection;
} t_map;
typedef struct s_io
{
int input;
int saved_clr;
t_coord saved_coord;
char read_mode;
char to_read;
char read_err;
int wheel_speed;
char print_loading;
} t_io;
typedef struct s_lamp
{
int light_brightness;
t_coord projection;
t_coord dot;
} t_lamp;
typedef struct s_view
{
void *id;
void *win;
t_map map;
t_mouse mouse;
t_image image;
t_image menu;
t_props props;
int ww;
int wh;
t_options options;
t_io io;
t_lamp lamp;
t_queue *draw_queue;
t_rect clip_space;
} t_view;
/*
** service.c
*/
void close_program(t_view *view);
void error(char *s);
t_view get_view();
/*
** hooks.c
*/
int exit_hook(t_view *view);
int motion_hook(int x, int y, t_view *view);
int mouse_press_hook(int key, int x, int y,
t_view *view);
int mouse_release_hook(int key, int x, int y,
t_view *view);
int key_press_hook(int key, t_view *view);
/*
** parse.c:
*/
void read_map(t_view *view, const char *file);
/*
** draw.c
*/
void print_info(t_view *view);
void print_map(t_view *view);
t_coord translate(t_view *view, t_coord c);
/*
** projection.c
*/
void project(t_view *view);
/*
** image.c
*/
void image_init(void *id, t_image *image, int ww,
int wh);
void pixel_put(t_view *view, double x, double y,
int clr);
void image_clear(t_view *view, t_image img);
/*
** menu.c
*/
void print_menu(t_view *view);
/*
** priority_draw.c
*/
t_list *get_z_lvls(t_view *view);
void fill_draw_queue(t_view *view);
void priority_line_draw(t_view *view);
/*
** hook_service.c
*/
void set_hooks(t_view *view);
void lock_angle(double *angle, double min,
double max);
void set_angles(t_view *view, int x, int y);
void set_clr(t_view *view);
int get_line_number(int y, int wh);
/*
** io_service.c
*/
int io_is_reading(t_view *view);
void io_set_coord(t_view *view);
int io_read_clr(t_view *view, int key);
int io_read_coord(t_view *view, int key);
/*
** io.c
*/
int io_read_coord_prepare(t_view *view, int x);
int io_read_clr_prepare(t_view *view, int x,
int clr_type, int clr);
int io_read(t_view *view, int key);
/*
** map.c
*/
int map_reset(t_view *view);
t_coord dot_center_coord(t_view *view);
void coord_reset(t_coord *c);
double dist3d(t_coord a, t_coord b);
double dist2d(t_coord a, t_coord b);
/*
** menu_hooks.c
*/
void menu_lmc_handle(t_view *view, int x, int line);
void menu_wheel_handle(t_view *view, int key,
int line);
void menu_mouse_hook(t_view *view, int key, int x,
int y);
/*
** color.c
*/
int str_to_clr(char *s);
int rgb(int r, int g, int b);
void set_line_color(t_view *view);
/*
** light.c
*/
void apply_light(t_view *view);
int darker(int clr, double k);
int brighter(int clr, double k);
/*
** menu_output.c
*/
void menu_line_with_coord(t_view *view, int line,
char *s, t_coord c);
void menu_line_with_clr(t_view *view, int line,
char *s, int clr);
void menu_line_with_num(t_view *view, int line,
char *s, int num);
void menu_line_with_num_and_procent(t_view *view,
int line, char *s, int num);
/*
** menu_output_service.c
*/
char *nspaces(int n);
char *clr_to_line(int clr);
char *coord_to_line(t_coord c);
void rgb_print(t_view *view, int line, int clr,
char *s);
/*
** tetra.c
*/
void *copy_tetra(void *tetra);
t_tetra *tetra_mas(t_tetra t);
/*
** print_line.c:
*/
void line_reverse(t_line *line);
void print_line(t_view *view, t_coord s,
t_coord e);
void print_smooth_line(t_view *view, t_line l);
/*
** print_smooth_line.c
*/
void print_smooth_yline(t_view *view, t_line l);
void print_smooth_xline(t_view *view, t_line l);
int intensity(int sclr, int eclr, double c,
double z);
double interpolation_coeff(t_view *view, t_line l,
char c);
/*
** clipper.c
*/
int invisible(t_view *view, t_coord *s, t_coord *e);
/*
** clipper_service.c
*/
int intersect(t_coord a, t_coord b, t_coord c,
t_coord d);
double fy(double x, t_coord s, t_coord e);
double fx(double y, t_coord s, t_coord e);
/*
** projection_service.c
*/
void print_loading(int max, int cur,
char is_printing);
double get_distance_to_cam(t_view *view);
void rotate_around(t_coord *coord, double angle,
double vecb[3]);
void apply_conic(t_coord *project, t_coord dot,
double max_dist, double y);
void z_perspective(t_coord *coord, double h);
/*
** scale.c
*/
void auto_scale(t_view *view);
void scale_adjust(t_view *view, int key);
#endif