PDA

View Full Version : Orthographic Projection Issue



nickyc95
08-18-2014, 09:27 AM
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.




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;
}

13971398

Video: (Same scene but rotating on Y axis)
youtube.com/embed/2feiZAIM9Y0

MtRoad
08-18-2014, 05:54 PM
I'm not sure your ortho matrix is correct. This is what glOrtho (https://www.opengl.org/sdk/docs/man2/xhtml/glOrtho.xml) uses:



2
------------ 0 0 tx
right - left

2
0 ------------ 0 ty
top - bottom

-2
0 0 ------------ tz
zFar-zNear

0 0 0 1

where
tx = - (right + left) / (right - left)
ty = - (top + bottom) / (top - bottom)
tz = - (zFar + zNear) / (zFar - zNear)


I'm looking specifically at:


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