www.jpct.net

jPCT-AE - a 3d engine for Android => Support => Topic started by: arekz on July 14, 2016, 10:09:48 am

Title: Is a helper method to rotate models by yaw, pitch, roll angles?
Post by: arekz on July 14, 2016, 10:09:48 am
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.
Title: Re: Is a helper method to rotate models by yaw, pitch, roll angles?
Post by: EgonOlsen 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
Title: Re: Is a helper method to rotate models by yaw, pitch, roll angles?
Post by: arekz 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?
Title: Re: Is a helper method to rotate models by yaw, pitch, roll angles?
Post by: EgonOlsen 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) (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);
...