2

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 !

safe_malloc
  • 824
  • 2
  • 12
  • 29
  • Is my answer that what you looking for? http://stackoverflow.com/questions/29869130/how-to-get-the-euler-rotation-of-a-rigid-body-between-0-to-360-in-bullet-physics/37506181#37506181 – Andrew May 29 '16 at 04:39

1 Answers1

0

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.

Bort
  • 2,423
  • 14
  • 22
  • So I guess if I wanted to smoothly rotate a mesh using Euler angles alone, that would not be possible. Because when a Euler angle crosses 90 and starts going down, the mesh would rotate backwards ! Strangely I get a range within [-90, 90] – safe_malloc Jun 23 '12 at 01:51
  • @safe-malloc if you want smooth rotations I suggest using quaternions. In contrast to Euler angles, quaternions are a 2->1 map on SO(3), which means that you don't have poles in the domain which cause side effects like gimbal lock. Additionally [interpolating](http://en.wikipedia.org/wiki/Slerp) between two orientations with a rotation is straight forward with quaternions. Check out `void btMatrix3x3::getRotation (btQuaternion &q )const`... `btQuaternion btQuaternion::slerp(...) ` is already implemented... nice – Bort Jun 27 '12 at 12:13