summaryrefslogtreecommitdiff
path: root/src/utility.h
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2011-10-15 02:28:57 +0300
committerPerttu Ahola <celeron55@gmail.com>2011-10-15 02:28:57 +0300
commit43a28f04fa3ddf4b612f58c25a896293a01567e3 (patch)
tree58ca2cac232c28ffd59609ad3998b97628f13e33 /src/utility.h
parent080002f8ed1af6d34cdc6f5abff0f51586ca831c (diff)
downloadminetest-43a28f04fa3ddf4b612f58c25a896293a01567e3.tar.gz
minetest-43a28f04fa3ddf4b612f58c25a896293a01567e3.tar.bz2
minetest-43a28f04fa3ddf4b612f58c25a896293a01567e3.zip
mobv2
Diffstat (limited to 'src/utility.h')
-rw-r--r--src/utility.h29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/utility.h b/src/utility.h
index f8cc34984..255b75c08 100644
--- a/src/utility.h
+++ b/src/utility.h
@@ -810,6 +810,35 @@ inline float wrapDegrees(float f)
return f;
}
+/* Wrap to 0...360 */
+inline float wrapDegrees_0_360(float f)
+{
+ // Take examples of f=10, f=720.5, f=-0.5, f=-360.5
+ // This results in
+ // 10, 720, -1, -361
+ int i = floor(f);
+ // 0, 2, 0, -1
+ int l = i / 360;
+ // Wrap to 0...360
+ // 0, 2, -1, -2
+ if(i < 0)
+ l -= 1;
+ // 0, 720, 0, -360
+ int k = l * 360;
+ // 10, 0.5, -0.5, -0.5
+ f -= float(k);
+ return f;
+}
+
+/* Wrap to -180...180 */
+inline float wrapDegrees_180(float f)
+{
+ f += 180;
+ f = wrapDegrees_0_360(f);
+ f -= 180;
+ return f;
+}
+
inline std::string lowercase(const std::string &s)
{
std::string s2;