-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprimitive_intersection.c
72 lines (67 loc) · 2.94 KB
/
primitive_intersection.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* primitive_intersection.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ajaehaer <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/12 15:00:20 by ajaehaer #+# #+# */
/* Updated: 2019/03/30 15:52:11 by ejommy ### ########.fr */
/* */
/* ************************************************************************** */
#include "engine_render.h"
t_intersection simplified_ray_primitive_intersection(t_ray r,
t_primitive *p)
{
t_intersection res;
res.z = 1. / 0.;
if (p->type == TRIANGLE)
res = simplified_ray_triangle_intersection(r,
*((t_triangle*)p->primitive));
else if (p->type == SPHERE)
res = simplified_ray_sphere_intersection(r, *((t_sphere*)p->primitive));
else if (p->type == CYLINDER)
res = simplified_ray_cylinder_intersection(r,
*((t_cylinder*)p->primitive));
else if (p->type == CIRCLE)
res = simplified_ray_circle_intersection(r, *((t_circle*)p->primitive));
else if (p->type == CONE)
res = simplified_ray_cone_intersection(r, *((t_cone*)p->primitive));
else if (p->type == PLANE)
res = simplified_ray_plane_intersection(r,
*((t_triangle*)p->primitive));
else if (p->type == PARABOLOID)
res = simplified_ray_paraboloid_intersection(r,
*((t_paraboloid*)p->primitive));
else if (p->type == TORUS)
res = simplified_ray_torus_intersection(r, *((t_torus*)p->primitive));
res.primitive = p;
return (res);
}
t_intersection ray_primitive_intersection(t_ray ray,
t_primitive *primitive)
{
t_intersection res;
res.z = 1. / 0.;
if (primitive->type == TRIANGLE)
res = ray_triangle_intersection(ray,
*((t_triangle*)primitive->primitive));
else if (primitive->type == SPHERE)
res = ray_sphere_intersection(ray, *((t_sphere*)primitive->primitive));
else if (primitive->type == CYLINDER)
res = ray_cylinder_intersection(ray,
*((t_cylinder*)primitive->primitive));
else if (primitive->type == CIRCLE)
res = ray_circle_intersection(ray, *((t_circle*)primitive->primitive));
else if (primitive->type == CONE)
res = ray_cone_intersection(ray, *((t_cone*)primitive->primitive));
else if (primitive->type == PLANE)
res = ray_plane_intersection(ray, *((t_triangle*)primitive->primitive));
else if (primitive->type == PARABOLOID)
res = ray_paraboloid_intersection(ray,
*((t_paraboloid*)primitive->primitive));
else if (primitive->type == TORUS)
res = ray_torus_intersection(ray, *((t_torus*)primitive->primitive));
res.primitive = primitive;
return (res);
}