Grab y rotation from matrix

Started by zammbi, September 01, 2008, 11:15:27 AM

Previous topic - Next topic

zammbi

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

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

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
   
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

Nvm it is correct. I just had to negate the number.