fork download
  1. //EaseIn = Start slow, accelerate to the goal.
  2. //EaseOut = Start fast, decelerate to the goal.
  3. //EaseInOut = Start slow, accelerate to the half-way point, decelerate to the goal.
  4. //EaseOutIn = Start fast, decelerate to the half-way point, accelerate to the goal.
  5. enum EaseStyle {EaseIn, EaseOut, EaseInOut, EaseOutIn};
  8. /*
  9.   Easer is an Easing/Tweening/Interpolating functor class.
  10.   You can either use the EaseEquations stand-alone, or pass them to Easer if you want
  11.   persistent data (perhaps holding Easer as a member-variable of another class).
  12. */
  13. class Easer
  14. {
  15. public:
  16. Easer(EaseFunction easeFunction, EaseStyle style = EaseIn) : EaseFunc(easeFunction), Style(style) { }
  17. ~Easer() = default;
  19. EaseStyle Style = EaseIn;
  20. EaseFunction EaseFunc;
  22. //Used to constrain the return result to the desired range, such as 0.0f - 1.0f.
  23. //The default setting is (-FLT_MAX, FLT_MAX). Note: For some funky reason, FLT_MIN is "the minimum positive value above zero". =/
  24. FloatRange Constaints = FloatRange(-FLT_MAX, FLT_MAX);
  26. //The current position.
  27. float Position = 0.0f;
  29. public:
  30. //Sets 'position' to 'newPosition'.
  31. void SetPosition(float position);
  32. //Resets 'position' to 0.0f. This is the same as calling SetPosition(0.0f);
  33. void Reset();
  35. //Returns true if 'position' is at or beyond 1.0f.
  36. bool AtEnd() const;
  38. //Returns the value at the current position.
  39. //(Note: Unless constrained, the actual result may actually drop below 0.0f or above 1.0f depending
  40. //on the easing function. This is intentional, and desirable for some effects)
  41. float Get() const;
  42. //Returns the value at the current position, scaled to the range of 'min' to 'max' instead of around (0.0f - 1.0f)-ish
  43. float GetInRange(const FloatRange &range) const;
  45. //Returns the value at 'pos'.
  46. float GetAt(float pos) const;
  47. //Returns the value at 'pos', scaled to the range of 'min' to 'max' instead of around (0.0f - 1.0f)-ish
  48. float GetInRangeAt(float pos, const FloatRange &range) const;
  50. //Moves the position of the ease by 'amount'.
  51. void Step(float amount);
  53. void operator+=(float amount); //Same as Step().
  54. void operator-=(float amount); //Same as Step() with a negative amount.
  55. void operator=(float position); //Same as SetPosition().
  57. float operator()() const; //Same as Get()
  58. float operator()(float value) const; //Same as GetAt()
  60. private:
  61. //Calls the callback function 'EaseFunc' and processes the result depending on the EaseStyle,
  62. //then constrains the result using 'Constaints'.
  63. float plot(float position) const;
  64. };
Not running #stdin #stdout 0s 0KB
Standard input is empty

Standard output is empty