AnimationChannel.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. std::vector<float>& getKeyValues();
  46. std::vector<float>& getKeyTimes();
  47. std::vector<float>& getTangentsIn();
  48. std::vector<float>& getTangentsOut();
  49. std::vector<unsigned int>& getInterpolationTypes();
  50. /**
  51. * Removes duplicate key frames from the animation channel.
  52. */
  53. void removeDuplicates();
  54. /**
  55. * Returns the interpolation type value for the given string or zero if not valid.
  56. * Example: "LINEAR" returns AnimationChannel::LINEAR
  57. *
  58. * @param str Interpolation such as "LINEAR" or "BSPLINE".
  59. *
  60. * @return A value from InterpolationTypes enum or zero if not valid.
  61. */
  62. static unsigned int getInterpolationType(const char* str);
  63. private:
  64. /**
  65. * Deletes all key frames from key time index begin to key time index end (exclusive).
  66. *
  67. * @param begin The start index to delete.
  68. * @param end The index to delete up to but not including.
  69. * @param propSize The size of the animation propery to delete. Example: Translate(x,y,z) is size 3.
  70. */
  71. void deleteRange(size_t begin, size_t end, size_t propSize);
  72. private:
  73. std::string _targetId;
  74. unsigned int _targetAttrib;
  75. std::vector<float> _keytimes;
  76. std::vector<float> _keyValues;
  77. std::vector<float> _tangentsIn;
  78. std::vector<float> _tangentsOut;
  79. std::vector<unsigned int> _interpolations;
  80. };
  81. }
  82. #endif