feat(math): add normal to rotation method (#431)

This commit is contained in:
Austin Dunn
2023-10-22 22:49:58 -07:00
committed by GitHub
parent 63033c71a4
commit 0b5ad76721

View File

@@ -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