Game Development Reference
In-Depth Information
the moving box is completely to the left of the stationary box, and at t = 1,
the moving box is completely to the right of the stationary box. There is
a point t
enter
where the boxes first begin to overlap, and a point t
leave
where the boxes cease to overlap. For the dimension we are considering, let
m
min
(t) and m
max
(t) be the minimum and maximum values, respectively,
of the moving box at time t, given by
m
min
(t) = m
min
(0) + td,
m
max
(t) = m
max
(0) + td,
where m
min
(0) and m
max
(0) are the initial extents of the moving box and
d is the component of the displacement vector
d
for this axis. Let s
min
and s
max
have similar definitions for the stationary box. (Of course, these
values are independent of t since the box is stationary.) The time t
enter
is
the t value for which m
max
(t) = s
min
. Solving, we get
m
max
(t
enter
) = s
min
,
m
max
(0) + t
enter
d = s
min
,
t
enter
d = s
min
− m
max
(0),
t
enter
=
s
min
− m
max
(0)
d
.
Likewise, we can solve for t
leave
:
m
min
(t
leave
) = s
max
,
m
min
(0) + t
leave
d = s
max
,
t
leave
d = s
max
− m
min
(0),
t
leave
=
s
max
− m
min
(0)
d
.
Three important points are noted here:
•
If the denominator d is zero, then boxes either always overlap or never
overlap.
•
If the moving box begins on the right side of the stationary box and
moves left, then t
enter
> t
leave
. We handle this scenario by swapping
their values to ensure that t
enter
< t
leave
.
•
The values for t
enter
and t
leave
may be outside the range [0,1]. To
accommodate t values outside this range, we can think of the moving
box as moving along an infinite trajectory parallel to d. If t
enter
> 1
or t
leave
< 0, then there is no overlap in the period of time under
consideration.
Search WWH ::
Custom Search