Skip to content

Commit 679c01b

Browse files
authored
Editor: rotation (#515)
Modify Euler calculation
1 parent 537d92d commit 679c01b

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

[editor]/editor_main/client/rotation.lua

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,18 @@ function getQuatFromEuler(euler)
127127
end
128128

129129
function getEulerFromQuat(quat)
130-
local result = {}
131-
local q0 = quat[1]
132-
local q1 = quat[2]
133-
local q2 = quat[3]
134-
local q3 = quat[4]
135-
result[1] = math.deg(math.atan2(2*(q0*q1 + q2*q3), 1-2*(q1^2 + q2^2)))
136-
result[2] = math.deg(math.asin(2*(q0*q2 - q3*q1)))
137-
result[3] = math.deg(math.atan2(2*(q0*q3 + q1*q2), 1-2*(q2^2 + q3^2)))
138-
return result
130+
local q0, q1, q2, q3 = quat[1], quat[2], quat[3], quat[4]
131+
local treshold = q0 * q2 - q3 * q1
132+
133+
if treshold > 0.499 then
134+
return {math.deg(2 * math.atan2(q1, q0)), 90, 0}
135+
elseif treshold < -0.499 then
136+
return {math.deg(-2 * math.atan2(q1, q0)), -90, 0}
137+
else
138+
return {
139+
math.deg(math.atan2(2 * (q0 * q1 + q2 * q3), 1 - 2 * (q1^2 + q2^2))),
140+
math.deg(math.asin(2 * treshold)),
141+
math.deg(math.atan2(2 * (q0 * q3 + q1 * q2), 1 - 2 * (q2^2 + q3^2)))
142+
}
143+
end
139144
end

0 commit comments

Comments
 (0)