Animation.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef ANKI_RESOURCE_ANIMATION_H
  2. #define ANKI_RESOURCE_ANIMATION_H
  3. #include "anki/Math.h"
  4. #include "anki/util/Vector.h"
  5. namespace anki {
  6. class XmlElement;
  7. /// @addtogroup Resources
  8. /// @{
  9. /// A keyframe
  10. template<typename T>
  11. class Key
  12. {
  13. friend class Animation;
  14. public:
  15. F32 getTime() const
  16. {
  17. return time;
  18. }
  19. const T& getValue() const
  20. {
  21. return value;
  22. }
  23. private:
  24. F32 time;
  25. T value;
  26. };
  27. /// Animation channel
  28. struct AnimationChannel
  29. {
  30. std::string name;
  31. I32 boneIndex = -1; ///< For skeletal animations
  32. Vector<Key<Vec3>> positions;
  33. Vector<Key<Quat>> rotations;
  34. Vector<Key<F32>> scales;
  35. Vector<Key<F32>> cameraFovs;
  36. };
  37. /// Animation consists of keyframe data
  38. class Animation
  39. {
  40. public:
  41. void load(const char* filename);
  42. /// @name Accessors
  43. /// @{
  44. const Vector<AnimationChannel>& getChannels() const
  45. {
  46. return channels;
  47. }
  48. F32 getDuration() const
  49. {
  50. return duration;
  51. }
  52. F32 getStartingTime() const
  53. {
  54. return startTime;
  55. }
  56. /// @}
  57. /// Get the interpolated data
  58. void interpolate(U channelIndex, F32 time,
  59. Vec3& position, Quat& rotation, F32& scale) const;
  60. private:
  61. Vector<AnimationChannel> channels;
  62. F32 duration;
  63. F32 startTime;
  64. void loadInternal(const XmlElement& el);
  65. };
  66. /// @}
  67. } // end namespace anki
  68. #endif