Author Topic: Order of the Values in the Matrix  (Read 3114 times)

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Order of the Values in the Matrix
« on: March 05, 2010, 09:47:05 pm »
I'm trying to convert between Max's camera matrix to jPCT (which, by the way, will make for a good Wiki). Problem is that the documentation doesn't specify how the matrices are arranged (just that it's a 4x4 matrix), and jPCT's matrix doesn't match Max's. So, what is the order?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Order of the Values in the Matrix
« Reply #1 on: March 05, 2010, 09:50:35 pm »
Like the docs for Matrix state: All matrices in jPCT are row major....and that's true, as long as you are using the set()-method in Matrix. If you are using setDump() to set a float[16], it's different. That one does this:

Code: [Select]
                        int cnt = 0;
for (int i = 0; i < 4; i++) {
mat[i][0] = dump[cnt];
mat[i][1] = dump[cnt + 1];
mat[i][2] = dump[cnt + 2];
mat[i][3] = dump[cnt + 3];
cnt += 4;
}
With i being the row, [0...3] the columns.

Offline AGP

  • quad
  • ******
  • Posts: 1726
    • View Profile
Re: Order of the Values in the Matrix
« Reply #2 on: March 05, 2010, 10:20:11 pm »
I read the wikipedia on row major. Not completely clear to me yet. Does anyone have any idea about Max's 4x3 matrices?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: Order of the Values in the Matrix
« Reply #3 on: March 05, 2010, 11:13:09 pm »
Conversion between row- and column-major isn't difficult. If this is a row-major matrix:

Code: [Select]
a b c d
e f g h
i j l m
n o p q

then this is the column major variant:

Code: [Select]
a e i n
b f j o
c g l p
d h m q

Plus, if your are doing matrix multiplications, the order changes. I.e. a*b with row-major matrices becomes b*a for column-major.