Graphics Reference
In-Depth Information
e
1
u
1
u
0
r
s
C
e
0
n
d
Figure 5.16
Testing intersection of an OBB against a plane.
to the evaluation of the plane equation for the box center. Figure 5.16 illustrates the
quantities used in the test.
Because the intersection between the OBB
B
and the plane
P
occurs when
−
r
≤
s
≤
r
, or equivalently when
|
s
| ≤
r
, there is now sufficient information to
implement the test.
// Test if OBB b intersects plane p
int TestOBBPlane(OBB b, Plane p)
{
// Compute the projection interval radius of b onto L(t) = b.c+t*p.n
float r = b.e[0]*Abs(Dot(p.n, b.u[0])) +
b.e[1]*Abs(Dot(p.n, b.u[1])) +
b.e[2]*Abs(Dot(p.n, b.u[2]));
// Compute distance of box center from plane
float s = Dot(p.n, b.c) - p.d;
// Intersection occurs when distance s falls within [-r,+r] interval
return Abs(s) <= r;
}
It is not necessary for
n
to be normalized for the test to work. If
n
is nonunit, both
r
and
s
will be a factor
larger, which does not affect the test.
Other tests can be easily implemented in a similar vein. For example, the OBB falls
inside the negative halfspace of the plane if
s
n
≤−
≤
r
.If
r
s
, the OBB lies fully in
=
+
+
+
the positive halfspace of the plane. For an OBB given as
B
C
k
0
v
0
k
1
v
1
k
2
v
2
,