Game Development Reference
In-Depth Information
Woo [72] describes a method that first determines which side of the
box would be intersected and then performs a ray-plane intersection test
against the plane containing that side. If the point of intersection with the
plane is within the box, then there is an intersection; otherwise, there is no
intersection. This is implemented in Listing A.6.
/ /
R e t u r n
p a r a m e t r i c
p o i n t
o f
i n t e r s e c t i o n
0 . . . 1 ,
o r
a
r e a l l y
huge
/ /
number
i f
no
i n t e r s e c t i o n
i s
found
f l o a t AABB3 : : r a y I n t e r s e c t (
c o n s t
V e c t o r 3
&r a y O r g ,
/ /
o r g i n
o f
t h e
r a y
c o n s t
V e c t o r 3
&r a y D e l t a ,
/ /
l e n g t h
and
d i r e c t i o n
o f
t h e
r a y
r e t u r n N o r m a l
V e c t o r 3
/ /
o p t i o n a l l y ,
t h e
normal
i s
r e t u r n e d
)
c o n s t
{
/ / We ' l l
r e t u r n
t h i s
huge
number
i f
no
i n t e r s e c t i o n
c o n s t
f l o a t
k N o I n t e r s e c t i o n
=
FLT MAX ;
/ /
Check
f o r
p o i n t
i n s i d e
box ,
t r i v i a l
r e j e c t ,
and
/ /
d e t e r m i n e
p a r a m e t r i c
d i s t a n c e
t o
each
f r o n t
f a c e
bool
i n s i d e
=
t r u e ;
f l o a t
x t ,
xn ;
i f
( r a y O r g . x < min . x )
{
x t
=
min . x
r a y O r g . x ;
i f
( x t > r a y D e l t a . x )
r e t u r n
k N o I n t e r s e c t i o n ;
x t
/ =
r a y D e l t a . x ;
i n s i d e
=
f a l s e ;
xn
=
1.0 f ;
}
e l s e
i f
( r a y O r g . x > max . x )
{
x t
=
max . x
r a y O r g . x ;
i f
( x t < r a y D e l t a . x )
r e t u r n
k N o I n t e r s e c t i o n ;
x t
/ =
r a y D e l t a . x ;
i n s i d e
=
f a l s e ;
xn
=
1 . 0 f ;
}
e l s e
{
x t
=
1.0 f ;
}
f l o a t
y t ,
yn ;
i f
( r a y O r g . y < min . y )
{
y t
=
min . y
r a y O r g . y ;
i f
( y t > r a y D e l t a . y )
r e t u r n
k N o I n t e r s e c t i o n ;
y t
/ =
r a y D e l t a . y ;
i n s i d e
=
f a l s e ;
1.0 f ;
yn
=
}
( r a y O r g . y > max . y )
{
e l s e
i f
y t
=
max . y
r a y O r g . y ;
i f
( y t < r a y D e l t a . y )
r e t u r n
k N o I n t e r s e c t i o n ;
y t
/ =
r a y D e l t a . y ;
i n s i d e
=
f a l s e ;
yn
=
1 . 0 f ;
}
e l s e
{
y t
=
1.0 f ;
}
f l o a t
z t ,
zn ;
i f
( r a y O r g . z < min . z )
{
z t
=
min . z
r a y O r g . z ;
i f
( z t > r a y D e l t a . z )
r e t u r n
k N o I n t e r s e c t i o n ;
z t
/ =
r a y D e l t a . z ;
Search WWH ::




Custom Search