19 template <
typename Real>
35 template <
typename Real>
56 int TestVertexRegion(Real cx, Real cy, Real vx, Real vy, Real ex,
57 Real ey, Real& ix, Real& iy, Real radius, Real& contactTime);
59 int TestEdgeRegion(Real cx, Real cy, Real vx, Real vy, Real ex, Real ey,
60 Real& ix, Real& iy, Real radius, Real& contactTime);
64 template <
typename Real>
70 auto pbResult = pbQuery(circle.center, box);
72 result.intersect = (pbResult.distance <= circle.radius);
78 template <
typename Real>
88 Vector2<Real> relativeVelocity = circleVelocity - boxVelocity;
89 Real cx =
Dot(diff, box.axis[0]);
90 Real cy =
Dot(diff, box.axis[1]);
91 Real vx =
Dot(relativeVelocity, box.axis[0]);
92 Real vy =
Dot(relativeVelocity, box.axis[1]);
93 Real ex = box.extent[0];
94 Real ey = box.extent[1];
104 type = TestVertexRegion(cx, cy, vx, vy, ex, ey, ix, iy,
105 circle.radius, result.contactTime);
110 type = TestEdgeRegion(cx, cy, vx, vy, ex, ey, ix, iy,
111 circle.radius, result.contactTime);
116 type = TestVertexRegion(cx, -cy, vx, -vy, ex, ey, ix, iy,
117 circle.radius, result.contactTime);
126 type = TestEdgeRegion(cy, cx, vy, vx, ey, ex, iy, ix,
127 circle.radius, result.contactTime);
133 result.intersect =
true;
134 result.contactTime = (Real)0;
135 result.contactPoint = circle.center;
141 type = TestEdgeRegion(-cy, cx, -vy, vx, ey, ex, iy, ix,
142 circle.radius, result.contactTime);
151 type = TestVertexRegion(-cx, cy, -vx, vy, ex, ey, ix, iy,
152 circle.radius, result.contactTime);
158 type = TestEdgeRegion(-cx, cy, -vx, vy, ex, ey, ix, iy,
159 circle.radius, result.contactTime);
165 type = TestVertexRegion(-cx, -cy, -vx, -vy, ex, ey, ix, iy,
166 circle.radius, result.contactTime);
172 if (type != 1 || result.contactTime > maxTime)
174 result.intersect =
false;
178 result.intersect =
true;
179 result.contactPoint = box.center + ix*box.axis[0] + iy*box.axis[1];
183 template <
typename Real>
185 Real cx, Real cy, Real vx, Real vy, Real ex, Real ey, Real& ix, Real& iy,
186 Real radius, Real& contactTime)
190 Real rsqr = radius*radius;
191 Real diff = dx*dx + dy*dy - rsqr;
195 contactTime = (Real)0;
199 Real dot = vx*dx + vy*dy;
206 Real dotPerp = vx*dy - vy*dx;
209 if (dotPerp >= (Real)0)
212 if (dotPerp <= radius*vy)
217 vsqr = vx*vx + vy*vy;
218 inv = ((Real)1) / sqrt(
std::abs(dot*dot - vsqr*diff));
219 contactTime = diff*inv / ((Real)1 - dot*inv);
229 vsqr = vx*vx + vy*vy;
231 dotPerp = vx*dy - vy*dx;
232 if (dotPerp >= (Real)0 && dotPerp*dotPerp > rsqr*vsqr)
242 if (dotPerp <= radius*vy)
245 contactTime = -(dx + radius) / vx;
246 iy = cy + contactTime*vy;
252 diff = dx*dx + dy*dy - rsqr;
253 inv = ((Real)1) / sqrt(
std::abs(dot*dot - vsqr*diff));
254 contactTime = diff*inv / ((Real)1 - dot*inv);
261 if (-dotPerp <= radius*vx)
266 vsqr = vx*vx + vy*vy;
267 inv = ((Real)1) / sqrt(
std::abs(dot*dot - vsqr*diff));
268 contactTime = diff*inv / ((Real)1 - dot*inv);
278 vsqr = vx*vx + vy*vy;
280 dotPerp = vx*dy - vy*dx;
281 if (-dotPerp >= (Real)0 && dotPerp*dotPerp > rsqr*vsqr)
291 if (-dotPerp <= radius*vx)
294 contactTime = -(dy + radius) / vy;
295 ix = cx + contactTime*vx;
301 diff = dx*dx + dy*dy - rsqr;
302 inv = ((Real)1) / sqrt(
std::abs(dot*dot - vsqr*diff));
303 contactTime = diff*inv / ((Real)1 - dot*inv);
311 template <
typename Real>
312 int FIQuery<Real, OrientedBox2<Real>,
Circle2<Real>>::TestEdgeRegion(Real cx,
313 Real cy, Real vx, Real vy, Real ex, Real ey, Real& ix, Real& iy,
314 Real radius, Real& contactTime)
317 Real xSignedDist = dx + radius;
318 if (xSignedDist >= (Real)0)
321 contactTime = (Real)0;
331 Real rsqr = radius*radius;
332 Real vsqr = vx*vx + vy*vy;
333 Real dy, dot, dotPerp, diff, inv;
338 dotPerp = vx*dy - vy*dx;
339 if (dotPerp >= (Real)0 && dotPerp*dotPerp > rsqr*vsqr)
349 if (dotPerp <= radius*vy)
352 contactTime = -xSignedDist / vx;
353 iy = cy + contactTime*vy;
359 diff = dx*dx + dy*dy - rsqr;
360 inv = ((Real)1) / sqrt(
std::abs(dot*dot - vsqr*diff));
361 contactTime = diff*inv / ((Real)1 - dot*inv);
368 dotPerp = vx*dy - vy*dx;
369 if (dotPerp <= (Real)0 && dotPerp*dotPerp > rsqr*vsqr)
379 if (dotPerp >= radius*vy)
382 contactTime = -xSignedDist / vx;
383 iy = cy + contactTime*vy;
389 diff = dx*dx + dy*dy - rsqr;
390 inv = ((Real)1) / sqrt(
std::abs(dot*dot - vsqr*diff));
391 contactTime = diff*inv / ((Real)1 - dot*inv);
Vector2< Real > contactPoint
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
DualQuaternion< Real > Dot(DualQuaternion< Real > const &d0, DualQuaternion< Real > const &d1)
Result operator()(Type0 const &primitive0, Type1 const &primitive1)
GLint GLint GLsizei GLint GLenum GLenum type