# Orthographic Projection Issue

I have a problem with my Ortho Matrix. The engine uses the perspective projection fine but for some reason the Ortho matrix is messed up. (See screenshots below).

Can anyone understand what is happening here?

At the min I am taking the Projection matrix * Transform (Translate, rotate, scale) and passing to the Vertex shader to multiply the Vertices by it.

VIDEO Shows the same scene, rotating on the Y axis. http://youtu.be/2feiZAIM9Y0

 void Matrix4f::InitOrthoProjTransform(float left, float right, float top, float bottom, float zNear, float zFar)
{
m[0][0] = 2 / (right - left);
m[0][1] = 0;
m[0][2] = 0;
m[0][3] = 0;

m[1][0] = 0;
m[1][1] = 2 / (top - bottom);
m[1][2] = 0;
m[1][3] = 0;

m[2][0] = 0;
m[2][1] = 0;
m[2][2] = -1 / (zFar - zNear);
m[2][3] = 0;

m[3][0] = -(right + left) / (right - left);
m[3][1] = -(top + bottom) / (top - bottom);
m[3][2] = -zNear / (zFar - zNear);
m[3][3] = 1;
}


This is what happens with Ortho Matrix:

This is the Perspective Matrix:

• You can take a screenshot of only the current window with alt + prtScn. That way you don't have to cut them in paint. – Eejin Aug 18 '14 at 15:27

Unless you just made a large number of typos posting this code, your indexing is sloppy; some of the array elements aren't initialized, some are overwritten and at one point you index out of bounds of the array. That looks like your problem.

m[0][0] = 2 / (right - left);
m[0][1] = 0;
m[0][2] = 0;
m[0][3] = 0;

m[1][0] = 0;
m[1][2] = 2 / (top - bottom); // should probably be m[1][1]
m[1][2] = 0;                  // immediately overwrites m[1][2]
m[1][3] = 0;

m[2][0] = 0;
m[2][3] = 0;                  // should probably be m[2][1]
m[2][2] = -1 / (zFar - zNear);
m[2][3] = 0;                  // again overwrites m[2][3]

m[3][0] = -(right + left) / (right - left);
m[3][4] = -(top + bottom) / (top - bottom); // m[3][4] is out of bounds of the array
m[3][2] = -zNear / (zFar - zNear);
m[3][3] = 1;

• Maybe elaborate on the sections he has gotten wrong, as it stands your answer doesn't point him in the correct direction. – Tom 'Blue' Piddock Aug 18 '14 at 13:41
• gotcha, edited. – Cormac O'Brien Aug 18 '14 at 13:44
• Sorry about that, pasted the code and formatted it wrong. I have corrected it in the post as it should be (Issue not solved). Thanks – Nick Aug 18 '14 at 13:46
• Okay so the edits on the question make this a little obsolete now but your answer format is a lot better! This is what we like to see in GD:SE as it gives future users a better insight to the solutions. – Tom 'Blue' Piddock Aug 18 '14 at 13:51