Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Don't forget to read Tuesday's email newsletter for your chance to win a free copy of Construct 2!


Orthographic Projection Issue


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 nickyc95   Members   -  Reputation: 153

Like
0Likes
Like

Posted 18 August 2014 - 07:02 AM

Hi there guys,

 

 

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?

 

VIDEO Shows the same scene, rotating on the Y axis.

 

Ortho Projection code

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

Then using projectionMatrix.InitOrthoProjTransform(0.0f, 800.0f, 0.0f, 600.0f, 0.1f, 1000.0f);

 

OK so the first screenshot that is attached shows the Ortho, second one shows perspective (rotated slightly to show persp).

Attached Thumbnails

  • 1Untitled-1.png
  • 2Untitled-1.png

Edited by nickyc95, 18 August 2014 - 09:14 AM.


Sponsor:

#2 Hosein G   Members   -  Reputation: 163

Like
0Likes
Like

Posted 18 August 2014 - 12:44 PM

you should use these parameters (-1.0, 1.0, -1.0*height/width, 1.0*height/width, 0.1, 1000) for ortho

in order (bottom , top , left , right , near , far)


Edited by Hosein G, 18 August 2014 - 12:46 PM.


#3 nickyc95   Members   -  Reputation: 153

Like
0Likes
Like

Posted 18 August 2014 - 01:09 PM

you should use these parameters (-1.0, 1.0, -1.0*height/width, 1.0*height/width, 0.1, 1000) for ortho

in order (bottom , top , left , right , near , far)

Why?

 

I thought that when you create an Ortho Matrix you use the screen dimensions to get a "pixel perfect" area to draw in (e.g. 800*600)

 

Thanks



#4 Hosein G   Members   -  Reputation: 163

Like
0Likes
Like

Posted 18 August 2014 - 01:17 PM

no actually there is no pixels there so the point is a ratio between height and width and you should take the origin in center



#5 nickyc95   Members   -  Reputation: 153

Like
0Likes
Like

Posted 18 August 2014 - 01:51 PM

no actually there is no pixels there so the point is a ratio between height and width and you should take the origin in center


Can you expand further?

Thanks

#6 Hosein G   Members   -  Reputation: 163

Like
0Likes
Like

Posted 18 August 2014 - 02:11 PM

check this : http://www.glprogramming.com/red/chapter03.html#name3

and its mostly the idea of perspective in ortho u don't really nead to define top left and etc. its actually just used for things like scaling.


Edited by Hosein G, 18 August 2014 - 02:14 PM.


#7 JohnnyCode   Members   -  Reputation: 266

Like
0Likes
Like

Posted 20 August 2014 - 09:49 AM

ortho matrix is easy to master in the manner of width and height. but you can easiily screw up depth! resulting in paranormal oclusion- or, objects being further ocluding objects being closer. Watch out.  (Ortho normal projection is an observation phenomena that is being rather paranormal- as it is)



#8 L. Spiro   Crossbones+   -  Reputation: 14005

Like
3Likes
Like

Posted 20 August 2014 - 10:00 PM

you should use these parameters (-1.0, 1.0, -1.0*height/width, 1.0*height/width, 0.1, 1000) for ortho
in order (bottom , top , left , right , near , far)

This is not correct.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd373965(v=vs.85).aspx
 
You are already passing the correct values, which should be actual pixel sizes.
 
Your Z values are both incorrect.
 
m[2][2] = -1 / (zFar - zNear); should be m[2][2] = -2 / (zFar - zNear);.

m[3][2] = -zNear / (zFar - zNear); should be m[3][2] = -(zFar + zNear) / (zFar - zNear);.

 

This is OpenGL, not Direct3D.

Also, try transposing the matrix if these changes do not work.

 

 

L. Spiro


It is amazing how often people try to be unique, and yet they are always trying to make others be like them. - L. Spiro 2011
I spent most of my life learning the courage it takes to go out and get what I want. Now that I have it, I am not sure exactly what it is that I want. - L. Spiro 2013
I went to my local Subway once to find some guy yelling at the staff. When someone finally came to take my order and asked, “May I help you?”, I replied, “Yeah, I’ll have one asshole to go.”
L. Spiro Engine: http://lspiroengine.com
L. Spiro Engine Forums: http://lspiroengine.com/forums

#9 nickyc95   Members   -  Reputation: 153

Like
0Likes
Like

Posted 22 August 2014 - 10:23 AM

 

you should use these parameters (-1.0, 1.0, -1.0*height/width, 1.0*height/width, 0.1, 1000) for ortho
in order (bottom , top , left , right , near , far)

This is not correct.
http://msdn.microsoft.com/en-us/library/windows/desktop/dd373965(v=vs.85).aspx
 
You are already passing the correct values, which should be actual pixel sizes.
 
Your Z values are both incorrect.
 
m[2][2] = -1 / (zFar - zNear); should be m[2][2] = -2 / (zFar - zNear);.

m[3][2] = -zNear / (zFar - zNear); should be m[3][2] = -(zFar + zNear) / (zFar - zNear);.

 

This is OpenGL, not Direct3D.

Also, try transposing the matrix if these changes do not work.

 

 

L. Spiro

 

Hi, 

 

thanks for "backing me up", haha.

 

Yeah turns out my matrices weren't consistent with each other, thus caused this issue.

 

Thanks






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS