fork download
  1. #include "Easer.h"
  2.  
  3. //Sets 'position' to 'newPosition'.
  4. void Easer::SetPosition(float position)
  5. {
  6. this->Position = position;
  7. }
  8.  
  9. //Resets 'position' to 0.0f. This is the same as calling SetPosition(0.0f);
  10. void Easer::Reset()
  11. {
  12. this->Position = 0.0f;
  13. }
  14.  
  15. //Returns true if 'position' is at or beyond 1.0f.
  16. bool Easer::AtEnd() const
  17. {
  18. return (this->Position >= 1.0f);
  19. }
  20.  
  21. //Returns the value at the current position.
  22. //(Note: Unless constrained, the actual result may actually drop below 0.0f or above 1.0f depending
  23. //on the easing function. This is intentional, and desirable for some effects)
  24. float Easer::Get() const
  25. {
  26. return this->plot(this->Position);
  27. }
  28.  
  29. //Returns the value at the current position, scaled to the range of 'min' to 'max' instead of around (0.0f - 1.0f)-ish
  30. float Easer::GetInRange(const FloatRange &range) const
  31. {
  32. float value = this->plot(this->Position);
  33. return range.GetAt(value);
  34. }
  35.  
  36. //Returns the value at 'pos'.
  37. float Easer::GetAt(float pos) const
  38. {
  39. return this->plot(pos);
  40. }
  41.  
  42. //Returns the value at 'pos', scaled to the range of 'min' to 'max' instead of around (0.0f - 1.0f)-ish
  43. float Easer::GetInRangeAt(float pos, const FloatRange &range) const
  44. {
  45. float value = this->plot(pos);
  46. return range.Constrained(value);
  47. }
  48.  
  49. //Moves the position of the ease by 'amount'.
  50. void Easer::Step(float amount)
  51. {
  52. this->Position += amount;
  53. }
  54.  
  55. //Same as Step().
  56. void Easer::operator+=(float amount)
  57. {
  58. this->Step(amount);
  59. }
  60.  
  61. //Same as Step() with a negative amount.
  62. void Easer::operator-=(float amount)
  63. {
  64. this->Step(-amount);
  65. }
  66.  
  67. //Same as SetPosition().
  68. void Easer::operator=(float position)
  69. {
  70. this->SetPosition(position);
  71. }
  72.  
  73. //Same as Get()
  74. float Easer::operator()() const
  75. {
  76. return this->Get();
  77. }
  78.  
  79. //Same as GetAt()
  80. float Easer::operator()(float value) const
  81. {
  82. return this->GetAt(value);
  83. }
  84.  
  85. //Calls the virtual function 'plot' and processes the result depending on the EaseStyle.
  86. float Easer::plot(float position) const
  87. {
  88. //Binds 'position' from 0.0 to 1.0.
  89. //if(position > 1.0f) position = 1.0f;
  90. //if(position < 0.0f) position = 0.0f;
  91.  
  92. float result;
  93.  
  94. if(this->Style == EaseIn)
  95. {
  96. //Plots the position.
  97. result = this->EaseFunc(position);
  98. }
  99. else if(this->Style == EaseOut)
  100. {
  101. //Plots the position.
  102. result = DoEaseOut(this->EaseFunc, position);
  103. }
  104. else if(this->Style == EaseInOut)
  105. {
  106. //Plots the position.
  107. result = DoEaseInOut(this->EaseFunc, position);
  108. }
  109. else if(this->Style == EaseOutIn)
  110. {
  111. //Plots the position.
  112. result = DoEaseOutIn(this->EaseFunc, position);
  113. }
  114.  
  115. //Constrains the result and returns.
  116. return this->Constaints.Constrained(result);
  117. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout

Standard output is empty