Game Development Reference
In-Depth Information
A.10
Intersection of an AABB and Plane
Consider a 3D axially aligned bounding box defined by extreme points p min
and p max , and a plane defined in the standard implicit manner by all points
p that satisfy
p n = d,
where n is not necessarily a unit vector. The plane must be expressed in
the same coordinate space as the AABB.
One obvious implementation strategy for a static test would be to clas-
sify each corner point as being on either the front or back side of the plane.
We do this by taking the dot products of the corner points with n and
comparing these dot products with d. If all of the dot products are greater
than d, then the box is completely on the front side of the plane. If all of
the dot products are less than d, then the box is completely on the back
side of the plane.
As it turns out, we don't have to check all eight corner points. We'll use
a trick similar to the one used in Section 9.4.4 to transform an AABB. For
example, if n x > 0, then the corner with the minimal dot product has x =
x min and the corner with the maximal dot product has x = x max . If n x < 0,
then the opposite is true. Similar statements apply to n y and n z . We
compute the minimum and maximum dot product values. If the minimum
dot product value is greater than d, or if the maximum dot product is less
than d, then there is no intersection. Otherwise, two corners were found
that are on opposite sides of the plane, and therefore an intersection is
detected. This strategy is implemented in Listing A.2.
/ /
P e r f o r m
s t a t i c
AABB p l a n e
i n t e r s e c t i o n
t e s t .
R e t u r n s :
/ /
/ / < 0
Box
i s
c o m p l e t e l y
on
t h e
BACK
s i d e
o f
t h e
p l a n e
/ / > 0
Box
i s
c o m p l e t e l y
on
t h e FRONT
s i d e
o f
t h e
p l a n e
/ /
0
Box
i n t e r s e c t s
t h e
p l a n e
i n t
AABB3 : : c l a s s i f y P l a n e ( c o n s t
V e c t o r 3
&n ,
f l o a t
d )
c o n s t
{
/ /
I n s p e c t
t h e
normal
and
compute
t h e
minimum and maximum
/ / D v a l u e s .
f l o a t
minD ,
maxD ;
i f
( n . x > 0 . 0 f )
{
minD
=
n . x min . x ;
maxD
=
n . x max . x ;
}
e l s e {
minD
=
n . x max . x ;
maxD
=
n . x min . x ;
}
i f
( n . y > 0 . 0 f )
{
minD
+=
n . y min . y ;
maxD
+=
n . y max . y ;
}
e l s e {
minD
+=
n . y max . y ;
maxD
+=
n . y min . y ;
}
i f
( n . z > 0 . 0 f )
{
minD
+=
n . z min . z ;
maxD
+=
n . z max . z ;
Search WWH ::




Custom Search