Graphics Reference
In-Depth Information
// Test if sphere with radius r moving from a to b intersects with plane p
int TestMovingSpherePlane(Point a, Point b, float r, Plane p)
{
// Get the distance for both a and b from plane p
float adist = Dot(a, p.n) - p.d;
float bdist = Dot(b, p.n) - p.d;
// Intersects if on different sides of plane (distances have different signs)
if (adist * bdist < 0.0f) return 1;
// Intersects if start or end position within radius from plane
if (Abs(adist) <= r || Abs(bdist) <= r) return 1;
// No intersection
return 0;
}
=
This test also assumes the plane has been normalized; that is,
n
1.
5.5.4
Intersecting Moving AABB Against Plane
Let a plane
d
, where
n
is a unit vector. Let an AABB
B
be
specified by a center
C
; local axis vectors
u
0
π
be specified by (
n
·
X
)
=
(0,0,1);
and extents
e
0
,
e
1
, and
e
2
. Let
v
be the direction vector for
B
such that the box center
movement is given by
C
(
t
)
=
(1,0,0),
u
1
=
(0, 1, 0), and
u
2
=
=
+
≤
≤
1.
Consider the plane normal
n
as a separating axis. The projection radius of
B
with
respect to an axis
n
is given by
C
t
v
over the interval of motion 0
t
r
=
e
0
|
u
0
·
n
| +
e
1
|
u
1
·
n
| +
e
2
|
u
2
·
n
|
.
Because
u
0
,
u
1
, and
u
2
are fixed, this simplifies to
e
1
n
y
+
r
=
e
0
|
n
x
| +
e
2
|
n
z
|
.
Note that the magnitude of the projected radius remains constant as
B
moves. The
test now proceeds equivalently to the moving-sphere-against-plane test. The signed
distance from the plane of a point
R
is (
n
·
R
)
−
d
. Consequently, the AABB initially
overlaps the plane if
(
n
d
≤
·
C
)
−
r
.If(
n
·
v
)
>
0, the AABB is moving away from
the plane. When (
n
0, the AABB is moving parallel to the plane.
Displacing the plane toward the AABB by
r
changes the plane to (
n
·
v
)
=
r
.
When the AABB is moving toward the plane, the first point on the AABB to touch
the plane is
Q
·
X
)
=
d
+
=
−
C
(
t
)
r
n
, where
C
(
t
) is the position of the AABB at the time it first