nerevelon5/lib/math2.lua
Ivan Yuriev 6a8bc1e07c - shadows demo
- scaling
 - math fix
 - refactoring
2025-04-17 03:52:58 +03:00

23 lines
490 B
Lua

math.named_direction = function(rotation)
local get_direction_index = function(rotation)
local pi = math.pi
rotation = rotation % (2 * pi)
local shifted = (rotation + pi / 8) % (2 * pi)
local index = math.floor(shifted / (pi / 4)) + 1
return index
end
local lookup = {
"s",
"se",
"e",
"ne",
"n",
"nw",
"w",
"sw",
}
return lookup[get_direction_index(rotation)]
end