hit.c
 1  /* ************************************************************************** */
 2  /*                                                                            */
 3  /*                                                        :::      ::::::::   */
 4  /*   hit.c                                              :+:      :+:    :+:   */
 5  /*                                                    +:+ +:+         +:+     */
 6  /*   By: salee2 <salee2@student.42seoul.kr>         +#+  +:+       +#+        */
 7  /*                                                +#+#+#+#+#+   +#+           */
 8  /*   Created: 2023/05/24 20:22:02 by salee2            #+#    #+#             */
 9  /*   Updated: 2023/05/24 20:22:03 by salee2           ###   ########.fr       */
10  /*                                                                            */
11  /* ************************************************************************** */
12  
13  #include "include/minirt.h"
14  
15  t_hit	hit_(double t_max)
16  {
17  	t_hit	this;
18  
19  	this.t_min = EPSILON;
20  	this.t_max = t_max;
21  	return (this);
22  }
23  
24  void	init_intersect_object(t_bool (*intersect_object[OBJECT_TYPE_SIZE])())
25  {
26  	intersect_object[CONE] = intersect_ray_cone;
27  	intersect_object[PLANE] = intersect_ray_plane;
28  	intersect_object[SPHERE] = intersect_ray_sphere;
29  	intersect_object[CYLINDER] = intersect_ray_cylinder;
30  	return ;
31  }
32  
33  t_bool	hit_objects(t_object *objects, t_ray *ray, t_hit *hit)
34  {
35  	t_bool	is_hit;
36  
37  	is_hit = FALSE;
38  	t_bool (*intersect_object[OBJECT_TYPE_SIZE])();
39  	init_intersect_object(intersect_object);
40  	while (objects)
41  	{
42  		if (intersect_object[objects->type](objects, ray, hit)) {
43  			is_hit = TRUE;
44  		}
45  		objects = objects->next;
46  	}
47  	return (is_hit);
48  }