easing.hpp 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /// @ref gtx_easing
  2. /// @file glm/gtx/easing.hpp
  3. /// @author Robert Chisholm
  4. ///
  5. /// @see core (dependence)
  6. ///
  7. /// @defgroup gtx_easing GLM_GTX_easing
  8. /// @ingroup gtx
  9. ///
  10. /// Include <glm/gtx/easing.hpp> to use the features of this extension.
  11. ///
  12. /// Easing functions for animations and transitons
  13. /// All functions take a parameter x in the range [0.0,1.0]
  14. ///
  15. /// Based on the AHEasing project of Warren Moore (https://github.com/warrenm/AHEasing)
  16. #pragma once
  17. // Dependency:
  18. #include "../glm.hpp"
  19. #include "../gtc/constants.hpp"
  20. #include "../detail/qualifier.hpp"
  21. #ifndef GLM_ENABLE_EXPERIMENTAL
  22. # error "GLM: GLM_GTX_easing is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
  23. #endif
  24. #if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  25. # pragma message("GLM: GLM_GTX_easing extension included")
  26. #endif
  27. namespace glm{
  28. /// @addtogroup gtx_easing
  29. /// @{
  30. /// Modelled after the line y = x
  31. /// @see gtx_easing
  32. template <typename genType>
  33. GLM_FUNC_DECL genType linearInterpolation(genType const & a);
  34. /// Modelled after the parabola y = x^2
  35. /// @see gtx_easing
  36. template <typename genType>
  37. GLM_FUNC_DECL genType quadraticEaseIn(genType const & a);
  38. /// Modelled after the parabola y = -x^2 + 2x
  39. /// @see gtx_easing
  40. template <typename genType>
  41. GLM_FUNC_DECL genType quadraticEaseOut(genType const & a);
  42. /// Modelled after the piecewise quadratic
  43. /// y = (1/2)((2x)^2) ; [0, 0.5)
  44. /// y = -(1/2)((2x-1)*(2x-3) - 1) ; [0.5, 1]
  45. /// @see gtx_easing
  46. template <typename genType>
  47. GLM_FUNC_DECL genType quadraticEaseInOut(genType const & a);
  48. /// Modelled after the cubic y = x^3
  49. template <typename genType>
  50. GLM_FUNC_DECL genType cubicEaseIn(genType const & a);
  51. /// Modelled after the cubic y = (x - 1)^3 + 1
  52. /// @see gtx_easing
  53. template <typename genType>
  54. GLM_FUNC_DECL genType cubicEaseOut(genType const & a);
  55. /// Modelled after the piecewise cubic
  56. /// y = (1/2)((2x)^3) ; [0, 0.5)
  57. /// y = (1/2)((2x-2)^3 + 2) ; [0.5, 1]
  58. /// @see gtx_easing
  59. template <typename genType>
  60. GLM_FUNC_DECL genType cubicEaseInOut(genType const & a);
  61. /// Modelled after the quartic x^4
  62. /// @see gtx_easing
  63. template <typename genType>
  64. GLM_FUNC_DECL genType quarticEaseIn(genType const & a);
  65. /// Modelled after the quartic y = 1 - (x - 1)^4
  66. /// @see gtx_easing
  67. template <typename genType>
  68. GLM_FUNC_DECL genType quarticEaseOut(genType const & a);
  69. /// Modelled after the piecewise quartic
  70. /// y = (1/2)((2x)^4) ; [0, 0.5)
  71. /// y = -(1/2)((2x-2)^4 - 2) ; [0.5, 1]
  72. /// @see gtx_easing
  73. template <typename genType>
  74. GLM_FUNC_DECL genType quarticEaseInOut(genType const & a);
  75. /// Modelled after the quintic y = x^5
  76. /// @see gtx_easing
  77. template <typename genType>
  78. GLM_FUNC_DECL genType quinticEaseIn(genType const & a);
  79. /// Modelled after the quintic y = (x - 1)^5 + 1
  80. /// @see gtx_easing
  81. template <typename genType>
  82. GLM_FUNC_DECL genType quinticEaseOut(genType const & a);
  83. /// Modelled after the piecewise quintic
  84. /// y = (1/2)((2x)^5) ; [0, 0.5)
  85. /// y = (1/2)((2x-2)^5 + 2) ; [0.5, 1]
  86. /// @see gtx_easing
  87. template <typename genType>
  88. GLM_FUNC_DECL genType quinticEaseInOut(genType const & a);
  89. /// Modelled after quarter-cycle of sine wave
  90. /// @see gtx_easing
  91. template <typename genType>
  92. GLM_FUNC_DECL genType sineEaseIn(genType const & a);
  93. /// Modelled after quarter-cycle of sine wave (different phase)
  94. /// @see gtx_easing
  95. template <typename genType>
  96. GLM_FUNC_DECL genType sineEaseOut(genType const & a);
  97. /// Modelled after half sine wave
  98. /// @see gtx_easing
  99. template <typename genType>
  100. GLM_FUNC_DECL genType sineEaseInOut(genType const & a);
  101. /// Modelled after shifted quadrant IV of unit circle
  102. /// @see gtx_easing
  103. template <typename genType>
  104. GLM_FUNC_DECL genType circularEaseIn(genType const & a);
  105. /// Modelled after shifted quadrant II of unit circle
  106. /// @see gtx_easing
  107. template <typename genType>
  108. GLM_FUNC_DECL genType circularEaseOut(genType const & a);
  109. /// Modelled after the piecewise circular function
  110. /// y = (1/2)(1 - sqrt(1 - 4x^2)) ; [0, 0.5)
  111. /// y = (1/2)(sqrt(-(2x - 3)*(2x - 1)) + 1) ; [0.5, 1]
  112. /// @see gtx_easing
  113. template <typename genType>
  114. GLM_FUNC_DECL genType circularEaseInOut(genType const & a);
  115. /// Modelled after the exponential function y = 2^(10(x - 1))
  116. /// @see gtx_easing
  117. template <typename genType>
  118. GLM_FUNC_DECL genType exponentialEaseIn(genType const & a);
  119. /// Modelled after the exponential function y = -2^(-10x) + 1
  120. /// @see gtx_easing
  121. template <typename genType>
  122. GLM_FUNC_DECL genType exponentialEaseOut(genType const & a);
  123. /// Modelled after the piecewise exponential
  124. /// y = (1/2)2^(10(2x - 1)) ; [0,0.5)
  125. /// y = -(1/2)*2^(-10(2x - 1))) + 1 ; [0.5,1]
  126. /// @see gtx_easing
  127. template <typename genType>
  128. GLM_FUNC_DECL genType exponentialEaseInOut(genType const & a);
  129. /// Modelled after the damped sine wave y = sin(13pi/2*x)*pow(2, 10 * (x - 1))
  130. /// @see gtx_easing
  131. template <typename genType>
  132. GLM_FUNC_DECL genType elasticEaseIn(genType const & a);
  133. /// Modelled after the damped sine wave y = sin(-13pi/2*(x + 1))*pow(2, -10x) + 1
  134. /// @see gtx_easing
  135. template <typename genType>
  136. GLM_FUNC_DECL genType elasticEaseOut(genType const & a);
  137. /// Modelled after the piecewise exponentially-damped sine wave:
  138. /// y = (1/2)*sin(13pi/2*(2*x))*pow(2, 10 * ((2*x) - 1)) ; [0,0.5)
  139. /// y = (1/2)*(sin(-13pi/2*((2x-1)+1))*pow(2,-10(2*x-1)) + 2) ; [0.5, 1]
  140. /// @see gtx_easing
  141. template <typename genType>
  142. GLM_FUNC_DECL genType elasticEaseInOut(genType const & a);
  143. /// @see gtx_easing
  144. template <typename genType>
  145. GLM_FUNC_DECL genType backEaseIn(genType const& a);
  146. /// @see gtx_easing
  147. template <typename genType>
  148. GLM_FUNC_DECL genType backEaseOut(genType const& a);
  149. /// @see gtx_easing
  150. template <typename genType>
  151. GLM_FUNC_DECL genType backEaseInOut(genType const& a);
  152. /// @param a parameter
  153. /// @param o Optional overshoot modifier
  154. /// @see gtx_easing
  155. template <typename genType>
  156. GLM_FUNC_DECL genType backEaseIn(genType const& a, genType const& o);
  157. /// @param a parameter
  158. /// @param o Optional overshoot modifier
  159. /// @see gtx_easing
  160. template <typename genType>
  161. GLM_FUNC_DECL genType backEaseOut(genType const& a, genType const& o);
  162. /// @param a parameter
  163. /// @param o Optional overshoot modifier
  164. /// @see gtx_easing
  165. template <typename genType>
  166. GLM_FUNC_DECL genType backEaseInOut(genType const& a, genType const& o);
  167. /// @see gtx_easing
  168. template <typename genType>
  169. GLM_FUNC_DECL genType bounceEaseIn(genType const& a);
  170. /// @see gtx_easing
  171. template <typename genType>
  172. GLM_FUNC_DECL genType bounceEaseOut(genType const& a);
  173. /// @see gtx_easing
  174. template <typename genType>
  175. GLM_FUNC_DECL genType bounceEaseInOut(genType const& a);
  176. /// @}
  177. }//namespace glm
  178. #include "easing.inl"