Converting yaw Euler angles in range [-90, 90] to [0, 360]

时光总嘲笑我的痴心妄想 提交于 2019-12-11 03:11:47

问题


Is it possible to convert the yaw Euler angle got from the Bullet physics engine using

btTransform trans;
trans.getBasis().getEulerYPR(rx, ry, rz);

into the range [0 , 360]. Otherwise for a 360 deg rotation I get the Euler angle varying from 0->90->0-> -90 -> 0

but I want from 0->90->180->270->0

My graphics API only accepts rotation angles in the range of 0 to 360


Well, the 0->90->0-> -90 was the pitch value. Here is the code I use now :

trans.getBasis().getEulerYPR(yaw, pitch, roll);
y1 = (pitch >= 0) ? pitch : (PI2 + pitch);

I was trying to add 180 for negative values of pitch, but that doesnt work. Well it seems I ll need to find another way to rotate meshes smoothly using euler angles.


Update: It seems I should not use the bullet functions directly. A better option is deal with the basis matrix directly :

btMatrix3x3 m_el = trans.getBasis();
ry = btAtan2( m_el[0].z(), m_el[0].x() );
if(ry < 0)
    ry += SIMD_PI;

So that gave me the rotation about the y-axis. Now about the other 2 ....phew !


回答1:


No, read up on the domains of the different angles, or Euler angles in general. Two have their domain [0, 2 pi] usually yaw and roll and one [0, pi] typically pitch.



来源:https://stackoverflow.com/questions/11165556/converting-yaw-euler-angles-in-range-90-90-to-0-360

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!