minirt.h
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* minirt.h :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: salee2 <salee2@student.42seoul.kr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/05/24 20:23:52 by salee2 #+# #+# */ 9 /* Updated: 2023/05/24 20:23:53 by salee2 ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #ifndef MINIRT_MINIRT_H 14 #define MINIRT_MINIRT_H 15 16 #include "define.h" 17 #include "enum.h" 18 #include "typedef.h" 19 #include "include.h" 20 21 t_vec2 vec2_(double x, double y); 22 23 t_vec3 vec3_(double ai, double bj, double ck); 24 25 t_vec3 add(t_vec3 u, t_vec3 v); 26 27 t_vec3 sub(t_vec3 u, t_vec3 v); 28 29 t_vec3 scl_mul(double k, t_vec3 vector); 30 31 double mag_sq(t_vec3 vec); 32 33 double mag(t_vec3 vec); 34 35 t_vec3 norm(t_vec3 vector); 36 37 double dot(t_vec3 u, t_vec3 v); 38 39 t_vec3 cross(t_vec3 u, t_vec3 v); 40 41 42 43 t_sphere* sphere_(t_point3 center, double radius); 44 45 //t_hit intersect_ray_collision(t_ray* ray, t_sphere* sphere); 46 47 48 t_raytracer raytracer_(const int width, const int height); 49 50 t_vec3 screen_to_world(t_vec2 pos_screen, t_raytracer* raytracer); 51 52 t_point3 point3_(double x, double y, double z); 53 54 t_color3 color3_(double r, double g, double b); 55 56 57 t_ray ray_(t_point3 origin, t_vec3 dir); 58 59 t_vec3 ray_at(double t, t_ray* ray); 60 61 62 63 int ray_color(t_scene* scene); 64 65 66 t_bool intersect_ray_sphere(t_object* object, t_ray* ray, t_hit* hit); 67 68 69 t_canvas canvas_(int height); 70 71 //t_camera camera_(t_canvas* canvas, t_vec3 origin); 72 73 t_camera 74 camera_(t_canvas* canvas, t_point3 look_from, t_point3 look_at, double h_fov); 75 76 t_ray primary_ray(t_camera* cam, t_vec2 xy); 77 78 //t_ray primary_ray(t_camera* cam, double u, double v); 79 80 void set_hit_face_normal(t_ray* ray, t_hit* hit); 81 82 83 t_object* object_(t_object_type type, void* element, t_color3 albedo); 84 85 86 void append_object(t_object** list, t_object* object); 87 88 t_object* back_object(t_object* list); 89 90 t_bool hit_objects(t_object* objects, t_ray* ray, t_hit* hit); 91 92 93 94 t_light* light_point(t_point3 origin, t_color3 color, double bright_ratio); 95 96 t_hit hit_(double t_max); 97 98 //t_hit hit_(void); 99 100 101 t_vec3 hadam_prod(t_vec3 u, t_vec3 v); 102 103 t_vec3 elem_min(t_vec3 u, t_vec3 v); 104 105 t_color3 phong_lighting(t_scene* scene); 106 107 t_color3 point_light_get(t_scene* scene, t_light* light); 108 109 void render(t_scene* scene); 110 111 112 t_cylinder* 113 cylinder_(t_point3 center, t_vec3 dir, double radius, double height); 114 115 t_bool intersect_ray_cylinder(t_object* object, t_ray* ray, t_hit* hit); 116 117 118 t_plane* plane_(t_point3 point, t_vec3 normal); 119 120 t_bool intersect_ray_plane(t_object* object, t_ray* ray, t_hit* hit); 121 122 t_scene* scene_(void); 123 124 void write_color(t_color3 color); 125 126 void update_hit(t_ray* ray, t_hit* hit, t_point3 center, t_color3 albedo); 127 128 t_bool intersect_cylinder_base(t_object* object, t_ray* ray, t_hit* hit, 129 enum e_component type); 130 131 t_bool intersect_cylinder_surface(t_object* object, t_ray* ray, t_hit* hit); 132 133 t_cone* cone_(t_point3 center, t_vec3 dir, double radius, double height); 134 135 t_bool intersect_cone_surface(t_object* object, t_ray* ray, t_hit* hit); 136 137 t_bool intersect_ray_cone(t_object* object, t_ray* ray, t_hit* hit); 138 139 t_bool intersect_cone_base(t_object* object, t_ray* ray, t_hit* hit); 140 141 t_bool intersect_cone_surface(t_object* object, t_ray* ray, t_hit* hit); 142 143 t_vec3 clamp_vec3(t_vec3 value, t_vec3 min, t_vec3 max); 144 145 146 int red_cross(void); 147 148 int key_hook(int keycode, t_vars* vars); 149 150 void get_minirt_image(t_vars* vars); 151 152 int ft_atoi(const char* str, int* is_error, double* sign); 153 154 double ft_atof(const char* str); 155 156 int ft_isdigit(int c); 157 158 int create_trgb(t_color3 color); 159 160 t_color3 get_diffuse(t_vec3 normal, t_vec3 light_dir, t_color3 color); 161 162 t_color3 get_specular(t_scene* scene, t_vec3 light_dir, t_color3 color); 163 164 void free_scene(t_scene* scene); 165 166 167 168 #endif //MINIRT_MINIRT_H