Skip to content

Commit

Permalink
Animation.h:
Browse files Browse the repository at this point in the history
* Renaming TransitionAnimation -> TransitionAnimationInOut.
* Renaming TransitionAnimationLinear -> TransitionAnimationSingle.
* TransitionAnimationSIngle now supports using an easing.
* Easing arguments are all defaulting to easings::ease_lin.
  • Loading branch information
razterizer committed Dec 2, 2024
1 parent 84a11c6 commit f31f6d4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace easings
}


struct TransitionAnimation
struct TransitionAnimationInOut
{
float transition_start_time_s = 0.f;
// Relative to transition_start_time_s.
Expand All @@ -39,7 +39,8 @@ struct TransitionAnimation
float exit_rel_end_time_s = 0.f;

float animate(float time_s, float value_start, float value_stationary, float value_end,
std::function<float(float)>& ease_enter_func, std::function<float(float)>& ease_exit_func) const
std::function<float(float)>& ease_enter_func = easings::ease_lin,
std::function<float(float)>& ease_exit_func = easings::ease_lin) const
{
auto rel_time_s = time_s - transition_start_time_s;

Expand Down Expand Up @@ -70,14 +71,15 @@ struct TransitionAnimation
};


struct TransitionAnimationLinear
struct TransitionAnimationSingle
{
float transition_start_time_s = 0.f;
// Relative to transition_start_time_s.
float enter_rel_start_time_s = 0.f;
float exit_rel_end_time_s = 0.f;

float animate(float time_s, float value_start, float value_end) const
float animate(float time_s, float value_start, float value_end,
std::function<float(float)>& ease_func = easings::ease_lin) const
{
auto rel_time_s = time_s - transition_start_time_s;

Expand All @@ -86,7 +88,7 @@ struct TransitionAnimationLinear
return value_start;
if (math::in_range<float>(t, 1.f, {}, Range::ClosedFree))
return value_end;
return math::lerp(t, value_start, value_end);
return math::lerp(ease_func(t), value_start, value_end);
}

bool in_range(float time_s) const
Expand Down

0 comments on commit f31f6d4

Please sign in to comment.