Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
You could check the source in "GLKit/GLKMatrix4.h" yourself to determine the answer.

I already looked at it. The function is unrolled, so it doesn't tell me much in terms of order.

Code:
GLKMatrix4Multiply
Returns the product of two matrices.

GLKMatrix4 GLKMatrix4Multiply (
   GLKMatrix4 matrixLeft,
   GLKMatrix4 matrixRight
);

I don't understand why Apple would create a matrix multiply function that gives a BxA result.
All of my OpenGL math is screwed up.
 
You could check the source in "GLKit/GLKMatrix4.h" yourself to determine the answer.

The code that produces the same result can be found in the SDK example pARk/ARView.m:

Code:
void multiplyMatrixAndMatrix(mat4f_t c, const mat4f_t a, const mat4f_t b)
{
	uint8_t col, row, i;
	memset(c, 0, 16*sizeof(float));
	
	for (col = 0; col < 4; col++) {
		for (row = 0; row < 4; row++) {
			for (i = 0; i < 4; i++) {
				c[col*4+row] += a[i*4+row]*b[col*4+i];
			}
		}
	}
}

This also creates a BxA matrix.

This line here:
c[col*4+row] += a[i*4+row]*b[col*4+i];

Can be written as:
c(col,row) += a(i,row) * b(col,i);

For AxB, it must do this:
c(row,col) += a(row,i) * b(i,col);

The whole GLK framework must be backwards or something. Argh.
 
Is this one of those row column things inherited from supercomputer Fortran/LINPACK math crunching code rather than newbie C conventions.
 
OpenGL uses a "right-handed" coordinate system. You probably are expecting a left-handed system?

LH and RH coordinate systems can use the same matrix functions.

Matrix functions shouldn't even know or care how the elements are stored in memory.
Ideally, they should request a (row,col) element and do whatever they want with it.

So, the problem here is not related to how matrix elements are stored in memory.
It just gives a backwards result.
 
Yeah, I wasn't sure that was the answer, but I thought I'd throw it out there. It's been many (, many) years since I was in my linear-algebra class and did matrix-multiplication.
 
Yeah, I wasn't sure that was the answer, but I thought I'd throw it out there. It's been many (, many) years since I was in my linear-algebra class and did matrix-multiplication.

No problem, it's just lack of documentation. I don't see it as a bug, because I usually prepare my
GL matrices in ZYX order.

So, GLKMatrix4Multiply makes sense here, but it doesn't make sense for generic matrix math.
I wasn't expecting a backwards result.

Thanks! Problem solved.
 
Last edited:
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.