This is an OpenGL sample of using mathematical interpolation in animated model viewer code. Please note that this sample is runnable only with the recent releases of Fbsl.exe dated later than September 3, 2010 whereby dynamic allocation of assembler opcode strings has been provided.

To reduce the amount of data in an animated model file, the animation sequence stores only certain key positions of mesh vertices at selected time intervals usually called "keyframes". The number of keyframes in the sequence is normally rather limited, and if we display only the keyframes as they are, the resulting movement will be rather jerky. An example of this may be seen in the accompanying sample if we run it in its "Interpolation Off" mode irrespective of the rendering speed which itself is dependent on the language chosen for the dynamic recalculation of vertex positions (FBSL, Asm, or both). In order to avoid this, a mathematical workaround called "interpolation" is usually used.

Interpolation is a method of constructing new data points within the range of a discrete set of known data points. There are various approaches to interpolation, among which "linear" and "Hermite" interpolation are most commonly used in 3D applications. Both are relatively fast computation-wise, though alongside some merits each one has its own drawbacks.

The accompanying sample uses linear interpolation to smooth out the model's movements. Positive effects of using interpolation are most clearly seen at high frame rates with pure Asm being chosen for vertex position calculations. Toggle the interpolation on/off with the "I" key to see the difference.

You will probably notice the somewhat unnatural positions the model's head and neck acquire as the model does its morning exercises . This is where the drawbacks of "linear" interpolation reveal themselves.

Suppose some vertex should move from position A stored in the model file's animation sequence as a keyframe to position B also stored there in the second keyframe that immediately follows the first one. In reality, the vertex is supposed to move along the sine wave path as depicted in the graph immediately following this text.

In order to follow that path precisely without interpolation, a much larger number of keyframes should seemingly be stored in the model file which will thus become impractically large in size. Instead, a linear interpolation method is used in the code to calculate the exact coordinates of the vertex along the straight line A-B (blue) whenever the time comes to display the model at an arbitrary position C at the current frame rate. The method is fast and it generally yields good results for very simple models. In our case, however, it introduces a displacement error.

In fact, the linearly interpolated keyframe C does not lie exactly on the sine wave path as it is expected to do. It is the displacement error depicted in green which is the very cause of the unnatural positions of the model's head and neck. Evidently, the head and neck displacement errors which we see in the appended sample have a cumulative nature. They accumulated at the time the model's movements were designed using simple model animation software, and they are aggravated still further by our simplistic interpolation techniques.

Those who'd like to have some additional reading on various mathematical interpolation methods may find it here.

FYI: Chris' model renderers used in his XANDREALE projects and also in my Quake III Arena model viewer utilize Hermite interpolation which produces much better visual results for medium- to high-poly bone-animated 3D models of various formats.

Enjoy!

[EDIT] While Gerome takes his time to recompile a completely new FBSL release, I append the Fbsl binary that'll be able to run the accompanying sample script.