diff --git a/imports/math/shared.lua b/imports/math/shared.lua index 99cf23d..23d7972 100644 --- a/imports/math/shared.lua +++ b/imports/math/shared.lua @@ -74,6 +74,21 @@ function math.tovector(input, min, max, round) error(('cannot convert %s to a vector value'):format(inputType), 2) end +---Tries to convert a surface Normal to a Rotation. +---@param input vector3 +---@return vector3 +function math.normaltorotation(input) + local inputType = type(input) + + if inputType == 'vector3' then + local pitch = -math.asin(input.y) * (180.0 / math.pi) + local yaw = math.atan(input.x, input.z) * (180.0 / math.pi) + return vec3(pitch, yaw, 0.0) + end + + error(('cannot convert type %s to a rotation vector'):format(inputType), 2) +end + ---Tries to convert its argument to a vector. ---@param input string | table ---@return number | vector2 | vector3 | vector4