Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

438 lines
11KB

  1. /// @ref gtx_easing
  2. /// @file glm/gtx/easing.inl
  3. #include <cmath>
  4. namespace glm{
  5. template <typename genType>
  6. GLM_FUNC_QUALIFIER genType linearInterpolation(genType const& a)
  7. {
  8. // Only defined in [0, 1]
  9. assert(a >= zero<genType>());
  10. assert(a <= one<genType>());
  11. return a;
  12. }
  13. template <typename genType>
  14. GLM_FUNC_QUALIFIER genType quadraticEaseIn(genType const& a)
  15. {
  16. // Only defined in [0, 1]
  17. assert(a >= zero<genType>());
  18. assert(a <= one<genType>());
  19. return a * a;
  20. }
  21. template <typename genType>
  22. GLM_FUNC_QUALIFIER genType quadraticEaseOut(genType const& a)
  23. {
  24. // Only defined in [0, 1]
  25. assert(a >= zero<genType>());
  26. assert(a <= one<genType>());
  27. return -(a * (a - static_cast<genType>(2)));
  28. }
  29. template <typename genType>
  30. GLM_FUNC_QUALIFIER genType quadraticEaseInOut(genType const& a)
  31. {
  32. // Only defined in [0, 1]
  33. assert(a >= zero<genType>());
  34. assert(a <= one<genType>());
  35. if(a < static_cast<genType>(0.5))
  36. {
  37. return static_cast<genType>(2) * a * a;
  38. }
  39. else
  40. {
  41. return (-static_cast<genType>(2) * a * a) + (4 * a) - one<genType>();
  42. }
  43. }
  44. template <typename genType>
  45. GLM_FUNC_QUALIFIER genType cubicEaseIn(genType const& a)
  46. {
  47. // Only defined in [0, 1]
  48. assert(a >= zero<genType>());
  49. assert(a <= one<genType>());
  50. return a * a * a;
  51. }
  52. template <typename genType>
  53. GLM_FUNC_QUALIFIER genType cubicEaseOut(genType const& a)
  54. {
  55. // Only defined in [0, 1]
  56. assert(a >= zero<genType>());
  57. assert(a <= one<genType>());
  58. genType const f = a - one<genType>();
  59. return f * f * f + one<genType>();
  60. }
  61. template <typename genType>
  62. GLM_FUNC_QUALIFIER genType cubicEaseInOut(genType const& a)
  63. {
  64. // Only defined in [0, 1]
  65. assert(a >= zero<genType>());
  66. assert(a <= one<genType>());
  67. if (a < static_cast<genType>(0.5))
  68. {
  69. return static_cast<genType>(4) * a * a * a;
  70. }
  71. else
  72. {
  73. genType const f = ((static_cast<genType>(2) * a) - static_cast<genType>(2));
  74. return static_cast<genType>(0.5) * f * f * f + one<genType>();
  75. }
  76. }
  77. template <typename genType>
  78. GLM_FUNC_QUALIFIER genType quarticEaseIn(genType const& a)
  79. {
  80. // Only defined in [0, 1]
  81. assert(a >= zero<genType>());
  82. assert(a <= one<genType>());
  83. return a * a * a * a;
  84. }
  85. template <typename genType>
  86. GLM_FUNC_QUALIFIER genType quarticEaseOut(genType const& a)
  87. {
  88. // Only defined in [0, 1]
  89. assert(a >= zero<genType>());
  90. assert(a <= one<genType>());
  91. genType const f = (a - one<genType>());
  92. return f * f * f * (one<genType>() - a) + one<genType>();
  93. }
  94. template <typename genType>
  95. GLM_FUNC_QUALIFIER genType quarticEaseInOut(genType const& a)
  96. {
  97. // Only defined in [0, 1]
  98. assert(a >= zero<genType>());
  99. assert(a <= one<genType>());
  100. if(a < static_cast<genType>(0.5))
  101. {
  102. return static_cast<genType>(8) * a * a * a * a;
  103. }
  104. else
  105. {
  106. genType const f = (a - one<genType>());
  107. return -static_cast<genType>(8) * f * f * f * f + one<genType>();
  108. }
  109. }
  110. template <typename genType>
  111. GLM_FUNC_QUALIFIER genType quinticEaseIn(genType const& a)
  112. {
  113. // Only defined in [0, 1]
  114. assert(a >= zero<genType>());
  115. assert(a <= one<genType>());
  116. return a * a * a * a * a;
  117. }
  118. template <typename genType>
  119. GLM_FUNC_QUALIFIER genType quinticEaseOut(genType const& a)
  120. {
  121. // Only defined in [0, 1]
  122. assert(a >= zero<genType>());
  123. assert(a <= one<genType>());
  124. genType const f = (a - one<genType>());
  125. return f * f * f * f * f + one<genType>();
  126. }
  127. template <typename genType>
  128. GLM_FUNC_QUALIFIER genType quinticEaseInOut(genType const& a)
  129. {
  130. // Only defined in [0, 1]
  131. assert(a >= zero<genType>());
  132. assert(a <= one<genType>());
  133. if(a < static_cast<genType>(0.5))
  134. {
  135. return static_cast<genType>(16) * a * a * a * a * a;
  136. }
  137. else
  138. {
  139. genType const f = ((static_cast<genType>(2) * a) - static_cast<genType>(2));
  140. return static_cast<genType>(0.5) * f * f * f * f * f + one<genType>();
  141. }
  142. }
  143. template <typename genType>
  144. GLM_FUNC_QUALIFIER genType sineEaseIn(genType const& a)
  145. {
  146. // Only defined in [0, 1]
  147. assert(a >= zero<genType>());
  148. assert(a <= one<genType>());
  149. return sin((a - one<genType>()) * half_pi<genType>()) + one<genType>();
  150. }
  151. template <typename genType>
  152. GLM_FUNC_QUALIFIER genType sineEaseOut(genType const& a)
  153. {
  154. // Only defined in [0, 1]
  155. assert(a >= zero<genType>());
  156. assert(a <= one<genType>());
  157. return sin(a * half_pi<genType>());
  158. }
  159. template <typename genType>
  160. GLM_FUNC_QUALIFIER genType sineEaseInOut(genType const& a)
  161. {
  162. // Only defined in [0, 1]
  163. assert(a >= zero<genType>());
  164. assert(a <= one<genType>());
  165. return static_cast<genType>(0.5) * (one<genType>() - cos(a * pi<genType>()));
  166. }
  167. template <typename genType>
  168. GLM_FUNC_QUALIFIER genType circularEaseIn(genType const& a)
  169. {
  170. // Only defined in [0, 1]
  171. assert(a >= zero<genType>());
  172. assert(a <= one<genType>());
  173. return one<genType>() - sqrt(one<genType>() - (a * a));
  174. }
  175. template <typename genType>
  176. GLM_FUNC_QUALIFIER genType circularEaseOut(genType const& a)
  177. {
  178. // Only defined in [0, 1]
  179. assert(a >= zero<genType>());
  180. assert(a <= one<genType>());
  181. return sqrt((static_cast<genType>(2) - a) * a);
  182. }
  183. template <typename genType>
  184. GLM_FUNC_QUALIFIER genType circularEaseInOut(genType const& a)
  185. {
  186. // Only defined in [0, 1]
  187. assert(a >= zero<genType>());
  188. assert(a <= one<genType>());
  189. if(a < static_cast<genType>(0.5))
  190. {
  191. return static_cast<genType>(0.5) * (one<genType>() - std::sqrt(one<genType>() - static_cast<genType>(4) * (a * a)));
  192. }
  193. else
  194. {
  195. return static_cast<genType>(0.5) * (std::sqrt(-((static_cast<genType>(2) * a) - static_cast<genType>(3)) * ((static_cast<genType>(2) * a) - one<genType>())) + one<genType>());
  196. }
  197. }
  198. template <typename genType>
  199. GLM_FUNC_QUALIFIER genType exponentialEaseIn(genType const& a)
  200. {
  201. // Only defined in [0, 1]
  202. assert(a >= zero<genType>());
  203. assert(a <= one<genType>());
  204. if(a <= zero<genType>())
  205. return a;
  206. else
  207. {
  208. genType const Complementary = a - one<genType>();
  209. genType const Two = static_cast<genType>(2);
  210. return glm::pow(Two, Complementary * static_cast<genType>(10));
  211. }
  212. }
  213. template <typename genType>
  214. GLM_FUNC_QUALIFIER genType exponentialEaseOut(genType const& a)
  215. {
  216. // Only defined in [0, 1]
  217. assert(a >= zero<genType>());
  218. assert(a <= one<genType>());
  219. if(a >= one<genType>())
  220. return a;
  221. else
  222. {
  223. return one<genType>() - glm::pow(static_cast<genType>(2), -static_cast<genType>(10) * a);
  224. }
  225. }
  226. template <typename genType>
  227. GLM_FUNC_QUALIFIER genType exponentialEaseInOut(genType const& a)
  228. {
  229. // Only defined in [0, 1]
  230. assert(a >= zero<genType>());
  231. assert(a <= one<genType>());
  232. if(a < static_cast<genType>(0.5))
  233. return static_cast<genType>(0.5) * glm::pow(static_cast<genType>(2), (static_cast<genType>(20) * a) - static_cast<genType>(10));
  234. else
  235. return -static_cast<genType>(0.5) * glm::pow(static_cast<genType>(2), (-static_cast<genType>(20) * a) + static_cast<genType>(10)) + one<genType>();
  236. }
  237. template <typename genType>
  238. GLM_FUNC_QUALIFIER genType elasticEaseIn(genType const& a)
  239. {
  240. // Only defined in [0, 1]
  241. assert(a >= zero<genType>());
  242. assert(a <= one<genType>());
  243. return std::sin(static_cast<genType>(13) * half_pi<genType>() * a) * glm::pow(static_cast<genType>(2), static_cast<genType>(10) * (a - one<genType>()));
  244. }
  245. template <typename genType>
  246. GLM_FUNC_QUALIFIER genType elasticEaseOut(genType const& a)
  247. {
  248. // Only defined in [0, 1]
  249. assert(a >= zero<genType>());
  250. assert(a <= one<genType>());
  251. return std::sin(-static_cast<genType>(13) * half_pi<genType>() * (a + one<genType>())) * glm::pow(static_cast<genType>(2), -static_cast<genType>(10) * a) + one<genType>();
  252. }
  253. template <typename genType>
  254. GLM_FUNC_QUALIFIER genType elasticEaseInOut(genType const& a)
  255. {
  256. // Only defined in [0, 1]
  257. assert(a >= zero<genType>());
  258. assert(a <= one<genType>());
  259. if(a < static_cast<genType>(0.5))
  260. return static_cast<genType>(0.5) * std::sin(static_cast<genType>(13) * half_pi<genType>() * (static_cast<genType>(2) * a)) * glm::pow(static_cast<genType>(2), static_cast<genType>(10) * ((static_cast<genType>(2) * a) - one<genType>()));
  261. else
  262. return static_cast<genType>(0.5) * (std::sin(-static_cast<genType>(13) * half_pi<genType>() * ((static_cast<genType>(2) * a - one<genType>()) + one<genType>())) * glm::pow(static_cast<genType>(2), -static_cast<genType>(10) * (static_cast<genType>(2) * a - one<genType>())) + static_cast<genType>(2));
  263. }
  264. template <typename genType>
  265. GLM_FUNC_QUALIFIER genType backEaseIn(genType const& a, genType const& o)
  266. {
  267. // Only defined in [0, 1]
  268. assert(a >= zero<genType>());
  269. assert(a <= one<genType>());
  270. genType z = ((o + one<genType>()) * a) - o;
  271. return (a * a * z);
  272. }
  273. template <typename genType>
  274. GLM_FUNC_QUALIFIER genType backEaseOut(genType const& a, genType const& o)
  275. {
  276. // Only defined in [0, 1]
  277. assert(a >= zero<genType>());
  278. assert(a <= one<genType>());
  279. genType n = a - one<genType>();
  280. genType z = ((o + one<genType>()) * n) + o;
  281. return (n * n * z) + one<genType>();
  282. }
  283. template <typename genType>
  284. GLM_FUNC_QUALIFIER genType backEaseInOut(genType const& a, genType const& o)
  285. {
  286. // Only defined in [0, 1]
  287. assert(a >= zero<genType>());
  288. assert(a <= one<genType>());
  289. genType s = o * static_cast<genType>(1.525);
  290. genType x = static_cast<genType>(0.5);
  291. genType n = a / static_cast<genType>(0.5);
  292. if (n < static_cast<genType>(1))
  293. {
  294. genType z = ((s + static_cast<genType>(1)) * n) - s;
  295. genType m = n * n * z;
  296. return x * m;
  297. }
  298. else
  299. {
  300. n -= static_cast<genType>(2);
  301. genType z = ((s + static_cast<genType>(1)) * n) + s;
  302. genType m = (n*n*z) + static_cast<genType>(2);
  303. return x * m;
  304. }
  305. }
  306. template <typename genType>
  307. GLM_FUNC_QUALIFIER genType backEaseIn(genType const& a)
  308. {
  309. return backEaseIn(a, static_cast<genType>(1.70158));
  310. }
  311. template <typename genType>
  312. GLM_FUNC_QUALIFIER genType backEaseOut(genType const& a)
  313. {
  314. return backEaseOut(a, static_cast<genType>(1.70158));
  315. }
  316. template <typename genType>
  317. GLM_FUNC_QUALIFIER genType backEaseInOut(genType const& a)
  318. {
  319. return backEaseInOut(a, static_cast<genType>(1.70158));
  320. }
  321. template <typename genType>
  322. GLM_FUNC_QUALIFIER genType bounceEaseOut(genType const& a)
  323. {
  324. // Only defined in [0, 1]
  325. assert(a >= zero<genType>());
  326. assert(a <= one<genType>());
  327. if(a < static_cast<genType>(4.0 / 11.0))
  328. {
  329. return (static_cast<genType>(121) * a * a) / static_cast<genType>(16);
  330. }
  331. else if(a < static_cast<genType>(8.0 / 11.0))
  332. {
  333. return (static_cast<genType>(363.0 / 40.0) * a * a) - (static_cast<genType>(99.0 / 10.0) * a) + static_cast<genType>(17.0 / 5.0);
  334. }
  335. else if(a < static_cast<genType>(9.0 / 10.0))
  336. {
  337. return (static_cast<genType>(4356.0 / 361.0) * a * a) - (static_cast<genType>(35442.0 / 1805.0) * a) + static_cast<genType>(16061.0 / 1805.0);
  338. }
  339. else
  340. {
  341. return (static_cast<genType>(54.0 / 5.0) * a * a) - (static_cast<genType>(513.0 / 25.0) * a) + static_cast<genType>(268.0 / 25.0);
  342. }
  343. }
  344. template <typename genType>
  345. GLM_FUNC_QUALIFIER genType bounceEaseIn(genType const& a)
  346. {
  347. // Only defined in [0, 1]
  348. assert(a >= zero<genType>());
  349. assert(a <= one<genType>());
  350. return one<genType>() - bounceEaseOut(one<genType>() - a);
  351. }
  352. template <typename genType>
  353. GLM_FUNC_QUALIFIER genType bounceEaseInOut(genType const& a)
  354. {
  355. // Only defined in [0, 1]
  356. assert(a >= zero<genType>());
  357. assert(a <= one<genType>());
  358. if(a < static_cast<genType>(0.5))
  359. {
  360. return static_cast<genType>(0.5) * (one<genType>() - bounceEaseOut(a * static_cast<genType>(2)));
  361. }
  362. else
  363. {
  364. return static_cast<genType>(0.5) * bounceEaseOut(a * static_cast<genType>(2) - one<genType>()) + static_cast<genType>(0.5);
  365. }
  366. }
  367. }//namespace glm