easing.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 transitions
  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. #elif GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
  24. # pragma message("GLM: GLM_GTX_easing extension included")
  25. #endif
  26. namespace glm{
  27. /// @addtogroup gtx_easing
  28. /// @{
  29. /// Modelled after the line y = x
  30. /// @see gtx_easing
  31. template <typename genType>
  32. GLM_FUNC_DECL genType linearInterpolation(genType const & a);
  33. /// Modelled after the parabola y = x^2
  34. /// @see gtx_easing
  35. template <typename genType>
  36. GLM_FUNC_DECL genType quadraticEaseIn(genType const & a);
  37. /// Modelled after the parabola y = -x^2 + 2x
  38. /// @see gtx_easing
  39. template <typename genType>
  40. GLM_FUNC_DECL genType quadraticEaseOut(genType const & a);
  41. /// Modelled after the piecewise quadratic
  42. /// y = (1/2)((2x)^2) ; [0, 0.5)
  43. /// y = -(1/2)((2x-1)*(2x-3) - 1) ; [0.5, 1]
  44. /// @see gtx_easing
  45. template <typename genType>
  46. GLM_FUNC_DECL genType quadraticEaseInOut(genType const & a);
  47. /// Modelled after the cubic y = x^3
  48. template <typename genType>
  49. GLM_FUNC_DECL genType cubicEaseIn(genType const & a);
  50. /// Modelled after the cubic y = (x - 1)^3 + 1
  51. /// @see gtx_easing
  52. template <typename genType>
  53. GLM_FUNC_DECL genType cubicEaseOut(genType const & a);
  54. /// Modelled after the piecewise cubic
  55. /// y = (1/2)((2x)^3) ; [0, 0.5)
  56. /// y = (1/2)((2x-2)^3 + 2) ; [0.5, 1]
  57. /// @see gtx_easing
  58. template <typename genType>
  59. GLM_FUNC_DECL genType cubicEaseInOut(genType const & a);
  60. /// Modelled after the quartic x^4
  61. /// @see gtx_easing
  62. template <typename genType>
  63. GLM_FUNC_DECL genType quarticEaseIn(genType const & a);
  64. /// Modelled after the quartic y = 1 - (x - 1)^4
  65. /// @see gtx_easing
  66. template <typename genType>
  67. GLM_FUNC_DECL genType quarticEaseOut(genType const & a);
  68. /// Modelled after the piecewise quartic
  69. /// y = (1/2)((2x)^4) ; [0, 0.5)
  70. /// y = -(1/2)((2x-2)^4 - 2) ; [0.5, 1]
  71. /// @see gtx_easing
  72. template <typename genType>
  73. GLM_FUNC_DECL genType quarticEaseInOut(genType const & a);
  74. /// Modelled after the quintic y = x^5
  75. /// @see gtx_easing
  76. template <typename genType>
  77. GLM_FUNC_DECL genType quinticEaseIn(genType const & a);
  78. /// Modelled after the quintic y = (x - 1)^5 + 1
  79. /// @see gtx_easing
  80. template <typename genType>
  81. GLM_FUNC_DECL genType quinticEaseOut(genType const & a);
  82. /// Modelled after the piecewise quintic
  83. /// y = (1/2)((2x)^5) ; [0, 0.5)
  84. /// y = (1/2)((2x-2)^5 + 2) ; [0.5, 1]
  85. /// @see gtx_easing
  86. template <typename genType>
  87. GLM_FUNC_DECL genType quinticEaseInOut(genType const & a);
  88. /// Modelled after quarter-cycle of sine wave
  89. /// @see gtx_easing
  90. template <typename genType>
  91. GLM_FUNC_DECL genType sineEaseIn(genType const & a);
  92. /// Modelled after quarter-cycle of sine wave (different phase)
  93. /// @see gtx_easing
  94. template <typename genType>
  95. GLM_FUNC_DECL genType sineEaseOut(genType const & a);
  96. /// Modelled after half sine wave
  97. /// @see gtx_easing
  98. template <typename genType>
  99. GLM_FUNC_DECL genType sineEaseInOut(genType const & a);
  100. /// Modelled after shifted quadrant IV of unit circle
  101. /// @see gtx_easing
  102. template <typename genType>
  103. GLM_FUNC_DECL genType circularEaseIn(genType const & a);
  104. /// Modelled after shifted quadrant II of unit circle
  105. /// @see gtx_easing
  106. template <typename genType>
  107. GLM_FUNC_DECL genType circularEaseOut(genType const & a);
  108. /// Modelled after the piecewise circular function
  109. /// y = (1/2)(1 - sqrt(1 - 4x^2)) ; [0, 0.5)
  110. /// y = (1/2)(sqrt(-(2x - 3)*(2x - 1)) + 1) ; [0.5, 1]
  111. /// @see gtx_easing
  112. template <typename genType>
  113. GLM_FUNC_DECL genType circularEaseInOut(genType const & a);
  114. /// Modelled after the exponential function y = 2^(10(x - 1))
  115. /// @see gtx_easing
  116. template <typename genType>
  117. GLM_FUNC_DECL genType exponentialEaseIn(genType const & a);
  118. /// Modelled after the exponential function y = -2^(-10x) + 1
  119. /// @see gtx_easing
  120. template <typename genType>
  121. GLM_FUNC_DECL genType exponentialEaseOut(genType const & a);
  122. /// Modelled after the piecewise exponential
  123. /// y = (1/2)2^(10(2x - 1)) ; [0,0.5)
  124. /// y = -(1/2)*2^(-10(2x - 1))) + 1 ; [0.5,1]
  125. /// @see gtx_easing
  126. template <typename genType>
  127. GLM_FUNC_DECL genType exponentialEaseInOut(genType const & a);
  128. /// Modelled after the damped sine wave y = sin(13pi/2*x)*pow(2, 10 * (x - 1))
  129. /// @see gtx_easing
  130. template <typename genType>
  131. GLM_FUNC_DECL genType elasticEaseIn(genType const & a);
  132. /// Modelled after the damped sine wave y = sin(-13pi/2*(x + 1))*pow(2, -10x) + 1
  133. /// @see gtx_easing
  134. template <typename genType>
  135. GLM_FUNC_DECL genType elasticEaseOut(genType const & a);
  136. /// Modelled after the piecewise exponentially-damped sine wave:
  137. /// y = (1/2)*sin(13pi/2*(2*x))*pow(2, 10 * ((2*x) - 1)) ; [0,0.5)
  138. /// y = (1/2)*(sin(-13pi/2*((2x-1)+1))*pow(2,-10(2*x-1)) + 2) ; [0.5, 1]
  139. /// @see gtx_easing
  140. template <typename genType>
  141. GLM_FUNC_DECL genType elasticEaseInOut(genType const & a);
  142. /// @see gtx_easing
  143. template <typename genType>
  144. GLM_FUNC_DECL genType backEaseIn(genType const& a);
  145. /// @see gtx_easing
  146. template <typename genType>
  147. GLM_FUNC_DECL genType backEaseOut(genType const& a);
  148. /// @see gtx_easing
  149. template <typename genType>
  150. GLM_FUNC_DECL genType backEaseInOut(genType const& a);
  151. /// @param a parameter
  152. /// @param o Optional overshoot modifier
  153. /// @see gtx_easing
  154. template <typename genType>
  155. GLM_FUNC_DECL genType backEaseIn(genType const& a, genType const& o);
  156. /// @param a parameter
  157. /// @param o Optional overshoot modifier
  158. /// @see gtx_easing
  159. template <typename genType>
  160. GLM_FUNC_DECL genType backEaseOut(genType const& a, genType const& o);
  161. /// @param a parameter
  162. /// @param o Optional overshoot modifier
  163. /// @see gtx_easing
  164. template <typename genType>
  165. GLM_FUNC_DECL genType backEaseInOut(genType const& a, genType const& o);
  166. /// @see gtx_easing
  167. template <typename genType>
  168. GLM_FUNC_DECL genType bounceEaseIn(genType const& a);
  169. /// @see gtx_easing
  170. template <typename genType>
  171. GLM_FUNC_DECL genType bounceEaseOut(genType const& a);
  172. /// @see gtx_easing
  173. template <typename genType>
  174. GLM_FUNC_DECL genType bounceEaseInOut(genType const& a);
  175. /// @}
  176. }//namespace glm
  177. #include "easing.inl"