# Orthographic Projection Matrix

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

## 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 on other sites
I beleive you want the last column to be all negative (except for[15]).

Cheers,

##### 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 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 on other sites
Quote:
 Original post by ShadxI beleive you want the last column to be all negative (except for[15]).Cheers,Shadx

Thanks guys - yep this was the error.