Game Development Reference

In-Depth Information

s ws ws ws

twt wt wt

=

+

+

00

11

22

(6.61)

=

+

+

22
.

00

11

6.2.2 Intersection of a Ray and a Box

A box is described by the six plane equations

=

0

0

0

xr

=

x

x

y

=

yr

=

y

z

=

z

=

r

,

(6.62)

z

where
r
,
r
, and
r
represent the dimensions of the box. At most three of these

planes need to be considered for intersection by the ray since at least three planes

must face away from the ray's direction
V
. We can determine which planes need

to be tested by examining the components of
V
one at a time. For instance, if

0

V

=

, then we know that the ray cannot intersect either of the planes

=

0

or

x

x

=

r

because
V
is parallel to them. If

V

>

0

, then we do not need to test for an

x

x

x

intersection with the plane

since it represents a back side of the box from

the ray's perspective. Similarly, if

x

=

r

x

V

<

0

, then we do not need to test for an inter-

x

section with the plane

=

0

. The same principle applies to the
y
and
z
compo-

x

nents of
V
.

Once we have found the point where a ray intersects a plane, we must check

that the point falls within the face of the box by examining the two coordinates

corresponding to the directions parallel to the plane. For instance, the value of
t

corresponding to the point where the ray given by Equation (6.51) intersects the

plane

=

r

is given by

x

x

rS

−

x

x

t

=

.

(6.63)

x

To lie within the corresponding face of the box, the
y
and
z
coordinates of the

point

()

P

t

must satisfy

]

()

0

0

()

t

r

≤

[

P

P

≤

y

y

[

]

≤

t

≤

r

.

(6.64)

z

z

If either of these conditions fails, then no intersection takes place within the face.

If both conditions pass, then an intersection has been found, in which case there

is no need to test any other planes since no closer intersection can occur.

Search Nedrilad ::

Custom Search