aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2018-08-03 00:25:37 +0200
committerParamat <paramat@users.noreply.github.com>2018-08-02 23:25:37 +0100
commitf3997025fd4785606fe4f8b05037e9463c5be7da (patch)
treefb334a76f0781a2dd944f25b3e4969cd56a5241a /src/util
parent741e3efaf5c8e6d85178051d8655971a7f8b0bb9 (diff)
downloadminetest-f3997025fd4785606fe4f8b05037e9463c5be7da.tar.gz
minetest-f3997025fd4785606fe4f8b05037e9463c5be7da.tar.bz2
minetest-f3997025fd4785606fe4f8b05037e9463c5be7da.zip
Smoothed yaw rotation for objects (#6825)
Diffstat (limited to 'src/util')
-rw-r--r--src/util/numeric.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/util/numeric.h b/src/util/numeric.h
index f7df19ca9..61370a3f4 100644
--- a/src/util/numeric.h
+++ b/src/util/numeric.h
@@ -376,3 +376,22 @@ inline u32 npot2(u32 orig) {
orig |= orig >> 16;
return orig + 1;
}
+
+// Gradual steps towards the target value in a wrapped (circular) system
+// using the shorter of both ways
+template<typename T>
+inline void wrappedApproachShortest(T &current, const T target, const T stepsize,
+ const T maximum)
+{
+ T delta = target - current;
+ if (delta < 0)
+ delta += maximum;
+
+ if (delta > stepsize && maximum - delta > stepsize) {
+ current += (delta < maximum / 2) ? stepsize : -stepsize;
+ if (current >= maximum)
+ current -= maximum;
+ } else {
+ current = target;
+ }
+}