RigidAnimationPlayer.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #region File Description
  2. //-----------------------------------------------------------------------------
  3. // RigidAnimationPlayer.cs
  4. //
  5. // Microsoft XNA Community Game Platform
  6. // Copyright (C) Microsoft Corporation. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. #endregion
  9. using System;
  10. using Microsoft.Xna.Framework;
  11. namespace CustomModelAnimation
  12. {
  13. /// <summary>
  14. /// This animation player knows how to play an animation on a rigid model, applying transformations
  15. /// to each of the objects in the model over time
  16. /// </summary>
  17. public class RigidAnimationPlayer : ModelAnimationPlayerBase
  18. {
  19. // This is an array of the transforms to each object in the model
  20. Matrix[] boneTransforms;
  21. /// <summary>
  22. /// Create a new rigid animation player
  23. /// </summary>
  24. /// <param name="count">Number of bones (objects) in the model</param>
  25. public RigidAnimationPlayer(int count)
  26. {
  27. if (count <= 0)
  28. throw new Exception("Bad arguments to model animation player");
  29. this.boneTransforms = new Matrix[count];
  30. }
  31. /// <summary>
  32. /// Initializes all the bone transforms to the identity
  33. /// </summary>
  34. protected override void InitClip()
  35. {
  36. for (int i = 0; i < this.boneTransforms.Length; i++)
  37. this.boneTransforms[i] = Matrix.Identity;
  38. }
  39. /// <summary>
  40. /// Sets the key frame for a bone to a transform
  41. /// </summary>
  42. /// <param name="keyframe">Keyframe to set</param>
  43. protected override void SetKeyframe(ModelKeyframe keyframe)
  44. {
  45. this.boneTransforms[keyframe.Bone] = keyframe.Transform;
  46. }
  47. /// <summary>
  48. /// Gets the current bone transform matrices for the animation
  49. /// </summary>
  50. public Matrix[] GetBoneTransforms()
  51. {
  52. return boneTransforms;
  53. }
  54. }
  55. }