Add quaternion.to_axis_angle

This commit is contained in:
Lars Mueller 2021-08-27 10:45:59 +02:00
parent 2d35d5da3d
commit 93096f385f

@ -81,6 +81,14 @@ function slerp(self, other, ratio)
return modlib.vector.add(modlib.vector.multiply_scalar(self, s_0), modlib.vector.multiply_scalar(other, s_1)) return modlib.vector.add(modlib.vector.multiply_scalar(self, s_0), modlib.vector.multiply_scalar(other, s_1))
end end
--> axis, angle
function to_axis_angle(self)
local axis = modlib.vector.new{self[1], self[2], self[3]}
local len = axis:length()
-- HACK invert axis for correct rotation in Minetest
return len == 0 and axis or axis:divide_scalar(-len), 2 * math.atan2(len, self[4])
end
--> {x = pitch, y = yaw, z = roll} euler rotation in degrees --> {x = pitch, y = yaw, z = roll} euler rotation in degrees
function to_euler_rotation(self) function to_euler_rotation(self)
local rotation = {} local rotation = {}