-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinter.c
More file actions
95 lines (86 loc) · 2.01 KB
/
inter.c
File metadata and controls
95 lines (86 loc) · 2.01 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
** inter.c for rtv1 in /home/thibaud/rendu/MUL_2013_rtv1
**
** Made by thibaud
** Login <thibaud@epitech.net>
**
** Started on Wed Feb 26 14:21:52 2014 thibaud
** Last update Fri Jun 6 14:53:14 2014 lhomme
*/
#include "rt.h"
float inter_sphere(t_vec3 *pos, t_vec3 *dir, int R)
{
float delta;
float k1;
float k2;
float c[3];
k1 = ZERO;
c[0] = (dir->x * dir->x) + (dir->y * dir->y) + (dir->z * dir->z);
c[1] = 2 * ((pos->x * dir->x) + (pos->y * dir->y) + (pos->z * dir->z));
c[2] = (pos->x * pos->x) + (pos->y * pos->y) + (pos->z * pos->z) - (R * R);
delta = (c[1] * c[1]) - (4 * c[0] * c[2]);
if (delta >= ZERO)
{
k1 = (((c[1] * (-1)) - sqrt(delta)) / (2 * c[0]));
k2 = ((((-1) * c[1]) + sqrt(delta)) / (2 * c[0]));
if (k2 < k1 && k2 >= ZERO)
k1 = k2;
}
else
return (-1);
return (k1);
}
float inter_plan(t_vec3 *pos, t_vec3 *dir, int R)
{
float k;
(void)R;
k = ZERO;
if (dir->z != ZERO)
k = (-pos->z / dir->z);
return (k);
}
float cut_obj(float k1, t_vec3 *pos, t_vec3 *dir)
{
t_eye eye_tmp;
t_vec3 *inter;
float x;
float y;
x = ZERO - 800;
y = ZERO;
eye_tmp.pos = pos;
eye_tmp.dir = dir;
inter = xmalloc(sizeof(*inter));
inter = inter_obj(inter, &eye_tmp, k1);
if (inter->z < x || inter->z > y)
{
free(inter);
return (ZERO);
}
free(inter);
return (k1);
}
float inter_cone(t_vec3 *pos, t_vec3 *dir, int R)
{
float delta;
float k1;
float k2;
float c[3];
k1 = -1;
k2 = 0;
c[0] = (pow(dir->x, 2) + pow(dir->y, 2)) - pow(dir->z, 2)
* tan(rad_conv(R));
c[1] = (pos->x * dir->x) + (pos->y * dir->y) -
((pos->z * dir->z) * tan(rad_conv(R)));
c[1] *= 2;
c[2] = (pow(pos->x, 2) + pow(pos->y, 2)) -
pow(pos->z, 2) * tan(rad_conv(R));
delta = pow(c[1], 2) - 4 * (c[0] * c[2]);
if (delta >= ZERO)
{
k1 = (((c[1] * (-1)) - sqrt(delta)) / (2 * c[0]));
k2 = ((((-1) * c[1]) + sqrt(delta)) / (2 * c[0]));
if (k2 < k1 && k2 >= ZERO)
k1 = k2;
}
return (k1);
}