Graphics Reference
In-Depth Information
// Calculate time difference between frames
var frameLength = frame.Time - prevKeyForBone.Time;
var timeDiff = time - prevKeyForBone.Time;
var amount = timeDiff / frameLength;
// Interpolation using Lerp on scale and translation,
// and Slerp on Rotation (Quaternion)
Vector3 t1, t2; // Translation
Quaternion q1, q2;// Rotation
float s1, s2; // Scale
// Decompose the previous key-frame's transform
prevFrame.Transform.DecomposeUniformScale(out s1,
out q1, out t1);
// Decompose the current key-frame's transform
frame.Transform.DecomposeUniformScale(out s2,
out q2, out t2);
// Perform interpolation and reconstruct matrix
skinMatrices.Bones[frame.BoneIndex] =
Matrix.Scaling(MathUtil.Lerp(s1, s2, amount)) *
Matrix.RotationQuaternion(
Quaternion.Slerp(q1, q2, amount)) *
Matrix.Translation(Vector3.Lerp(t1, t2, amount));
}
5. And finally, in place of the second TODO comment regarding the animation loop,
insert the following code:
// Check if need to loop animation
if (!PlayOnce && CurrentAnimation.HasValue &&
CurrentAnimation.Value.EndTime <= time)
{
this.Clock.Restart();
}
6.
To start our animation, add the following code to the D3DApp.Run method just after
we finish loading and initializing our mesh renderers:
// Set first animation as the current animation and start
foreach (var m in meshes) {
if (m.Mesh.Animations != null && m.Mesh.Animations.Any())
m.CurrentAnimation = m.Mesh.Animations.First().Value;
m.Clock.Start();
}
 
Search WWH ::




Custom Search