This repository has been archived by the owner on Feb 5, 2020. It is now read-only.
forked from aaswenson/FinalProject_759
-
Notifications
You must be signed in to change notification settings - Fork 0
/
save_alg.txt
107 lines (78 loc) · 2.86 KB
/
save_alg.txt
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
96
97
98
99
100
101
102
103
104
105
106
107
// x goes first
tmin = (x_surfs[0] - x_0) * dir_inv[0];
tmax = (x_surfs[1] - x_0) * dir_inv[0];
// if necessary swap within x
if (tmax < tmin){
savet = tmax;
tmax = tmin;
tmin = savet;
}
// distance to cross in y
float tymin = (y_surfs[0] - y_0) * dir_inv[1];
float tymax = (y_surfs[1] - y_0) * dir_inv[1];
// if necessary swap within y
if (tymax < tymin){
savet = tymax;
tymax = tymin;
tymin = savet;
}
if ((tmin > tymax) || (tymin > tmax)){
intersect = 0;
}
// swap in between x and y if necesary
if (tymin > tmin){
tmin = tymin;
}
if (tymax < tmax){
tmax = tymax;
}
// distance to cross in z
float tzmin = (z_surfs[0] - z_0) * dir_inv[2];
float tzmax = (z_surfs[1] - z_0) * dir_inv[2];
// if necessary swap within z
if (tzmax < tzmin){
savet = tzmax;
tzmax = tzmin;
tzmin = savet;
}
if ((tmin > tzmax) || (tzmin > tmax)){
intersect = 0;
}
// swap in between y and z if necessary
if (tzmin > tmin){
tmin = tzmin;
}
if (tzmax < tmax){
tmax = tzmax;
}
// x goes first
float txmin = (x_surfs[0] - x_0) * dir_inv[0];
float txmax = (x_surfs[1] - x_0) * dir_inv[0];
// distance to cross in y
float tymin = (y_surfs[0] - y_0) * dir_inv[1];
float tymax = (y_surfs[1] - y_0) * dir_inv[1];
// distance to cross in z
float tzmin = (z_surfs[0] - z_0) * dir_inv[2];
float tzmax = (z_surfs[1] - z_0) * dir_inv[2];
// if necessary swap within x,y,z
if (txmax < txmin){
savet = txmax;
txmax = txmin;
txmin = savet;
}
if (tymax < tymin){
savet = tymax;
tymax = tymin;
tymin = savet;
}
if (tzmax < tzmin){
savet = tzmax;
tzmax = tzmin;
tzmin = savet;
}
// get min of tmax/tmin for x,y,z
tmax = fminf(txmax, fminf(tymax, tzmax));
tmin = fminf(txmin, fminf(tymin, tzmin));
if( (tmin > tymax) || (tymin > tmax)){intersect = 0;}
if( (tmin > tzmax) || (tzmin > tmax)){intersect = 0;}
if((tmin < 0 && tmax < 0)){intersect = 0;}