30 template <
typename Real>
57 Polygon
const& polygon, Result&
result);
65 template <
typename Real>
70 template <
typename Real>
77 mPolygon[ 0] = { 6, { 1, 5, 4, 6, 2, 3 } };
78 mPolygon[ 1] = { 6, { 0, 2, 3, 1, 5, 4 } };
79 mPolygon[ 2] = { 6, { 0, 2, 3, 7, 5, 4 } };
80 mPolygon[ 3] = { 6, { 0, 4, 6, 2, 3, 1 } };
81 mPolygon[ 4] = { 4, { 0, 2, 3, 1 } };
82 mPolygon[ 5] = { 6, { 0, 2, 3, 7, 5, 1 } };
83 mPolygon[ 6] = { 6, { 0, 4, 6, 7, 3, 1 } };
84 mPolygon[ 7] = { 6, { 0, 2, 6, 7, 3, 1 } };
85 mPolygon[ 8] = { 6, { 0, 2, 6, 7, 5, 1 } };
86 mPolygon[ 9] = { 6, { 0, 1, 5, 4, 6, 2 } };
87 mPolygon[10] = { 4, { 0, 1, 5, 4 } };
88 mPolygon[11] = { 6, { 0, 1, 3, 7, 5, 4 } };
89 mPolygon[12] = { 4, { 0, 4, 6, 2 } };
90 mPolygon[13] = { 0, { 0 } };
91 mPolygon[14] = { 4, { 1, 3, 7, 5 } };
92 mPolygon[15] = { 6, { 0, 4, 6, 7, 3, 2 } };
93 mPolygon[16] = { 4, { 2, 6, 7, 3 } };
94 mPolygon[17] = { 6, { 1, 3, 2, 6, 7, 5 } };
95 mPolygon[18] = { 6, { 0, 1, 5, 7, 6, 2 } };
96 mPolygon[19] = { 6, { 0, 1, 5, 7, 6, 4 } };
97 mPolygon[20] = { 6, { 0, 1, 3, 7, 6, 4 } };
98 mPolygon[21] = { 6, { 0, 4, 5, 7, 6, 2 } };
99 mPolygon[22] = { 4, { 4, 5, 7, 6 } };
100 mPolygon[23] = { 6, { 1, 3, 7, 6, 4, 5 } };
101 mPolygon[24] = { 6, { 0, 4, 5, 7, 3, 2 } };
102 mPolygon[25] = { 6, { 2, 6, 4, 5, 7, 3 } };
103 mPolygon[26] = { 6, { 1, 3, 2, 6, 4, 5 } };
107 mMod3 = { 0, 1, 2, 0 };
110 template <
typename Real>
119 box.GetCenteredForm(boxCenter, boxExtent);
123 Real DdCmV =
Dot(cone.ray.direction, CmV);
125 boxExtent[0] *
std::abs(cone.ray.direction[0]) +
126 boxExtent[1] *
std::abs(cone.ray.direction[1]) +
127 boxExtent[2] *
std::abs(cone.ray.direction[2]);
128 if (DdCmV + radius <= (Real)0)
131 result.intersect =
false;
137 if (cone.height < std::numeric_limits<Real>::max())
139 if (DdCmV - radius >= cone.height)
143 result.intersect =
false;
153 (CmV[0] < -boxExtent[0] ? 2 : (CmV[0] > boxExtent[0] ? 0 : 1)),
154 (CmV[1] < -boxExtent[1] ? 2 : (CmV[1] > boxExtent[1] ? 0 : 1)),
155 (CmV[2] < -boxExtent[2] ? 2 : (CmV[2] > boxExtent[2] ? 0 : 1))
157 int lookup = index[0] + 3 * index[1] + 9 * index[2];
161 result.intersect =
true;
165 Polygon
const& polygon = mPolygon[lookup];
167 DoQuery(boxExtent, cone.cosAngleSqr, cone.ray.direction, CmV, DdCmV,
172 template <
typename Real>
180 Real DdPmV[8], sqrDdPmV[8], sqrLenPmV[8],
q;
181 int iMax = -1, jMax = -1;
182 for (
int i = 0; i < polygon.numPoints; ++i)
184 int j = polygon.indices[i];
185 X[j][0] = (j & 1 ? boxExtent[0] : -boxExtent[0]);
186 X[j][1] = (j & 2 ? boxExtent[1] : -boxExtent[1]);
187 X[j][2] = (j & 4 ? boxExtent[2] : -boxExtent[2]);
188 DdPmV[j] =
Dot(D, X[j]) + DdCmV;
189 if (DdPmV[j] > (Real)0)
192 sqrDdPmV[j] = DdPmV[j] * DdPmV[j];
193 sqrLenPmV[j] =
Dot(PmV[j], PmV[j]);
194 q = sqrDdPmV[j] - cosSqr * sqrLenPmV[j];
197 result.intersect =
true;
204 sqrDdPmV[j] * sqrLenPmV[jMax] > sqrDdPmV[jMax] * sqrLenPmV[j])
219 result.intersect =
false;
224 Real maxSqrLenPmV = sqrLenPmV[jMax];
225 Real maxDdPmV = DdPmV[jMax];
228 int k0, k1, k2, jDiff;
229 Real
s, fder, numer, denom, DdMmV, det;
233 int iNext = (iMax < polygon.numPoints - 1 ? iMax + 1 : 0);
234 int jNext = polygon.indices[iNext];
235 jDiff = jNext - jMax;
236 s = (jDiff > 0 ? (Real)1 : (Real)-1);
238 fder = s * (D[k0] * maxSqrLenPmV - maxDdPmV * maxPmV[k0]);
246 numer = maxPmV[k1] * maxPmV[k1] + maxPmV[k2] * maxPmV[k2];
247 denom = D[k1] * maxPmV[k1] + D[k2] * maxPmV[k2];
248 MmV[k0] = numer * D[k0];
249 MmV[k1] = denom * (maxX[k1] + CmV[k1]);
250 MmV[k2] = denom * (maxX[k2] + CmV[k2]);
254 q = DdMmV * DdMmV - cosSqr *
Dot(MmV, MmV);
257 result.intersect =
true;
265 det = s * (D[k1] * maxPmV[k2] - D[k2] * maxPmV[k1]);
266 result.intersect = (det <= (Real)0);
271 int iPrev = (iMax > 0 ? iMax - 1 : polygon.numPoints - 1);
272 int jPrev = polygon.indices[iPrev];
273 jDiff = jMax - jPrev;
274 s = (jDiff > 0 ? (Real)1 : (Real)-1);
276 fder = -s * (D[k0] * maxSqrLenPmV - maxDdPmV * maxPmV[k0]);
284 numer = maxPmV[k1] * maxPmV[k1] + maxPmV[k2] * maxPmV[k2];
285 denom = D[k1] * maxPmV[k1] + D[k2] * maxPmV[k2];
286 MmV[k0] = numer * D[k0];
287 MmV[k1] = denom * (maxX[k1] + CmV[k1]);
288 MmV[k2] = denom * (maxX[k2] + CmV[k2]);
292 q = DdMmV * DdMmV - cosSqr *
Dot(MmV, MmV);
295 result.intersect =
true;
303 det = s * (D[k1] * maxPmV[k2] - D[k2] * maxPmV[k1]);
304 result.intersect = (det <= (Real)0);
308 result.intersect =
false;
std::array< int, 6 > indices
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
std::array< int, 4 > mMod3
std::array< Polygon, 27 > mPolygon
GLdouble GLdouble GLdouble GLdouble q
Result operator()(Type0 const &primitive0, Type1 const &primitive1)