Refactor unnecessary closure

This commit is contained in:
Lars Mueller 2023-09-07 17:25:08 +02:00
parent 115f3c2a31
commit 5f0dea2780

@ -60,6 +60,8 @@ function conjugate(self)
end end
function inverse(self) function inverse(self)
-- TODO this is just a fancy normalization *of the conjungate*,
-- which for rotations is the inverse
return modlib.vector.divide_scalar(conjugate(self), self[1] ^ 2 + self[2] ^ 2 + self[3] ^ 2 + self[4] ^ 2) return modlib.vector.divide_scalar(conjugate(self), self[1] ^ 2 + self[2] ^ 2 + self[3] ^ 2 + self[4] ^ 2)
end end
@ -136,29 +138,27 @@ function to_euler_rotation_irrlicht(self)
local x, y, z, w = unpack(self) local x, y, z, w = unpack(self)
local test = 2 * (y * w - x * z) local test = 2 * (y * w - x * z)
local function _calc() local rot
if math.abs(test - 1) <= 1e-6 then if math.abs(test - 1) <= 1e-6 then
return { rot = {
z = -2 * math.atan2(x, w), z = -2 * math.atan2(x, w),
x = 0, x = 0,
y = math.pi/2 y = math.pi/2
} }
end elseif math.abs(test + 1) <= 1e-6 then
if math.abs(test + 1) <= 1e-6 then rot = {
return {
z = 2 * math.atan2(x, w), z = 2 * math.atan2(x, w),
x = 0, x = 0,
y = math.pi/-2 y = math.pi/-2
} }
end else
return { rot = {
z = math.atan2(2 * (x * y + z * w), x ^ 2 - y ^ 2 - z ^ 2 + w ^ 2), z = math.atan2(2 * (x * y + z * w), x ^ 2 - y ^ 2 - z ^ 2 + w ^ 2),
x = math.atan2(2 * (y * z + x * w), -x ^ 2 - y ^ 2 + z ^ 2 + w ^ 2), x = math.atan2(2 * (y * z + x * w), -x ^ 2 - y ^ 2 + z ^ 2 + w ^ 2),
y = math.asin(math.min(math.max(test, -1), 1)) y = math.asin(math.min(math.max(test, -1), 1))
} }
end end
return vector.apply(rot, math.deg)
return vector.apply(_calc(), math.deg)
end end
-- Export environment -- Export environment