Just for kicks, I'm wring a software renderer. No particular reason, just for kicks.
In my DirectX engine or my OpenGL engine, doing perspective or orthographic rendering is simply the matter of generating the corresponding matrix, perspective or orthographic. Both rendering API's handle this without any additional information.
Here's my code to convert perspective projection to screen space.
((trans.vert.x / trans.vert.z) * m_screenHalf.w) + m_screenHalfS.w + 0.5f;
((trans.vert.y / trans.vert.z) * m_screenHalf.h) + m_screenHalfS.h + 0.5f;
The problem is, this same code can't be used for orthographic projection. For orthographic projection, you don't need to divide by z so I was assuming z would translate to 1. The orthographic matrix is described as below.
yScale = cot(fovY/2)
xScale = yScale / aspect ratio
xScale 0 0 0
0 yScale 0 0
0 0 zf/(zn-zf) -1
0 0 zn*zf/(zn-zf) 0
So to correct this problem, I would simple do the below.
(trans.vert.x * m_screenHalf.w) + m_screenHalfS.w + 0.5f;
(trans.vert.y * m_screenHalf.h) + m_screenHalfS.h + 0.5f;
So my question is, why do I need to differentiate in my code the projection of perspective vs orthographic when DirectX or OpenGL works seamlessly? For DirectX or OpenGL, you can give your geometry any z value and it seems to ignore it. I'm getting z values I can't ues for orthographic projection.