Game Development Reference
In-Depth Information
f l o a t
gamma
=
1 . 0 f
a l p h a
b e t a ;
i f
( ! ( gamma > =
0 . 0 f ) )
{
r e t u r n
k N o I n t e r s e c t i o n ;
}
/ /
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
r e t u r n
t ;
}
Listing A.4
Ray-triangle intersection test
There is one more significant strategy, not illustrated in Listing A.4,
for optimizing expensive calculations: precompute their results. If values
such as the polygon normal can be computed ahead of time, then different
strategies may be used.
Because of the fundamental importance of this test, programmers are al-
ways looking for ways to make it faster. The technique we have given here
is a standard one that is easy to understand and produces the barycen-
tric coordinates, often a useful byproduct, as a side effect. It is not the
fastest. See Tomas Akenine-Moller's collection of intersection tests on the
web page for Real-Time Rendering at http://www.realtimerendering.com/
intersections.html.
A.17
Intersection of Two AABBs
Detecting the static intersection of two AABBs is an extremely important
operation. Luckily, it's rather trivial. 1 We simply check for overlapping
extents on each dimension independently. If there is no overlap on a par-
ticular dimension, then the two AABBs do not intersect. This technique is
used in Listing A.5.
bool
a a b b s O v e r l a p ( c o n s t
AABB3 &a ,
c o n s t
AABB3 &b )
{
/ /
Check
f o r
a
s e p a r a t i n g
a x i s .
i f
( a . min . x > =
b . max . x )
r e t u r n
f a l s e ;
i f
( a . max . x < =
b . min . x )
r e t u r n
f a l s e ;
i f
( a . min . y > =
b . max . y )
r e t u r n
f a l s e ;
i f
( a . max . y < =
b . min . y )
r e t u r n
f a l s e ;
i f
( a . min . z > =
b . max . z )
r e t u r n
f a l s e ;
i f
( a . max . z < =
b . min . z )
r e t u r n
f a l s e ;
/ /
Overlap
on
a l l
t h r e e
a x e s ,
so
t h e i r
/ /
i n t e r s e c t i o n
must
be
non empty
r e t u r n
t r u e ;
}
Listing A.5
AABB-AABB overlap test
1 This is one of Fletcher's favorite interview questions. It's surprising how many
programmers do not know how to perform this very simple operation. Don't be one of
those applicants!
Search WWH ::




Custom Search