CCAnimationCurve.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /****************************************************************************
  2. Copyright (c) 2014-2017 Chukong Technologies Inc.
  3. http://www.cocos2d-x.org
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. ****************************************************************************/
  20. #ifndef __CCANIMATIONCURVE_H__
  21. #define __CCANIMATIONCURVE_H__
  22. #include <cmath>
  23. #include <functional>
  24. #include "platform/CCPlatformMacros.h"
  25. #include "base/CCRef.h"
  26. #include "math/CCMath.h"
  27. #if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
  28. #undef NEAR
  29. #endif
  30. NS_CC_BEGIN
  31. /**
  32. * @addtogroup _3d
  33. * @{
  34. */
  35. /**
  36. * Evaluate Type
  37. */
  38. enum class EvaluateType
  39. {
  40. INT_LINEAR,
  41. INT_NEAR,
  42. INT_QUAT_SLERP,
  43. INT_USER_FUNCTION,
  44. };
  45. /**
  46. * @brief curve of bone's position, rotation or scale
  47. *
  48. * @lua NA
  49. */
  50. template <int componentSize>
  51. class AnimationCurve: public Ref
  52. {
  53. public:
  54. /**create animation curve*/
  55. static AnimationCurve* create(float* keytime, float* value, int count);
  56. /**
  57. * evaluate value of time
  58. * @param time Time to be estimated
  59. * @param dst Estimated value of that time
  60. * @param type EvaluateType
  61. */
  62. void evaluate(float time, float* dst, EvaluateType type) const;
  63. /**set evaluate function, allow the user use own function*/
  64. void setEvaluateFun(std::function<void(float time, float* dst)> fun);
  65. /**get start time*/
  66. float getStartTime() const;
  67. /**get end time*/
  68. float getEndTime() const;
  69. CC_CONSTRUCTOR_ACCESS:
  70. AnimationCurve();
  71. virtual ~AnimationCurve();
  72. /**
  73. * Determine index by time.
  74. */
  75. int determineIndex(float time) const;
  76. protected:
  77. float* _value; //
  78. float* _keytime; //key time(0 - 1), start time _keytime[0], end time _keytime[_count - 1]
  79. int _count;
  80. int _componentSizeByte; //component size in byte, position and scale 3 * sizeof(float), rotation 4 * sizeof(float)
  81. std::function<void(float time, float* dst)> _evaluateFun; //user defined function
  82. };
  83. // end of 3d group
  84. /// @}
  85. NS_CC_END
  86. #include "3d/CCAnimationCurve.inl"
  87. #endif