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