afxEase.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  2. // Arcane-FX for MIT Licensed Open Source version of Torque 3D from GarageGames
  3. // Copyright (C) 2015 Faust Logic, Inc.
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to
  7. // deal in the Software without restriction, including without limitation the
  8. // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9. // sell copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. // IN THE SOFTWARE.
  22. //
  23. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  24. #include "afx/arcaneFX.h"
  25. #include "afxEase.h"
  26. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//
  27. F32
  28. afxEase::t(F32 t, F32 ein, F32 eout)
  29. {
  30. if (t == 0.0)
  31. return 0.0;
  32. if (t == 1.0)
  33. return 1.0;
  34. F32 ee = eout - ein + 1.0;
  35. // ease in section
  36. if (t <= ein)
  37. {
  38. F32 tin = t/ein;
  39. return (mSin(M_PI_F*(tin - 1.0)) + M_PI_F*tin)*ein*(1.0/M_PI_F)/ee;
  40. }
  41. // middle linear section
  42. else if (t <= eout)
  43. {
  44. return (2.0*t - ein)/ee;
  45. }
  46. // ease out section
  47. else
  48. {
  49. F32 iout = 1.0 - eout;
  50. F32 g = (t - eout)*M_PI_F/iout;
  51. return ((mSin(g) + g)*(iout)/M_PI_F + 2.0*eout - ein)*1.0/ee + 0.0;
  52. }
  53. }
  54. F32
  55. afxEase::eq(F32 t, F32 a, F32 b, F32 ein, F32 eout)
  56. {
  57. if (t == 0.0)
  58. return a;
  59. if (t == 1.0)
  60. return b;
  61. F32 ab = b - a;
  62. F32 ee = eout - ein + 1.0;
  63. // ease in section
  64. if (t <= ein)
  65. {
  66. F32 tin = t/ein;
  67. return a + (mSin(M_PI_F*(tin - 1.0)) + M_PI_F*tin)*ab*ein*(1.0/M_PI_F)/ee;
  68. }
  69. // middle linear section
  70. else if (t <= eout)
  71. {
  72. return a + ab*(2.0*t - ein)/ee;
  73. }
  74. // ease out section
  75. else
  76. {
  77. F32 iout = 1.0 - eout;
  78. F32 g = (t - eout)*M_PI_F/iout;
  79. return ((mSin(g) + g)*(iout)/M_PI_F + 2.0*eout - ein)*ab/ee + a;
  80. }
  81. }
  82. //~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~//~~~~~~~~~~~~~~~~~~~~~//