16 template <
typename Real>
31 template <
typename Real>
41 Dot(diff, frustum.rVector),
42 Dot(diff, frustum.uVector),
43 Dot(diff, frustum.dVector) };
47 if (test[0] < (Real)0)
58 if (test[1] < (Real)0)
69 Real rmin = frustum.rBound;
70 Real rmax = frustum.GetDRatio()*rmin;
71 Real umin = frustum.uBound;
72 Real umax = frustum.GetDRatio()*umin;
73 Real dmin = frustum.dMin;
74 Real dmax = frustum.dMax;
75 Real rminSqr = rmin*rmin;
76 Real uminSqr = umin*umin;
77 Real dminSqr = dmin*dmin;
78 Real minRDDot = rminSqr + dminSqr;
79 Real minUDDot = uminSqr + dminSqr;
80 Real minRUDDot = rminSqr + minUDDot;
81 Real maxRDDot = frustum.GetDRatio()*minRDDot;
82 Real maxUDDot = frustum.GetDRatio()*minUDDot;
83 Real maxRUDDot = frustum.GetDRatio()*minRUDDot;
89 Real rDot, uDot, rdDot, udDot, rudDot, rEdgeDot, uEdgeDot,
t;
104 closest[0] = test[0];
115 closest[1] = test[1];
127 else if (test[2] <= dmin)
134 closest[0] = test[0];
135 closest[1] = test[1];
140 udDot = umin*test[1] + dmin*test[2];
141 if (udDot >= maxUDDot)
144 closest[0] = test[0];
148 else if (udDot >= minUDDot)
151 uDot = dmin*test[1] - umin*test[2];
153 closest[0] = test[0];
154 closest[1] = test[1] - t*dmin;
155 closest[2] = test[2] + t*umin;
160 closest[0] = test[0];
170 rdDot = rmin*test[0] + dmin*test[2];
171 if (rdDot >= maxRDDot)
175 closest[1] = test[1];
178 else if (rdDot >= minRDDot)
181 rDot = dmin*test[0] - rmin*test[2];
183 closest[0] = test[0] - t*dmin;
184 closest[1] = test[1];
185 closest[2] = test[2] + t*rmin;
191 closest[1] = test[1];
197 rudDot = rmin*test[0] + umin*test[1] + dmin*test[2];
198 rEdgeDot = umin*rudDot - minRUDDot*test[1];
199 if (rEdgeDot >= (Real)0)
201 rdDot = rmin*test[0] + dmin*test[2];
202 if (rdDot >= maxRDDot)
206 closest[1] = test[1];
209 else if (rdDot >= minRDDot)
212 rDot = dmin*test[0] - rmin*test[2];
214 closest[0] = test[0] - t*dmin;
215 closest[1] = test[1];
216 closest[2] = test[2] + t*rmin;
222 closest[1] = test[1];
228 uEdgeDot = rmin*rudDot - minRUDDot*test[0];
229 if (uEdgeDot >= (Real)0)
231 udDot = umin*test[1] + dmin*test[2];
232 if (udDot >= maxUDDot)
235 closest[0] = test[0];
239 else if (udDot >= minUDDot)
242 uDot = dmin*test[1] - umin*test[2];
244 closest[0] = test[0];
245 closest[1] = test[1] - t*dmin;
246 closest[2] = test[2] + t*umin;
251 closest[0] = test[0];
258 if (rudDot >= maxRUDDot)
265 else if (rudDot >= minRUDDot)
268 t = rudDot / minRUDDot;
287 rDot = dmin*test[0] - rmin*test[2];
288 uDot = dmin*test[1] - umin*test[2];
289 if (rDot <= (Real)0.0)
298 udDot = umin*test[1] + dmin*test[2];
299 if (udDot >= maxUDDot)
302 closest[0] = test[0];
310 closest[0] = test[0];
311 closest[1] = test[1] - t*dmin;
312 closest[2] = test[2] + t*umin;
320 rdDot = rmin*test[0] + dmin*test[2];
321 if (rdDot >= maxRDDot)
325 closest[1] = test[1];
332 closest[0] = test[0] - t*dmin;
333 closest[1] = test[1];
334 closest[2] = test[2] + t*rmin;
339 rudDot = rmin*test[0] + umin*test[1] + dmin*test[2];
340 rEdgeDot = umin*rudDot - minRUDDot*test[1];
341 if (rEdgeDot >= (Real)0)
343 rdDot = rmin*test[0] + dmin*test[2];
344 if (rdDot >= maxRDDot)
348 closest[1] = test[1];
355 closest[0] = test[0] - t*dmin;
356 closest[1] = test[1];
357 closest[2] = test[2] + t*rmin;
362 uEdgeDot = rmin*rudDot - minRUDDot*test[0];
363 if (uEdgeDot >= (Real)0)
365 udDot = umin*test[1] + dmin*test[2];
366 if (udDot >= maxUDDot)
369 closest[0] = test[0];
377 closest[0] = test[0];
378 closest[1] = test[1] - t*dmin;
379 closest[2] = test[2] + t*umin;
384 if (rudDot >= maxRUDDot)
394 t = rudDot / minRUDDot;
405 diff = test - closest;
410 closest[0] = -closest[0];
415 closest[1] = -closest[1];
419 result.frustumClosestPoint = frustum.origin +
420 closest[0] * frustum.rVector +
421 closest[1] * frustum.uVector +
422 closest[2] * frustum.dVector;
424 result.sqrDistance =
Dot(diff, diff);
425 result.distance = sqrt(result.sqrDistance);
GLsizei GLsizei GLfloat distance
Vector3< Real > frustumClosestPoint
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)