cone.c
1 /* ************************************************************************** */ 2 /* */ 3 /* ::: :::::::: */ 4 /* cone.c :+: :+: :+: */ 5 /* +:+ +:+ +:+ */ 6 /* By: salee2 <salee2@student.42seoul.kr> +#+ +:+ +#+ */ 7 /* +#+#+#+#+#+ +#+ */ 8 /* Created: 2023/05/24 20:21:24 by salee2 #+# #+# */ 9 /* Updated: 2023/05/24 20:21:26 by salee2 ### ########.fr */ 10 /* */ 11 /* ************************************************************************** */ 12 13 #include "include/minirt.h" 14 15 t_cone *cone_(t_point3 center, t_vec3 normal, double radius, double height) 16 { 17 t_cone *this; 18 19 this = (t_cone *)malloc((sizeof(t_cone))); 20 if (this == NULL) 21 return (NULL); 22 this->normal = norm(normal); 23 this->base_center = center; 24 this->tip_center = add(this->base_center, scl_mul(height, this->normal)); 25 this->h_dir = sub(this->base_center, this->tip_center); 26 this->h_normal = norm(this->h_dir); 27 this->height = height; 28 this->radius = radius; 29 this->radius_sq = radius * radius; 30 return (this); 31 } 32 33 t_bool intersect_ray_cone(t_object *object, t_ray *ray, t_hit *hit) 34 { 35 t_bool is_inter; 36 37 is_inter = FALSE; 38 is_inter += intersect_cone_surface(object, ray, hit); 39 is_inter += intersect_cone_base(object, ray, hit); 40 return (is_inter); 41 }