Game Development Reference
In-Depth Information
We can also find out position and rotation information for the start, end, and current
offsets using the methods GetMatOfsInitial , GetMatOfsFinal , and GetMatOfs
of CIwAnimPlayer . Each of these methods allows access to a CIwFMat object
representing the current orientation of the offset. We can then use this information to
allow us to update the position of a game character accordingly, so that other game
functions such as collision detection continue to work correctly.
Obtaining bone positions and rotations
When discussing sub-animations earlier, we presented the example of a character
being able to hold a variety of different weapons. Sub-animations will, of course,
only provide half the solution to this problem, as they will move the character's arms
to the correct pose; but, because the weapon is not part of the source 3D model, the
character will just appear to be clutching at thin air.
We need some way of drawing a further model depicting the weapon, but how can
we get it positioned in the correct place?
The answer is to ask the animation player to provide us with the current orientation
and position of a bone that is located at the point where the weapon model
would need to be drawn. We can do this by calling the GetBoneNamed method of
CIwAnimPlayer , which will return a pointer to a CIwAnimBone instance representing
the current orientation of the requested bone.
The position and rotation of the bone can be found using the GetPos and GetRot
methods of CIwAnimBone , which allow us to generate a matrix in model space, or
alternatively the GetMat method will return a model space matrix representing both
the position and rotation of the bone if it has been calculated during the update of
the CIwAnimPlayer instance.
Using the bone information, we can easily calculate a model matrix for rendering the
weapon model in the correct place. First we use the bone information to generate a
matrix in model space, we then multiply this by any rotation matrix needed to orient
the character in the game world. Finally, add the world position of the character and
the weapon model can be rendered in the character's hand.
Example code
The following sections give an overview of the sample projects accompanying
this chapter.
 
Search WWH ::




Custom Search