Game Development Reference
In-Depth Information
quaternion start_rotation = quaternion::CreateFromAxisAngle(vector3::UnitX, Pi/4);
quaternion end_rotation = quaternion::CreateFromAxisAngle(vector3::UnitZ, Pi/4);
quaternion result = start_rotation;
float t = 0.0;
while ( t < 1.0 )
{
result = quaternion::Slerp(start_rotation, end_rotation, t);
object.SetRotation(result);
t += 1.0 / 30.0;
}
This very simple example shows how we can interpolate between some starting rota-
tion represented with a quaternion towards an ending rotation, in the loop we simulate 30
frames per second, each frame we advance the interpolation forward storing it in result
which we then use to transform some object. What we would see is an object smoothly an-
imating between facing 45 degrees in x towards facing 45 degrees in z .
Programmers should shed the irrational fear of quaternions, while a good understanding of
what they do and how they do it is expected, do not start by spending hours learning the
intricate detailsofhowtomultiplythem,orhowtoimplement yourownslerpfunction.In-
stead learn to use them first, grab an object and rotate it, then multiply another quaternion
in and watch the result. Once you understand how to use them properly and when they are
appropriate, invest the time to learn why they work, they are fascinating all the way down
to how they were first conceived.
Search WWH ::




Custom Search