Orthographic Projection Issue

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

Orthographic Projection Issue

Postby nickyc95 on Mon Aug 18, 2014 11:07 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;
}


This image shows the Perspective projection:
2Untitled-1.png
Persp
2Untitled-1.png (12.12 KiB) Viewed 1186 times


Then the Orthographic projection (InitOrthoProjectionTransform(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 1000.0f) )
(I'll upload a video to demonstrate what is happening.)
1Untitled-1.png
Ortho
1Untitled-1.png (14.67 KiB) Viewed 1186 times



VIDEO Shows the same scene, rotating on the Y axis.
http://youtu.be/2feiZAIM9Y0
nickyc95
Chaos Rift Newbie
Chaos Rift Newbie
 
Posts: 9
Joined: Wed Mar 05, 2014 1:12 pm

Re: Orthographic Projection Issue

Postby X Abstract X on Mon Aug 18, 2014 7:14 pm

Try these 2 changes:

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] = -2 / (zFar - zNear);
m[2][3] = 0;

m[3][0] = -(right + left) / (right - left);
m[3][1] = -(top + bottom) / (top - bottom);
m[3][2] = -(zFar + zNear) / (zFar - zNear);
m[3][3] = 1;
}
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
 
Posts: 178
Joined: Thu Feb 11, 2010 11:46 pm
Location: Ottawa, Canada

Re: Orthographic Projection Issue

Postby nickyc95 on Tue Aug 19, 2014 4:19 am

X Abstract X wrote:Try these 2 changes:

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] = -2 / (zFar - zNear);
m[2][3] = 0;

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


Hi, thanks for the reply.

Changing the ortho matrix to the one you have posted still hasn't fixed the issue.

Thanks
nickyc95
Chaos Rift Newbie
Chaos Rift Newbie
 
Posts: 9
Joined: Wed Mar 05, 2014 1:12 pm

Re: Orthographic Projection Issue

Postby X Abstract X on Tue Aug 19, 2014 2:25 pm

What are the results if you omit using any model or camera transforms and multiply the vertices of an on-screen quad by just the ortho matrix?
X Abstract X
Chaos Rift Regular
Chaos Rift Regular
 
Posts: 178
Joined: Thu Feb 11, 2010 11:46 pm
Location: Ottawa, Canada

Re: Orthographic Projection Issue

Postby nickyc95 on Tue Aug 19, 2014 3:45 pm

X Abstract X wrote:What are the results if you omit using any model or camera transforms and multiply the vertices of an on-screen quad by just the ortho matrix?

Hi there,

Turns out my math class isn't pristine :lol:

I was swapping conventions from the actual math class and the orthographic matrix.

I just have to ensure I am more constant with the conventions that I use.

Thank you :)
nickyc95
Chaos Rift Newbie
Chaos Rift Newbie
 
Posts: 9
Joined: Wed Mar 05, 2014 1:12 pm


Return to Programming Discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron