Friday, December 28, 2007

Frame of Reference and Animation Thoughts

Recently I have been studying the ideas of Frame Hierarchies used in graphics programming.  Specifically, with DirectX and the X file graphics format.  Listed are some of my findings:

Frame of References

Frame of References are all around us.  A typical example is someone giving directions to someone else.  These are typically given "within a frame of reference".  Meaning, if directions are given to the location (B), they are given assuming you are starting at location (A).

In the context of DirectX graphics, frames (which contain mesh(s)) are usually more complex than just a single frame / mesh.  Hence, we require a way to manipulate the "series" of frames (and corresponding meshes) in a way that will allow each frame to be manipulated, but still allow the frame objects to maintain some sort of relationship.  If we use the concept of a hierarchy and a frame of reference we can accomplish this.

Basically, we establish a root of the hierarchy and then siblings/children under this.  Each sibling will share the same parent world matrix, and each child will have a parent (which it will get its world matrix from).

The order of operation on the world matrix at the child level determines how the object is manipulated/changed.  If we apply, for instance, a rotation to the child model space matrix and then concatenate this matrix with the child's parent matrix, we can archive frame independent transformation/rotation/scaling while maintaining the overall frame hierarchal relationship.


How does this frame hierarchy business help us when we begin to use animation?  It does so by defining animation interfaces, that are called by D3DX when Animation Sets that are active (allocated to tracks in the animation mixer) are found that have frame name references that are found in our Frame Hierarchy.

The D3DX API is constructed in such a way as to allow the X file definition contain animation sets, which contain animation definitions.  These are in turn linked to frames in the hierarchy.  Animation is a much more complex subject, but to simplify it, D3DX will crawl our hierarchy as time advances looking for frames that contain animation sets/animations.  It will then do the calculations to determine what the animation should do based on passed time values and animation definition.

One key to remember is that since we are using a hierarchy we don't necessarily have to reprocess the entire tree if only a few children are affected by the change.  We just process that part of the tree.

No comments: