www.jpct.net
jPCT  a 3d engine for Java => Support => Topic started by: guiloic on June 05, 2006, 12:39:44 pm

How can I calculate the angle from a RotationMatrix ?
thx

This should (may...:wink: ) work:
public SimpleVector deriveAngles(Matrix mat) {
SimpleVector s=new SimpleVector();
float[] m=mat.getDump();
s.x=(float) Math.atan(m[9]/m[10]);
s.y=(float) Math.asin(m[2]);
s.z=(float) Math.atan(m[4]/m[0]);
return s;
}
But keep in mind that rotations depend on each other, i.e. after doing a rotateX(0.1f); rotateY(0.1f); rotateZ(0.2f), the result won't be (0.1,0.1,0.2). Plus there are multiple posibilities to get the same result out of different rotations, i.e. the resulting angles show no "history" of former rotations.
Hope this helps.