aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorAuke Kok <sofar@foo-projects.org>2017-01-12 11:56:41 -0800
committerparamat <mat.gregory@virginmedia.com>2017-01-23 07:38:39 +0000
commit7fc67199683d3c60fe0b3ddcb2a9594b4804cc38 (patch)
treef79879304d42bfeb5ae649d12cc4850b8029828d /builtin
parent2d7a6f2cc0717eb92de4a91326a871d525ce513d (diff)
downloadminetest-7fc67199683d3c60fe0b3ddcb2a9594b4804cc38.tar.gz
minetest-7fc67199683d3c60fe0b3ddcb2a9594b4804cc38.tar.bz2
minetest-7fc67199683d3c60fe0b3ddcb2a9594b4804cc38.zip
core: Add dir_to_yaw and yaw_to_dir helpers
These are needed to go from things like entity yaw to a vector and vice versa.
Diffstat (limited to 'builtin')
-rw-r--r--builtin/game/item.lua8
1 files changed, 8 insertions, 0 deletions
diff --git a/builtin/game/item.lua b/builtin/game/item.lua
index bf456a4e0..e51da6d6b 100644
--- a/builtin/game/item.lua
+++ b/builtin/game/item.lua
@@ -147,6 +147,14 @@ function core.wallmounted_to_dir(wallmounted)
return wallmounted_to_dir[wallmounted]
end
+function core.dir_to_yaw(dir)
+ return -math.atan2(dir.x, dir.z)
+end
+
+function core.yaw_to_dir(yaw)
+ return {x = -math.sin(yaw), y = 0, z = math.cos(yaw)}
+end
+
function core.get_node_drops(nodename, toolname)
local drop = ItemStack({name=nodename}):get_definition().drop
if drop == nil then