Graphics Reference
In-Depth Information
B
A
v
d first = a .min[ i ] - b .max[ i ]
d last = a .max[ i ] - b .min[ i ]
Figure 5.38 Illustrating the distances the projection of box B travels to reach first and last
contact with the projection of the stationary box A when B is moving toward A .
and v B , can be solved using the moving version of the separating-axis test as described
in Section 5.5.2.
The problem is first cast into that of a stationary box A and a moving box B by
subtracting the velocity of A from B , giving the relative velocity v
v A . Figure
5.38 illustrates, given B moving toward A , the distances d first and d last that B must
cover to reach first and last contact with A . The times to first and last contact, t first
and t last , are then easily obtained by dividing these distances by the speed with which
B is moving toward A . These times are obtained for all three principal axes, and the
largest t first and smallest t last correspond to the intersection of the times the boxes
overlap on the three axes, if at all. If the projections of the boxes are ever found to be
nonintersecting and moving apart on an axis, the test can immediately exit with “no
intersection.”A full implementation of this test follows.
=
v B
// Intersect AABBs 'a' and 'b' moving with constant velocities va and vb.
// On intersection, return time of first and last contact in tfirst and tlast
int IntersectMovingAABBAABB(AABB a, AABB b, Vector va, Vector vb,
float &tfirst, float &tlast)
{
// Exit early if 'a' and 'b' initially overlapping
if (TestAABBAABB(a, b)) {
tfirst = tlast = 0.0f;
return 1;
}
// Use relative velocity; effectively treating 'a' as stationary
Vectorv=vb-va;
 
Search WWH ::




Custom Search