summaryrefslogtreecommitdiffstats
path: root/core/math/math_funcs.h
diff options
context:
space:
mode:
authorTokage <tokage.it.lab@gmail.com>2021-04-25 05:47:03 +0900
committerSilc 'Tokage' Renew <tokage.it.lab@gmail.com>2021-10-09 18:08:43 +0900
commit372ba7666304805abe8641487c97899f9bdd97af (patch)
tree3a5d56b1fd80db923c08fa25c7c3d407b992c496 /core/math/math_funcs.h
parente8c89b2b9158ce011ed5c1a913f55d38226c4a55 (diff)
downloadredot-engine-372ba7666304805abe8641487c97899f9bdd97af.tar.gz
implement ping-pong loop in animation
Co-authored-by: Chaosus <chaosus89@gmail.com>
Diffstat (limited to 'core/math/math_funcs.h')
-rw-r--r--core/math/math_funcs.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 4e4f566517..5824d194a6 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -291,6 +291,19 @@ public:
return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range));
}
+ static _ALWAYS_INLINE_ float fract(float value) {
+ return value - floor(value);
+ }
+ static _ALWAYS_INLINE_ double fract(double value) {
+ return value - floor(value);
+ }
+ static _ALWAYS_INLINE_ float pingpong(float value, float length) {
+ return (length != 0.0f) ? abs(fract((value - length) / (length * 2.0f)) * length * 2.0f - length) : 0.0f;
+ }
+ static _ALWAYS_INLINE_ double pingpong(double value, double length) {
+ return (length != 0.0) ? abs(fract((value - length) / (length * 2.0)) * length * 2.0 - length) : 0.0;
+ }
+
// double only, as these functions are mainly used by the editor and not performance-critical,
static double ease(double p_x, double p_c);
static int step_decimals(double p_step);