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

2019-07-17 01:15发布

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条回答
forever°为你锁心
2楼-- · 2019-07-17 01:51

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.

查看更多
登录 后发表回答