Game Development Reference
In-Depth Information
As Figure 9.21 shows, each vertex has a vector from v i to p , named d i .
Summarizing the equations for the vectors, we have
e 1 = v 3
v 2 ,
e 2 = v 1
v 3 ,
e 3 = v 2
v 1 ,
d 1 = p v 1 ,
d 2 = p v 2 ,
d 3 = p v 3 .
We'll also need a surface normal, which can be computed by
e 1 × e 2
e 1
n =
.
× e 2
Now the areas for the entire triangle (which we'll simply call T) and the
three subtriangles are given by
A(T) = (( e 1
× e 2 ) n )/2,
A(T 1 ) = (( e 1
× d 3 ) n )/2,
A(T 2 ) = (( e 2
× d 1 ) n )/2,
A(T 3 ) = (( e 3
× d 2 ) n )/2.
Each barycentric coordinate b i is given by A(T i )/A(T):
b 1 = A(T 1 )/A(T) = ( e 1
× d 3 ) n
( e 1 × e 2 ) n ,
b 2 = A(T 2 )/A(T) = ( e 2 × d 1 ) n
( e 1
Computing barycentric
coordinates in 3D
× e 2 ) n ,
b 3 = A(T 3 )/A(T) = ( e 3
× d 2 ) n
( e 1 × e 2 ) n .
Notice that n is used in all of the numerators and all of the denomina-
tors, and so it is doesn't necessarily have to be a unit vector.
This technique for computing barycentric coordinates involves more
scalar math operations than the method of projection into 2D. However, it
is branchless and offers better SIMD optimization.
9.6.5 Special Points
In this section we discuss three points on a triangle that have special geo-
metric significance:
center of gravity
incenter
circumcenter.
 
Search WWH ::




Custom Search