9
3

easing.hpp 6.7 KB

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