From 48801a69da7eec36a7f77b2f305f23a91dfdd45b Mon Sep 17 00:00:00 2001 From: lisyarus Date: Thu, 4 Aug 2022 11:43:07 +0300 Subject: [PATCH] Add geom::smoothstep & smootherstep --- libs/geom/include/psemek/geom/easing.hpp | 4 +++- libs/geom/include/psemek/geom/math.hpp | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/libs/geom/include/psemek/geom/easing.hpp b/libs/geom/include/psemek/geom/easing.hpp index 40adce6b..4e116a9a 100644 --- a/libs/geom/include/psemek/geom/easing.hpp +++ b/libs/geom/include/psemek/geom/easing.hpp @@ -1,5 +1,7 @@ #pragma once +#include + #include namespace psemek::geom @@ -26,7 +28,7 @@ namespace psemek::geom case easing_type::linear: return t; case easing_type::quadratic_in: return t * t; case easing_type::quadratic_out: return t * (2 - t); - case easing_type::cubic: return t * t * (3 - 2 * t); + case easing_type::cubic: return smoothstep(t); default: assert(false); } diff --git a/libs/geom/include/psemek/geom/math.hpp b/libs/geom/include/psemek/geom/math.hpp index 89855458..28660c95 100644 --- a/libs/geom/include/psemek/geom/math.hpp +++ b/libs/geom/include/psemek/geom/math.hpp @@ -193,4 +193,16 @@ namespace psemek::geom return false; } + template + T smoothstep(T x) + { + return x * x * (3 - 2 * x); + } + + template + T smootherstep(T x) + { + return x * x * x * (10 - x * (15 - 6 * x)); + } + }