Game Development Reference
In-Depth Information
rent pose. In other words, this matrix describes the difference between the
bone's orientation in the binding pose and the bone's current orientation
in the current pose. This is shown in Listing 10.8.
/ /
S e t
a
l i m i t
on
t h e
max number
o f
bones
t h a t
can
i n f l u e n c e
one
v e r t e x
c o n s t
i n t
k M a x B o n e s P e r V e r t e x
=
4 ;
/ /
D e s c r i b e s
a
v e r t e x
i n
a
s k e l e t a l
model
s t r u c t
S k i n n e d V e r t e x
{
/ /
Number
o f
bones
t h a t
i n f l u e n c e
t h i s
v e r t e x
i n t
boneCount ;
/ /
Which
bones
i n f l u e n c e
t h e
v e r t e x ?
These
a r e
i n d i c e s
/ /
i n t o
a
l i s t
o f
bones .
i n t
b o n e I n d e x [ k M a x B o n e s P e r V e r t e x ] ;
/ /
Bone
w e i g h t s .
These
must
sun
t o
1
f l o a t
boneWeight [ k M a x B o n e s P e r V e r t e x ] ;
/ /
V e r t e x
p o s i t i o n
and
normal
i n
t h e
b i n d i n g
pose ,
/ /
i n
model
space
V e c t o r 3
po s ;
V e c t o r 3
n o r m a l ;
} ;
/ /
D e s c r i b e s
a
v e r t e x
a s
we
w i l l
use
i t
f o r
r e n d e r i n g
s t r u c t
V e r t e x
{
V e c t o r 3
po s ;
V e c t o r 3
n o r m a l ;
} ;
/ /
Compute
s k i n n e d
v e r t e x
p o s i t i o n s
and
n o r m a l s .
v o i d
c o m p u t e S k i n n e d V e r t i c e s (
i n t
v e r t e x C o u n t ,
/ /
number
o f
v e r t s
t o
s k i n
c o n s t
S k i n n e d V e r t e x
i n S k i n V e r t L i s t ,
/ /
i n p u t
v e r t
l i s t
c o n s t
M a t r i x 4 x 3
b o n e T r a n s f o r m L i s t ,
/ /
From
b i n d i n g
t o
c u r r e n t
pose
V e r t e x
o u t V e r t L i s t
/ /
o u t p u t
goes
h e r e
)
{
/ /
I t e r a t e
o v e r
a l l
t h e
v e r t i c e s
f o r
( i n t
i
=
0
;
i < v e r t e x C o u n t
;
++ i )
{
c o n s t
S k i n n e d V e r t e x
&s
=
i n S k i n V e r t L i s t [ i ] ;
V e r t e x
&d
=
o u t V e r t L i s t [ i ] ;
/ /
Loop
o v e r
a l l
bones
t h a t
i n f l u e n c e
t h i s
v e r t e x ,
and
compute
m a t r i x
/ /
a
blended
f o r
t h i s
v e r t e x
M a t r i x 4 x 3 b l e n d e d M a t ;
b l e n d e d M a t . z e r o ( ) ;
f o r
( i n t
j
=
0
;
j < s . boneCount
;
++ j )
{
b l e n d e d M a t
+=
b o n e T r a n s f o r m L i s t [ s . b o n e I n d e x [ j ] ]
s . boneWeight [ j ] ;
}
/ /
T r a n s f o r m
p o s i t i o n
and
normal
u s i n g
blended
m a t r i x
d . p os
=
s . p os
b l e n d e d M a t ;
d . n o r m a l
=
b l e n d e d M a t . r o t a t e ( s . n o r m a l ) ;
/ /
Make
s u r e
t h e
normal
i s
n o r m a l i z e d
d . n o r m a l . n o r m a l i z e ( ) ;
}
}
Listing 10.8
A more optimized strategy for skinning vertices
Search WWH ::




Custom Search