mirror of
https://github.com/g-truc/glm.git
synced 2024-11-10 04:31:47 +00:00
Merge pull request #1019 from dscharrer/master
Fix singularity in quaternion to euler angle roll conversion #1019
This commit is contained in:
commit
b033c73b42
@ -15,7 +15,13 @@ namespace glm
|
||||
template<typename T, qualifier Q>
|
||||
GLM_FUNC_QUALIFIER T roll(qua<T, Q> const& q)
|
||||
{
|
||||
return static_cast<T>(atan(static_cast<T>(2) * (q.x * q.y + q.w * q.z), q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z));
|
||||
T const y = static_cast<T>(2) * (q.x * q.y + q.w * q.z);
|
||||
T const x = q.w * q.w + q.x * q.x - q.y * q.y - q.z * q.z;
|
||||
|
||||
if(all(equal(vec<2, T, Q>(x, y), vec<2, T, Q>(0), epsilon<T>()))) //avoid atan2(0,0) - handle singularity - Matiis
|
||||
return static_cast<T>(0);
|
||||
|
||||
return static_cast<T>(atan(y, x));
|
||||
}
|
||||
|
||||
template<typename T, qualifier Q>
|
||||
|
Loading…
Reference in New Issue
Block a user