Orthographic Projection Matrix

Started by
3 comments, last by dustamulet 17 years, 8 months ago
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;
Advertisement
I beleive you want the last column to be all negative (except for[15]).

Cheers,

Shadx
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.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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.
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.

This topic is closed to new replies.

Advertisement