From 0b5ad767214f903f11157f4a69708acc09ca2b45 Mon Sep 17 00:00:00 2001 From: Austin Dunn <60995067+Demigod916@users.noreply.github.com> Date: Sun, 22 Oct 2023 22:49:58 -0700 Subject: [PATCH] feat(math): add normal to rotation method (#431) --- imports/math/shared.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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