# www.jpct.net

## jPCT - a 3d engine for Java => Support => Topic started by: zammbi on September 01, 2008, 11:15:27 am

Title: Grab y rotation from matrix
Post by: zammbi on September 01, 2008, 11:15:27 am
I'm having a little trouble with grabbing the y rotation from a matrix. I found a nice example for 3x3 matrix but I'm totally lost with jpct matrix.
Title: Re: Grab y rotation from matrix
Post by: EgonOlsen on September 01, 2008, 12:00:11 pm
It's the same. The upper left part is the rotational part. You can extract the values needed from the float[]-array that getDump() returns.
Title: Re: Grab y rotation from matrix
Post by: zammbi on September 01, 2008, 01:04:12 pm
Seems what I have is incorrect. Maybe someone can help me?

I'm using this code to work out the 3 angles got it from
http://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToEuler/index.htm
Code: [Select]
`    public final SimpleVector matrixToRad(Matrix  m) {    float[] mDump = m.getDump();        float heading,attitude,bank;    if (mDump[4] > 0.998) { // singularity at north pole    heading = (float) Math.atan2(mDump[2],mDump[10]);    attitude = (float) (Math.PI/2);    bank = 0;    }    else if (mDump[4] < -0.998) { // singularity at south pole    heading = (float) Math.atan2(mDump[2],mDump[10]);    attitude = (float) (-Math.PI/2);    bank = 0;    }    else{    heading = (float) Math.atan2(-mDump[8],mDump[0]);    bank = (float) Math.atan2(-mDump[6],mDump[5]);    attitude = (float) Math.asin(mDump[4]);    }    return new SimpleVector(bank,heading,attitude);    }`
I wish there was a getYrotation on a object3D because I'm totally confused how to do these matrices.
Title: Re: Grab y rotation from matrix
Post by: zammbi on September 01, 2008, 01:21:20 pm
Nvm it is correct. I just had to negate the number.