Skip to content

Commit 7fc6719

Browse files
sofarparamat
authored andcommittedJan 23, 2017
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.
1 parent 2d7a6f2 commit 7fc6719

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed
 

Diff for: ‎builtin/game/item.lua

+8
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ function core.wallmounted_to_dir(wallmounted)
147147
return wallmounted_to_dir[wallmounted]
148148
end
149149

150+
function core.dir_to_yaw(dir)
151+
return -math.atan2(dir.x, dir.z)
152+
end
153+
154+
function core.yaw_to_dir(yaw)
155+
return {x = -math.sin(yaw), y = 0, z = math.cos(yaw)}
156+
end
157+
150158
function core.get_node_drops(nodename, toolname)
151159
local drop = ItemStack({name=nodename}):get_definition().drop
152160
if drop == nil then

Diff for: ‎doc/lua_api.txt

+4
Original file line numberDiff line numberDiff line change
@@ -2403,6 +2403,10 @@ and `minetest.auth_reload` call the authetification handler.
24032403
* Convert a vector to a wallmounted value, used for `paramtype2="wallmounted"`
24042404
* `minetest.wallmounted_to_dir(wallmounted)`
24052405
* Convert a wallmounted value back into a vector aimed directly out the "back" of a node
2406+
* `minetest.dir_to_yaw(dir)`
2407+
* Convert a vector into a yaw (angle)
2408+
* `minetest.yaw_to_dir(yaw)`
2409+
* Convert yaw (angle) to a vector
24062410
* `minetest.get_node_drops(nodename, toolname)`
24072411
* Returns list of item names.
24082412
* **Note**: This will be removed or modified in a future version.

0 commit comments

Comments
 (0)
Please sign in to comment.