20 template <
typename Real>
50 std::array<Vector3<Real>, 2>
point;
62 template <
typename Real>
68 parameter.fill((Real)0);
69 point.fill({ (Real)0, (Real)0, (Real)0 });
72 template <
typename Real>
78 DoQuery(line.origin, line.direction, cone, result);
82 result.point[0] = line.origin + result.parameter[0] * line.direction;
83 result.point[1] = result.point[0];
86 result.point[0] = line.origin + result.parameter[0] * line.direction;
87 result.point[1] = line.origin + result.parameter[1] * line.direction;
90 result.point[0] = line.origin + result.parameter[0] * line.direction;
91 result.point[1] = line.direction;
94 result.point[0] = line.origin + result.parameter[1] * line.direction;
95 result.point[1] = -line.direction;
98 result.point[0] = line.origin;
99 result.point[1] = line.direction;
107 template <
typename Real>
134 Real DdU =
Dot(cone.
ray.direction, lineDirection);
135 Real DdPmV =
Dot(cone.
ray.direction, PmV);
136 Real UdPmV =
Dot(lineDirection, PmV);
137 Real PmVdPmV =
Dot(PmV, PmV);
139 Real c2 = DdU * DdU - cosAngleSqr;
140 Real c1 = DdU * DdPmV - cosAngleSqr * UdPmV;
141 Real c0 = DdPmV * DdPmV - cosAngleSqr * PmVdPmV;
146 Real discr = c1 * c1 - c0 * c2;
151 result.intersect =
false;
155 else if (discr > (Real)0)
160 Real root = sqrt(discr);
161 Real invC2 = ((Real)1) / c2;
162 int numParameters = 0;
164 t = (-c1 - root) * invC2;
165 if (DdU * t + DdPmV >= (Real)0)
167 result.parameter[numParameters++] =
t;
170 t = (-c1 + root) * invC2;
171 if (DdU * t + DdPmV >= (Real)0)
173 result.parameter[numParameters++] =
t;
176 if (numParameters == 2)
180 result.intersect =
true;
182 if (result.parameter[0] > result.parameter[1])
184 std::swap(result.parameter[0], result.parameter[1]);
187 else if (numParameters == 1)
192 result.intersect =
true;
196 result.parameter[1] = std::numeric_limits<Real>::max();
201 result.parameter[1] = result.parameter[0];
202 result.parameter[0] = -std::numeric_limits<Real>::max();
211 result.intersect =
false;
222 if (DdU * t + DdPmV >= (Real)0)
224 result.intersect =
true;
226 result.parameter[0] =
t;
227 result.parameter[1] =
t;
231 result.intersect =
false;
237 else if (c1 != (Real)0)
240 t = -((Real)0.5)*c0 / c1;
241 if (DdU * t + DdPmV >= (Real)0)
245 result.intersect =
true;
249 result.parameter[0] =
t;
250 result.parameter[1] = std::numeric_limits<Real>::max();
255 result.parameter[0] = -std::numeric_limits<Real>::max();
256 result.parameter[1] =
t;
263 result.intersect =
false;
268 else if (c0 != (Real)0)
271 result.intersect =
false;
278 result.intersect =
true;
280 result.parameter[0] = -std::numeric_limits<Real>::max();
281 result.parameter[1] = +std::numeric_limits<Real>::max();
284 if (cone.
height < std::numeric_limits<Real>::max())
289 Real invDdU = ((Real)1) / DdU;
290 std::array<Real, 2> hInterval;
293 hInterval[0] = -DdPmV * invDdU;
294 hInterval[1] = (cone.
height - DdPmV) * invDdU;
298 hInterval[0] = (cone.
height - DdPmV) * invDdU;
299 hInterval[1] = -DdPmV * invDdU;
303 auto iiResult = iiQuery(result.parameter, hInterval);
304 result.intersect = (iiResult.numIntersections > 0);
305 result.type = iiResult.numIntersections;
306 result.parameter = iiResult.overlap;
308 else if (result.intersect)
312 result.intersect =
false;
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
std::array< Vector3< Real >, 2 > point
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
std::array< Real, 2 > parameter
GLint GLint GLsizei GLint GLenum GLenum type