If you want to get the pitch, yaw and roll angles at any stage after several rotations, you can get them from the transformation matrix of the 3D model.
If you have a look at the transformation matrix after several rotations:
Transform T = model3D.getLocalToSceneTransform();
System.out.println(T);
you'll see something like this:
Transform [
0.9034731871219395, -0.4260296991535005, -0.04727468234587054, 1.4044414829046357
0.3743586809560477, 0.837958815679334, -0.39709016761704913, 0.5234811188037405
0.2087864414768669, 0.3410626315861443, 0.9165612381019399, -1.1277640590168572
]
If you want the angles, you just need to compare this matrix with this one from this answer:
As you have already stated, to get the roll angle you can use T.getMxx()
and T.getMyx()
:
double roll = Math.atan2(-T.getMyx(),T.getMxx());
Now, for the pitch, you can use T.getMzy()
and T.getMzz()
in the same way:
double pitch = Math.atan2(-T.getMzy(),T.getMzz());
Finally, for the yaw, use T.getMzx()
, T.getMzy()
and T.getMzz()
:
double yaw = Math.atan2(T.getMzx(),Math.sqrt(T.getMzy()*T.getMzy()+T.getMzz()*T.getMzz()));
This will give for the above matrix the angles you are looking for (in radians):
roll: -0.39281984604895126
pitch: -0.356235553820928
yaw: 0.21033388848106072