-
Notifications
You must be signed in to change notification settings - Fork 0
/
raymarching.h
296 lines (251 loc) · 5.86 KB
/
raymarching.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* raymarching.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jserrano <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/05 13:46:38 by jserrano #+# #+# */
/* Updated: 2020/11/05 14:56:14 by jserrano ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef RAYMARCHING_H
# define RAYMARCHING_H
# ifndef M_PI
# define M_PI 3.14159265358979323846
# endif
# define KEY_PR 2
# define BUT_PR 4
# define BUT_RE 5
# define MOT_NT 6
# define CLI_MG 33
# define MK_KEY_PR 1
# define MK_BUT_PR 4
# define MK_BUT_RE 8
# define MK_PTR_MO 64
# define CL_CLOSE 3
# define KEY_ESC 0xff1b
# define KEY_W 0x0077
# define KEY_A 0x0061
# define KEY_S 0x0073
# define KEY_D 0x0064
# define KEY_SPA 0x0020
# define KEY_CTR 0xffe3
# define KEY_ENT 0xff0d
# define KEY_V 0x0076
# include <stdlib.h>
# include <stdio.h>
# include <unistd.h>
# include <math.h>
# include "minilibx-linux-master/mlx.h"
# include "gnl/get_next_line_bonus.h"
# include "libft/libft.h"
typedef struct s_mouse{
int x;
int y;
double speed;
} t_mouse;
typedef struct s_coord{
int x;
int y;
int aux_x;
int aux_y;
} t_coord;
typedef struct s_screen{
int x;
int y;
int fov;
double dist;
} t_screen;
typedef struct s_ray{
double v_o[3];
double v_l[3];
double o[3];
double o_prev[3];
double mod;
int obj_c;
int obj_n;
int ray_c;
int ray_rgb[3];
int ray_rgb_l[3];
int ray_rgb_o[3];
double intens;
} t_ray;
typedef struct s_camera{
int i;
int n;
double o[3];
double p[3];
double vn[3];
double vx[3];
double vy[3];
double rot_z;
double rot_y;
t_ray ray;
} t_camera;
typedef struct s_cams{
double o[3];
double v[3];
int fov;
} t_cams;
typedef struct s_image{
void *img;
char *addr;
int bits_per_pixel;
int line_length;
int endian;
} t_image;
typedef struct s_sphere{
double o[3];
double r;
int col;
} t_sphere;
typedef struct s_plane{
double o[3];
double v[3];
int col;
} t_plane;
typedef struct s_cylinder{
double o[3];
double v[3];
double h;
double d;
int col;
} t_cylinder;
typedef struct s_square{
double o[3];
double v[3];
double x[3];
double y[3];
double h;
int col;
} t_square;
typedef struct s_box{
double o[3];
double v[3];
double x[3];
double y[3];
double h;
int col;
} t_box;
typedef struct s_triangle{
double a[3];
double b[3];
double c[3];
double ab[3];
double ac[3];
double nor[3];
int col;
} t_triangle;
typedef struct s_light{
double o[3];
int col;
int rgb[3];
} t_light;
typedef struct s_data{
void *id;
void *win_id;
int max_res[2];
int key;
int button;
int reload;
t_mouse mou;
t_coord crd;
t_screen scr;
t_camera cam;
t_image img;
t_sphere **sp;
t_plane **pl;
t_cylinder **cy;
t_square **sq;
t_box **bx;
t_triangle **tr;
t_light **l;
t_cams **c;
int amb_l;
int amb_l_rgb[3];
} t_data;
/*
** mouse.c && keyboard.c
*/
int get_pos(int x, int y, t_data *param);
int button_pressed(int button, int x, int y, t_data *param);
int button_released(int button, int x, int y, t_data *param);
int key_pressed(int keycode, t_data *param);
/*
** misc/
*/
int ft_loop(t_data *param);
int ft_exit(t_data *param);
void my_mlx_pixel_put(t_data *param, int x, int y, int color);
double mod(double *v);
void rgb_to_hex(int *rgb, int *hex);
void hex_to_rgb(int hex, int *rgb);
double max(double a, double b);
double cross_prod(double *u, double *v, int i);
double dot_prod(double *u, double *v);
double plane_dist(double *v, double *o, double *p);
double segment_dist(double *a, double *b, double *p);
double min(double a, double b);
double dot2_prod(double *u);
double dot_2d(double *u, double *v, int x, int y);
void norm(double *u, double *v);
/*
** init.c
*/
void mouse_init(t_data *param);
void pos_init(t_data *param, int i);
void vectors_init(t_data *param, int i);
void ft_init(t_data *param, char **argv);
/*
** cam_calc.c
*/
void calculate_vectors(t_data *def);
void calculate_rotation(t_data *param);
void copy_cam(t_data *param);
/*
** add_obj/
*/
t_sphere **add_sp(t_sphere **sp, double *o, double r, int c);
t_plane **add_pl(t_plane **pl, double *o, double *v, int c);
t_cylinder **add_cy(t_cylinder **cy, double **o_v, double *h_d, int c);
t_light **add_l(t_light **l, double *o, int c);
t_cams **add_c(t_cams **c, double **o_v, int fov);
t_square **add_sq(t_square **sq, double **o_v, double h, int c);
t_box **add_bx(t_box **bx, double **o_v, double h, int c);
t_triangle **add_tr(t_triangle **tr, double **abc, int col);
/*
** raymarching.c
*/
void gen_ray(t_data *param, int x, int y, int boolean);
int is_hit(t_data *param);
int bounce_ray(t_data *param, int i);
/*
** test_func.c
*/
int show_obj(t_data *param);
/*
** dist.c
*/
double obj_dist(t_data *param);
/*
** parse
*/
int def_settings(t_data *param, char *line);
int def_sp(t_data *param, char *line);
int def_pl(t_data *param, char *line);
int def_cy(t_data *param, char *line);
int def_sq(t_data *param, char *line);
int def_tr(t_data *param, char *line);
int def_bx(t_data *param, char *line);
int def_obj(t_data *param, char *line);
int def_elm(t_data *param, char *line);
/*
** parser.c
*/
void parse(t_data *param, char **argv);
/*
** save.c
*/
void save_scr(t_data *param);
#endif