Jump to content
  • Advertisement
Sign in to follow this  
dustamulet

Orthographic Projection Matrix

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, can anyone help me out with what I'm doing wrong here? I am trying to construct an orthographic projection matrix, with the top left corner being (0,0) and the bottom right corner being (m_viewportWidth, m_viewportHeight). Near and far clipping planes are 0.0f and 1.0f respectively. The matrix is read as column-major.
m_projectionMatrix[0]  = 2.0f / (float)(m_viewportWidth - 0.0f);
m_projectionMatrix[1]  = 0.0f;
m_projectionMatrix[2]  = 0.0f;
m_projectionMatrix[3]  = 0.0f;

m_projectionMatrix[4]  = 0.0f;
m_projectionMatrix[5]  = 2.0f / (float)(0.0f - m_viewportHeight);
m_projectionMatrix[6]  = 0.0f;
m_projectionMatrix[7]  = 0.0f;

m_projectionMatrix[8]  = 0.0f;
m_projectionMatrix[9]  = 0.0f;
m_projectionMatrix[10] = -2.0f / (float)(1.0f - 0.0f);
m_projectionMatrix[11] = 0.0f;

m_projectionMatrix[12] = (m_viewportWidth + 0.0f) / (m_viewportWidth - 0.0f);
m_projectionMatrix[13] = (0.0f + m_viewportHeight) / (0.0f - m_viewportHeight);
m_projectionMatrix[14] = (1.0f + 0.0f) / (1.0f - 0.0f);
m_projectionMatrix[15] = 1.0f;

Share this post


Link to post
Share on other sites
Advertisement
I beleive you want the last column to be all negative (except for[15]).

Cheers,

Shadx

Share this post


Link to post
Share on other sites
You need to tell us why you think it is wrong. If you are using OpenGL, then my guess is that inverting the Y axis is turning your right handed coordinate system into left handed.

Share this post


Link to post
Share on other sites
Just thought I'd mention that in at least one version of the Red Book the orthographic projection matrix given in the appendix is incorrect; I believe the error may be exactly the one that Shadx described.

This may have been corrected in later versions or in the online version, but I'm not sure. Anyway, if your reference was the Red Book then that may be the source of the error in your code.

Share this post


Link to post
Share on other sites
Quote:
Original post by Shadx
I beleive you want the last column to be all negative (except for[15]).

Cheers,

Shadx

Thanks guys - yep this was the error.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!