RT
rtstruct.h
Go to the documentation of this file.
1 /* ************************************************************************** */
2 /* */
3 /* ::: :::::::: */
4 /* rtstruct.h :+: :+: :+: */
5 /* +:+ +:+ +:+ */
6 /* By: nihuynh <nihuynh@student.42.fr> +#+ +:+ +#+ */
7 /* +#+#+#+#+#+ +#+ */
8 /* Created: 2018/12/10 00:44:05 by nihuynh #+# #+# */
9 /* Updated: 2019/07/17 19:06:58 by nihuynh ### ########.fr */
10 /* */
11 /* ************************************************************************** */
12 
13 #ifndef RTSTRUCT_H
14 # define RTSTRUCT_H
15 
16 # include <stdbool.h>
17 # include <stdint.h>
18 # include "ftbtree.h"
19 # include "color.h"
20 
21 typedef struct s_obj t_obj;
22 typedef struct s_inter t_inter;
23 
24 typedef struct s_vec2
25 {
26  float x;
27  float y;
28 } t_vec2;
29 
30 typedef struct s_vec3
31 {
32  float x;
33  float y;
34  float z;
35 } t_vec3;
36 
37 typedef t_vec3 t_pt3;
38 
39 typedef struct s_matrix
40 {
41  float m[3][3];
42 } t_matrix;
43 
44 typedef struct s_ray
45 {
48 } t_ray;
49 
50 typedef struct s_plane
51 {
59  int type;
60 } t_plane;
61 
62 typedef struct s_sphere
63 {
65  float radius;
69 } t_sphere;
70 
71 typedef struct s_cone
72 {
75  float theta;
76  float size;
79 } t_cone;
80 
81 typedef struct s_cylinder
82 {
87  float radius;
88  float size;
89 } t_cylinder;
90 
91 typedef struct s_csg
92 {
97  t_btree *root;
98 } t_csg;
99 
100 typedef struct s_cube
101 {
108  float size;
109 } t_cube;
110 
111 typedef struct s_tore
112 {
117  float radius;
118  float size;
119 } t_tore;
120 
121 typedef struct s_light
122 {
125  float intensity;
126  char *name;
127  void *anim;
128 } t_light;
129 
130 typedef struct s_cam
131 {
135  float y_angle;
136  float x_angle;
137  void *anim;
144  bool rotate_up;
148  bool lock;
149  bool lock_pos;
151  bool lock_obj;
153  int speed;
154 } t_cam;
155 
156 /*
157 ** @brief Struct for material caracteristics
158 ** http://www.lama.univ-savoie.fr/pagesmembres/lachaud/Cours/INFO805/Tests/html/
159 ** Material_8h_source.html
160 ** typedef t_color (*f_texture)(t_texture*, float x, float y);
161 */
162 
163 typedef struct s_texture t_texture;
164 typedef struct s_material t_material;
165 
166 struct s_texture
167 {
168  char *name;
169  char *dir;
171  char *pixels;
172  int width;
173  int height;
174  char bpp;
175 };
176 
177 typedef struct s_uv_mapping {
180  bool repeat;
181 } t_uv_mapping;
182 
183 /*
184 ** t_texture *rough_map;
185 ** t_texture *disp_map;
186 ** t_texture *occlusion_map;
187 */
188 
190 {
191  char *name;
195  float spec_idx;
196  float spec_power;
205 };
206 
207 /*
208 ** @brief Struct that hold the intersection.
209 ** dist : minimal distant at the inter
210 ** obj : object touch by the ray
211 ** ray : Ray information
212 ** point : Intersection point
213 ** n : Normal of the object at the inter
214 ** reflected : Vector director of the ray after the inter
215 ** find_normal : Methode to find the normal of the object hit
216 */
217 
218 struct s_inter
219 {
220  float dist;
227 };
228 
229 # define INTER 1
230 # define INTER_STR "INTER"
231 # define NOT 2
232 # define NOT_STR "NOT"
233 # define UNION 3
234 # define UNION_STR "UNION"
235 
236 /*
237 ** @brief Struct that hold any shape and is in a t_list
238 ** type : Type of the shape
239 ** shape : Pointer to shape data
240 ** material : Material caracteristics
241 ** diffuse : Outdated
242 ** f_inter : final color of the pixel
243 */
244 
245 struct s_obj
246 {
247  int type;
248  void *shape;
249  char *name;
255  void *anim;
256  void (*f_inter) (t_inter*, t_obj*);
257  void (*find_normal) (t_inter*);
259  void (*f_gui) (void*, void*);
260  void (*export) (int, void*);
261 };
262 
263 typedef struct s_shading {
267  float light_dist;
273 } t_shading;
274 
275 #endif
s_material::color_tex
t_color color_tex
Definition: rtstruct.h:194
t_cone
struct s_cone t_cone
s_ray
Definition: rtstruct.h:44
s_cam
Definition: rtstruct.h:130
s_tore::n
t_vec3 n
Definition: rtstruct.h:115
t_shading
struct s_shading t_shading
s_ray::dir
t_vec3 dir
Definition: rtstruct.h:47
s_csg::n
t_vec3 n
Definition: rtstruct.h:95
s_tore::x
t_vec3 x
Definition: rtstruct.h:114
s_vec3
Definition: rtstruct.h:30
s_tore::z
t_vec3 z
Definition: rtstruct.h:116
s_shading::specular_dir
t_vec3 specular_dir
Definition: rtstruct.h:271
s_cam::move_upward
bool move_upward
Definition: rtstruct.h:142
s_shading::mat
t_material mat
Definition: rtstruct.h:264
s_cam::anim
void * anim
Definition: rtstruct.h:137
s_cylinder
Definition: rtstruct.h:81
s_cube
Definition: rtstruct.h:100
s_inter::hit_pts
t_vec2 hit_pts
Definition: rtstruct.h:221
s_material::refraction_idx
float refraction_idx
Definition: rtstruct.h:199
t_light
struct s_light t_light
t_csg
struct s_csg t_csg
s_cam::speed
int speed
Definition: rtstruct.h:153
s_cam::pos_lock
t_pt3 pos_lock
Definition: rtstruct.h:150
s_cone::size
float size
Definition: rtstruct.h:76
s_cube::min_corner
t_vec3 min_corner
Definition: rtstruct.h:106
s_material::spec_map
t_texture * spec_map
Definition: rtstruct.h:202
s_ray::origin
t_pt3 origin
Definition: rtstruct.h:46
s_plane::y
t_vec3 y
Definition: rtstruct.h:55
s_vec3::x
float x
Definition: rtstruct.h:32
s_light::name
char * name
Definition: rtstruct.h:126
s_material::reflection_color
t_color reflection_color
Definition: rtstruct.h:198
s_csg
Definition: rtstruct.h:91
s_inter::n
t_vec3 n
Definition: rtstruct.h:225
s_material::refract_map
t_texture * refract_map
Definition: rtstruct.h:203
s_csg::root
t_btree * root
Definition: rtstruct.h:97
s_cone::n
t_vec3 n
Definition: rtstruct.h:74
s_shading::hit_pos
t_vec3 hit_pos
Definition: rtstruct.h:268
s_matrix::m
float m[3][3]
Definition: rtstruct.h:41
s_uv_mapping
Definition: rtstruct.h:177
s_shading::normal
t_vec3 normal
Definition: rtstruct.h:269
s_material
Definition: rtstruct.h:189
s_inter::obj
t_obj * obj
Definition: rtstruct.h:222
s_color
Definition: color.h:23
t_matrix
struct s_matrix t_matrix
s_cam::y_angle
float y_angle
Definition: rtstruct.h:135
s_shading::light_dir
t_vec3 light_dir
Definition: rtstruct.h:266
s_shading
Definition: rtstruct.h:263
t_cylinder
struct s_cylinder t_cylinder
s_obj
Definition: rtstruct.h:245
t_vec2
struct s_vec2 t_vec2
s_cam::rotate_right
bool rotate_right
Definition: rtstruct.h:147
s_obj::z
t_vec3 * z
Definition: rtstruct.h:254
s_uv_mapping::scale
t_vec2 scale
Definition: rtstruct.h:179
t_cam
struct s_cam t_cam
s_cam::obj_lock
t_obj * obj_lock
Definition: rtstruct.h:152
s_cam::rotate_down
bool rotate_down
Definition: rtstruct.h:145
s_obj::n
t_vec3 * n
Definition: rtstruct.h:253
s_obj::f_inter
void(* f_inter)(t_inter *, t_obj *)
Definition: rtstruct.h:256
s_sphere::z
t_vec3 z
Definition: rtstruct.h:68
s_light::color
t_color color
Definition: rtstruct.h:124
s_texture
Definition: rtstruct.h:166
s_cube::n
t_vec3 n
Definition: rtstruct.h:104
s_plane::x
t_vec3 x
Definition: rtstruct.h:54
s_light::anim
void * anim
Definition: rtstruct.h:127
s_cam::lock_obj
bool lock_obj
Definition: rtstruct.h:151
s_uv_mapping::offset
t_vec2 offset
Definition: rtstruct.h:178
s_obj::pos
t_pt3 * pos
Definition: rtstruct.h:251
s_vec2::y
float y
Definition: rtstruct.h:27
s_cam::rotation
t_matrix rotation
Definition: rtstruct.h:134
s_csg::x
t_vec3 x
Definition: rtstruct.h:94
s_vec3::y
float y
Definition: rtstruct.h:33
s_obj::export
void(* export)(int, void *)
Definition: rtstruct.h:260
t_uv_mapping
struct s_uv_mapping t_uv_mapping
s_inter::dist
float dist
Definition: rtstruct.h:220
s_cylinder::n
t_vec3 n
Definition: rtstruct.h:85
t_ray
struct s_ray t_ray
s_plane::type
int type
Definition: rtstruct.h:59
s_vec2::x
float x
Definition: rtstruct.h:26
s_shading::light_dist
float light_dist
Definition: rtstruct.h:267
s_uv_mapping::repeat
bool repeat
Definition: rtstruct.h:180
s_cone::x
t_vec3 x
Definition: rtstruct.h:77
s_texture::width
int width
Definition: rtstruct.h:172
s_cam::strafe_right
bool strafe_right
Definition: rtstruct.h:141
s_cylinder::origin
t_pt3 origin
Definition: rtstruct.h:83
s_cylinder::radius
float radius
Definition: rtstruct.h:87
s_matrix
Definition: rtstruct.h:39
s_material::tex
t_texture * tex
Definition: rtstruct.h:200
s_tore::size
float size
Definition: rtstruct.h:118
s_sphere::radius
float radius
Definition: rtstruct.h:65
s_material::normal_map
t_texture * normal_map
Definition: rtstruct.h:201
s_sphere::origin
t_pt3 origin
Definition: rtstruct.h:64
s_obj::material
t_material material
Definition: rtstruct.h:250
s_plane::n
t_vec3 n
Definition: rtstruct.h:53
s_sphere
Definition: rtstruct.h:62
s_tore::radius
float radius
Definition: rtstruct.h:117
s_material::uv_mapping
t_uv_mapping uv_mapping
Definition: rtstruct.h:204
s_cam::dir
t_vec3 dir
Definition: rtstruct.h:133
s_shading::shading_normal
t_vec3 shading_normal
Definition: rtstruct.h:270
s_cube::x
t_vec3 x
Definition: rtstruct.h:103
s_plane::origin
t_pt3 origin
Definition: rtstruct.h:52
t_plane
struct s_plane t_plane
s_cube::size
float size
Definition: rtstruct.h:108
s_cam::pos
t_pt3 pos
Definition: rtstruct.h:132
s_cam::rotate_left
bool rotate_left
Definition: rtstruct.h:146
s_cone::z
t_vec3 z
Definition: rtstruct.h:78
t_cube
struct s_cube t_cube
s_texture::name
char * name
Definition: rtstruct.h:168
s_light::origin
t_pt3 origin
Definition: rtstruct.h:123
s_cylinder::z
t_vec3 z
Definition: rtstruct.h:86
s_shading::uv
t_vec3 uv
Definition: rtstruct.h:272
s_inter::deflected
t_ray deflected
Definition: rtstruct.h:226
s_cam::x_angle
float x_angle
Definition: rtstruct.h:136
s_obj::name
char * name
Definition: rtstruct.h:249
s_plane
Definition: rtstruct.h:50
s_obj::get_uv
t_vec3(* get_uv)(t_inter *)
Definition: rtstruct.h:258
s_csg::origin
t_pt3 origin
Definition: rtstruct.h:93
s_obj::x
t_vec3 * x
Definition: rtstruct.h:252
s_obj::f_gui
void(* f_gui)(void *, void *)
Definition: rtstruct.h:259
s_texture::f_texture
t_color(* f_texture)(t_material *, t_texture *, t_vec3)
Definition: rtstruct.h:170
s_light::intensity
float intensity
Definition: rtstruct.h:125
s_tore::origin
t_pt3 origin
Definition: rtstruct.h:113
s_obj::find_normal
void(* find_normal)(t_inter *)
Definition: rtstruct.h:257
t_vec3
struct s_vec3 t_vec3
s_material::spec_idx
float spec_idx
Definition: rtstruct.h:195
s_inter::point
t_pt3 point
Definition: rtstruct.h:224
s_cylinder::size
float size
Definition: rtstruct.h:88
s_cam::lock_pos
bool lock_pos
Definition: rtstruct.h:149
t_tore
struct s_tore t_tore
s_cylinder::x
t_vec3 x
Definition: rtstruct.h:84
s_vec3::z
float z
Definition: rtstruct.h:34
s_texture::dir
char * dir
Definition: rtstruct.h:169
s_csg::z
t_vec3 z
Definition: rtstruct.h:96
s_sphere::x
t_vec3 x
Definition: rtstruct.h:66
s_tore
Definition: rtstruct.h:111
s_plane::p1
t_vec2 p1
Definition: rtstruct.h:57
s_cube::z
t_vec3 z
Definition: rtstruct.h:105
s_cam::lock
bool lock
Definition: rtstruct.h:148
s_material::name
char * name
Definition: rtstruct.h:191
s_cam::move_backward
bool move_backward
Definition: rtstruct.h:139
s_inter
Definition: rtstruct.h:218
color.h
s_cam::move_downward
bool move_downward
Definition: rtstruct.h:143
s_plane::p2
t_vec2 p2
Definition: rtstruct.h:58
t_pt3
t_vec3 t_pt3
Definition: rtstruct.h:37
s_cone
Definition: rtstruct.h:71
s_obj::type
int type
Definition: rtstruct.h:247
s_cone::origin
t_pt3 origin
Definition: rtstruct.h:73
s_cam::strafe_left
bool strafe_left
Definition: rtstruct.h:140
s_texture::height
int height
Definition: rtstruct.h:173
s_cone::theta
float theta
Definition: rtstruct.h:75
s_material::color_specular
t_color color_specular
Definition: rtstruct.h:193
s_plane::size
t_vec2 size
Definition: rtstruct.h:56
s_texture::bpp
char bpp
Definition: rtstruct.h:174
s_material::refraction_color
t_color refraction_color
Definition: rtstruct.h:197
s_obj::anim
void * anim
Definition: rtstruct.h:255
s_cube::max_corner
t_vec3 max_corner
Definition: rtstruct.h:107
t_sphere
struct s_sphere t_sphere
s_material::spec_power
float spec_power
Definition: rtstruct.h:196
s_texture::pixels
char * pixels
Definition: rtstruct.h:171
s_cube::origin
t_pt3 origin
Definition: rtstruct.h:102
s_cam::rotate_up
bool rotate_up
Definition: rtstruct.h:144
t_color
struct s_color t_color
s_material::color_diffuse
t_color color_diffuse
Definition: rtstruct.h:192
s_inter::ray
t_ray ray
Definition: rtstruct.h:223
s_obj::shape
void * shape
Definition: rtstruct.h:248
s_sphere::y
t_vec3 y
Definition: rtstruct.h:67
s_cam::move_forward
bool move_forward
Definition: rtstruct.h:138
s_shading::light
t_light light
Definition: rtstruct.h:265
s_vec2
Definition: rtstruct.h:24
s_light
Definition: rtstruct.h:121