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

Offline zammbi

  • float
  • ****
  • Posts: 361
    • View Profile
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
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.

Offline zammbi

  • float
  • ****
  • Posts: 361
    • View Profile
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.

Offline zammbi

  • float
  • ****
  • Posts: 361
    • View Profile
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.