PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

glLoadMatrixf(float *matrix) help needed

I've read the docs and thought I understood this.. but I can't seem to get it correct. I use Direct3D style matrices, so I thought there would be some reordering... I tried that to no avail. Then looking at the docs, it seems that maybe there isn't any reordering... of course, that doesn't work either. ;)

Does anyone have some code or insight to loading D3D style matrices into GLES?

Thanks!
I believe GL matrices are column major order float arrays. That's the only thing special that comes to mind.

I don't know what a D3D-style matrix is. I'll apologize in advance if I'm completely stating the obvious.
rcp wrote:Does anyone have some code or insight to loading D3D style matrices into GLES?

You need to transpose the matrix (the code below is the reverse, it converts a GLES matrix to DX):
Code:

void Matrix2DXMatrix(const Matrix & matrix, D3DXMATRIXA16 & result)
{
result._11 = matrix.Element(0, 0);
result._12 = matrix.Element(1, 0);
result._13 = matrix.Element(2, 0);
result._14 = matrix.Element(3, 0);

result._21 = matrix.Element(0, 1);
result._22 = matrix.Element(1, 1);
result._23 = matrix.Element(2, 1);
result._24 = matrix.Element(3, 1);

result._31 = matrix.Element(0, 2);
result._32 = matrix.Element(1, 2);
result._33 = matrix.Element(2, 2);
result._34 = matrix.Element(3, 2);

result._41 = matrix.Element(0, 3);
result._42 = matrix.Element(1, 3);
result._43 = matrix.Element(2, 3);
result._44 = matrix.Element(3, 3);
}

where
Code:

const Fixed& Element(size_t row, size_t column) const {
return elements[row + column * 4];
}


- HM
ya know, i tried that and it should have worked. I took a closer look at it seems that glLoadMatrixf looks at an array of 16 floats in the *exact* same order I keep my matrices in. So even though they are 'reversed', the load function expects it the way I already have it. The irony is that I pass my mats straight to DX without any problem. The *big* difference that kept everything from working ended up being the way OpenGL creates the projection matrix. There are a couple of subtle differences that kept my SetFOV() routine from creating a projection matrix that GL could live with. Once I fixed (basically adding more clipping information) SetFOV(), all other matrix manipulation functions (LookAt, Rotate, etc) worked just fine.

The irony of course, is that really nothing needed to be changed from an order standpoint... which was were I was looking to begin.

I get my Axim with PowerVR chip next week, so hopefully I can get an ES version up an running quickly.