### Author Topic: Grab y rotation from matrix  (Read 2788 times)

#### zammbi

• float
• Posts: 360
##### Grab y rotation from matrix
« 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.

#### EgonOlsen

• Posts: 11898
##### Re: Grab y rotation from matrix
« Reply #1 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.

#### zammbi

• float
• Posts: 360
##### Re: Grab y rotation from matrix
« Reply #2 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.

#### zammbi

• float
• Posts: 360
##### Re: Grab y rotation from matrix
« Reply #3 on: September 01, 2008, 01:21:20 pm »
Nvm it is correct. I just had to negate the number.