From 93096f385f36984c94e56a6e3c5ed58fbe1cb7cd Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Fri, 27 Aug 2021 10:45:59 +0200 Subject: [PATCH] Add quaternion.to_axis_angle --- quaternion.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/quaternion.lua b/quaternion.lua index 3adee90..54c72cc 100644 --- a/quaternion.lua +++ b/quaternion.lua @@ -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)) 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 function to_euler_rotation(self) local rotation = {}