summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorCoderForTheBetter <marcumjp@gmail.com>2018-11-28 03:38:50 -0500
committerLoïc Blot <nerzhul@users.noreply.github.com>2018-11-28 09:38:50 +0100
commitfaa358e797128ab07bb5644ce305a832d59e5596 (patch)
treedcf05ef0611b839503c4845fd89ad9519ee1c4bb /src/util
parent9519d57017cfa28eb4f2fbf3c780f826017bbb00 (diff)
downloadminetest-faa358e797128ab07bb5644ce305a832d59e5596.tar.gz
minetest-faa358e797128ab07bb5644ce305a832d59e5596.tar.bz2
minetest-faa358e797128ab07bb5644ce305a832d59e5596.zip
Add Lua methods 'set_rotation()' and 'get_rotation()' (#7395)
* Adds Lua methods 'set_rotation()' and 'get_rotation'. Also changed some method names to be more clear. Instead of an f32 being sent over network for yaw, now a v3f is sent for rotation on xyz axes. Perserved Lua method set_yaw/setyaw so that old mods still work, other wise to set yaw they would need to switch to set_rotation(0, yaw, 0).
Diffstat (limited to 'src/util')
-rw-r--r--src/util/numeric.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/util/numeric.h b/src/util/numeric.h
index b1e2845b8..bfdff84a0 100644
--- a/src/util/numeric.h
+++ b/src/util/numeric.h
@@ -182,6 +182,23 @@ inline float wrapDegrees_0_360(float f)
}
+/** Returns \p v3f wrapped to the range [0, 360]
+ */
+inline v3f wrapDegrees_0_360_v3f(v3f v)
+{
+ v3f value_v3f;
+ value_v3f.X = modulo360f(v.X);
+ value_v3f.Y = modulo360f(v.Y);
+ value_v3f.Z = modulo360f(v.Z);
+
+ // Now that values are wrapped, use to get values for certain ranges
+ value_v3f.X = value_v3f.X < 0 ? value_v3f.X + 360 : value_v3f.X;
+ value_v3f.Y = value_v3f.Y < 0 ? value_v3f.Y + 360 : value_v3f.Y;
+ value_v3f.Z = value_v3f.Z < 0 ? value_v3f.Z + 360 : value_v3f.Z;
+ return value_v3f;
+}
+
+
/** Returns \p f wrapped to the range [-180, 180]
*/
inline float wrapDegrees_180(float f)