-
Notifications
You must be signed in to change notification settings - Fork 76
/
Copy pathray.cpp
148 lines (138 loc) · 2.89 KB
/
ray.cpp
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/******************************************************************************
This source code accompanies the Journal of Graphics Tools paper:
"Fast Ray / Axis-Aligned Bounding Box Overlap Tests using Ray Slopes"
by Martin Eisemann, Thorsten Grosch, Stefan Müller and Marcus Magnor
Computer Graphics Lab, TU Braunschweig, Germany and
University of Koblenz-Landau, Germany
Parts of this code are taken from
"Fast Ray-Axis Aligned Bounding Box Overlap Tests With Pluecker Coordinates"
by Jeffrey Mahovsky and Brian Wyvill
Department of Computer Science, University of Calgary
This source code is public domain, but please mention us if you use it.
******************************************************************************/
#include <math.h>
#include "ray.h"
void make_ray(float x, float y, float z, float i, float j, float k, ray *r)
{
//common variables
r->x = x;
r->y = y;
r->z = z;
r->i = i;
r->j = j;
r->k = k;
r->ii = 1.0f/i;
r->ij = 1.0f/j;
r->ik = 1.0f/k;
//ray slope
r->ibyj = r->i * r->ij;
r->jbyi = r->j * r->ii;
r->jbyk = r->j * r->ik;
r->kbyj = r->k * r->ij;
r->ibyk = r->i * r->ik;
r->kbyi = r->k * r->ii;
r->c_xy = r->y - r->jbyi * r->x;
r->c_xz = r->z - r->kbyi * r->x;
r->c_yx = r->x - r->ibyj * r->y;
r->c_yz = r->z - r->kbyj * r->y;
r->c_zx = r->x - r->ibyk * r->z;
r->c_zy = r->y - r->jbyk * r->z;
//ray slope classification
if(i < 0)
{
if(j < 0)
{
if(k < 0)
{
r->classification = MMM;
}
else if(k > 0){
r->classification = MMP;
}
else//(k >= 0)
{
r->classification = MMO;
}
}
else//(j >= 0)
{
if(k < 0)
{
r->classification = MPM;
if(j==0)
r->classification = MOM;
}
else//(k >= 0)
{
if((j==0) && (k==0))
r->classification = MOO;
else if(k==0)
r->classification = MPO;
else if(j==0)
r->classification = MOP;
else
r->classification = MPP;
}
}
}
else//(i >= 0)
{
if(j < 0)
{
if(k < 0)
{
r->classification = PMM;
if(i==0)
r->classification = OMM;
}
else//(k >= 0)
{
if((i==0) && (k==0))
r->classification = OMO;
else if(k==0)
r->classification = PMO;
else if(i==0)
r->classification = OMP;
else
r->classification = PMP;
}
}
else//(j >= 0)
{
if(k < 0)
{
if((i==0) && (j==0))
r->classification = OOM;
else if(i==0)
r->classification = OPM;
else if(j==0)
r->classification = POM;
else
r->classification = PPM;
}
else//(k > 0)
{
if(i==0)
{
if(j==0)
r->classification = OOP;
else if(k==0)
r->classification = OPO;
else
r->classification = OPP;
}
else
{
if((j==0) && (k==0))
r->classification = POO;
else if(j==0)
r->classification = POP;
else if(k==0)
r->classification = PPO;
else
r->classification = PPP;
}
}
}
}
}