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

Title: RotationMatrix
Post by: guiloic on June 05, 2006, 12:39:44 pm
How can I calculate the angle from a RotationMatrix ?

Title: RotationMatrix
Post by: EgonOlsen on June 06, 2006, 04:44:29 pm
This should (may...:wink: ) work:

Code: [Select]
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.