Author Topic: Is a helper method to rotate models by yaw, pitch, roll angles?  (Read 1618 times)

Offline arekz

  • byte
  • *
  • Posts: 8
    • View Profile
As we know the multiplication of rotation matrix aren't commutative so I need rotate the Object3D at once by three angles (Yaw, Pitch, Roll)
I get this angles form external source (not sensors).

Code: [Select]
     
      obj3d..clearRotation();
      obj3d.rotateY(measurements.yaw);
        obj3d.rotateX(measurements.pitch);
        obj3d.rotateZ(measurements.roll);
So is there any helper method to solve that?
for example in libgdx I used method Matrix..setFromEulerAnglesRad() and then I make multiplication that matrix with transform matrix. Unfortnightly the Object3D class not contain any method rotateByEurelAngles() or similar or I miss something.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Is a helper method to rotate models by yaw, pitch, roll angles?
« Reply #1 on: July 14, 2016, 10:30:57 am »
I'm not sure, if I understand the problem correctly!? If I did, just convert from degrees to radians. It's dead simple:

Code: [Select]
float rad=euler*(float)Math.PI/180f

Offline arekz

  • byte
  • *
  • Posts: 8
    • View Profile
Re: Is a helper method to rotate models by yaw, pitch, roll angles?
« Reply #2 on: July 14, 2016, 10:45:37 am »
My angles are in radius already.

My problem is that if I rotate by X axis then by Y axis and then by Z axis I will have different model pose if I first rotate by Z axis then by Y axis and finally by X axis.
So below code give me diffrent result (model pose)
Code: [Select]
    obj3d..clearRotation();
        obj3d.rotateX(measurements.pitch);
      obj3d.rotateY(measurements.yaw);
        obj3d.rotateZ(measurements.roll);
then this one:
Code: [Select]
    obj3d..clearRotation();
      obj3d.rotateZ(measurements.roll); 
        obj3d.rotateY(measurements.yaw);
      obj3d.rotateX(measurements.pitch); 
right?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Is a helper method to rotate models by yaw, pitch, roll angles?
« Reply #3 on: July 14, 2016, 10:52:33 am »
I see. You can use this method for that: http://www.jpct.net/jpct-ae/doc/com/threed/jpct/Object3D.html#rotateAxis(com.threed.jpct.SimpleVector, float)

Just do something like:

Code: [Select]
obj.rotateAxis(obj.getXAxis(), radX);
obj.rotateAxis(obj.getYAxis(), radY);
...