Game Development Reference
In-Depth Information
Finally, by applying the quadratic formula, we have
0 = t 2 − 2( e d )t + e e − r 2 ,
2 − 4( e e − r 2 )
2( e d ) ±
−2( e d )
t =
,
2
2( e d ) ±
4( e d ) 2 − 4( e e − r 2 )
2
t =
,
t = e d ±
( e d ) 2 + r 2 e e .
Which root do we pick? The lower number (the negative root) produces
the t value when the spheres begin intersecting. The greater number (the
positive root) is the point where the spheres cease to intersect. We are
interested in the first intersection:
t = e d
( e d ) 2 + r 2 e e .
If e < r, then the spheres are intersecting at t = 0. If t < 0 or
t > l, then the intersection does not occur within the period of time being
considered. If the value inside the square root is negative, then there is no
intersection.
A.14
Intersection of a Sphere and AABB
To detect the static intersection of a sphere and an AABB, we first find
the point on the box that is closest to the center of the sphere by using
the techniques from Section A.5. We compute the distance from this point
to the center of the sphere and compare this distance with the radius.
(Actually, in practice we compare the distance squared against the radius
squared to avoid the square root in the distance computation.) If the
distance is smaller than the radius, then the sphere intersects the AABB.
Arvo [2] discusses this technique, which he uses for intersecting spheres
with “solid” boxes. He also discusses some tricks for intersecting spheres
with “hollow” boxes.
Unfortunately, the dynamic test is more complicated than the static
one. For details, see Lengyel [42].
Search WWH ::




Custom Search