# Converting matrices between OGL and DX?

This topic is 2863 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hiya. I've been bashing my head lately while trying to convert a row-major matrix to column-major. I have this function in my GLRenderingSystem to do just that.
void ViewToGL(float *p_pfM,Matrix4 &p_xM)
{
p_pfM[0] = p_xM.m11; p_pfM[4] = p_xM.m21; p_pfM[8 ] = p_xM.m31; p_pfM[12] = p_xM.m41;
p_pfM[1] = p_xM.m12; p_pfM[5] = p_xM.m22; p_pfM[9 ] = p_xM.m32; p_pfM[13] = p_xM.m42;
p_pfM[2] = p_xM.m13; p_pfM[6] = p_xM.m23; p_pfM[10] = p_xM.m33; p_pfM[14] = p_xM.m43;
p_pfM[3] = p_xM.m14; p_pfM[7] = p_xM.m24; p_pfM[11] = p_xM.m34; p_pfM[15] = p_xM.m44;
};

This works out fine, the thing is, I also want to negate the Z-axis, so I can rest assured that objects will stay the same whether I'm rendering with OGL or D3D. So it tried changing
p_pfM[14] = p_xM.m43;
to
p_pfM[14] = p_xM.m43 * -1
At first i thought this worked fine, but then I tried rotating the camera, and as a result the camera didn't rotate around itself, but around an unknown point. The rotation in D3D works out as expected though. Can someone help me with the logic here? I'm about to go crazy.

##### Share on other sites
If I understand correctly you're just flipping the z axis of the translation vector (located in positions 12, 13, and 14). I think what you want to do is flip the basis vector, so you'd need to multiply components 8, 9, and 10 by -1.