AnimationChannel.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #ifndef ANIMATIONCHANNEL_H_
  2. #define ANIMATIONCHANNEL_H_
  3. #include "Object.h"
  4. namespace gameplay
  5. {
  6. class AnimationChannel : public Object
  7. {
  8. public:
  9. enum InterpolationTypes
  10. {
  11. LINEAR = 1,
  12. BEZIER = 2,
  13. CARDINAL = 3,
  14. HERMITE = 4,
  15. BSPLINE = 5,
  16. STEP = 6
  17. };
  18. /**
  19. * Constructor.
  20. */
  21. AnimationChannel(void);
  22. /**
  23. * Destructor.
  24. */
  25. virtual ~AnimationChannel(void);
  26. virtual unsigned int getTypeId(void) const;
  27. virtual const char* getElementName(void) const;
  28. virtual void writeBinary(FILE* file);
  29. virtual void writeText(FILE* file);
  30. const std::string& getTargetId() const;
  31. /**
  32. * Sets the interpolation type of the entire animation channel.
  33. *
  34. * @param interpolation The interpolation type from InterpolationTypes enum.
  35. */
  36. void setInterpolation(unsigned int interpolation);
  37. void setTargetId(const std::string& str);
  38. void setTargetAttribute(unsigned int attrib);
  39. void setKeyTimes(const std::vector<float>& values);
  40. void setKeyValues(const std::vector<float>& values);
  41. void setTangentsIn(const std::vector<float>& values);
  42. void setTangentsOut(const std::vector<float>& values);
  43. void setInterpolations(const std::vector<unsigned int>& values);
  44. unsigned int getTargetAttribute() const;
  45. const std::vector<float>& getKeyValues() const;
  46. const std::vector<float>& getKeyTimes() const;
  47. const std::vector<float>& getTangentsIn() const;
  48. const std::vector<float>& getTangentsOut() const;
  49. const std::vector<unsigned int>& getInterpolationTypes() const;
  50. /**
  51. * Removes duplicate key frames from the animation channel.
  52. */
  53. void removeDuplicates();
  54. void convertToQuaternion();
  55. void convertToTransform();
  56. /**
  57. * Returns the interpolation type value for the given string or zero if not valid.
  58. * Example: "LINEAR" returns AnimationChannel::LINEAR
  59. *
  60. * @param str Interpolation such as "LINEAR" or "BSPLINE".
  61. *
  62. * @return A value from InterpolationTypes enum or zero if not valid.
  63. */
  64. static unsigned int getInterpolationType(const char* str);
  65. private:
  66. /**
  67. * Deletes all key frames from key time index begin to key time index end (exclusive).
  68. *
  69. * @param begin The start index to delete.
  70. * @param end The index to delete up to but not including.
  71. * @param propSize The size of the animation propery to delete. Example: Translate(x,y,z) is size 3.
  72. */
  73. void deleteRange(size_t begin, size_t end, size_t propSize);
  74. private:
  75. std::string _targetId;
  76. unsigned int _targetAttrib;
  77. std::vector<float> _keytimes;
  78. std::vector<float> _keyValues;
  79. std::vector<float> _tangentsIn;
  80. std::vector<float> _tangentsOut;
  81. std::vector<unsigned int> _interpolations;
  82. };
  83. }
  84. #endif