I wasn't trying to reinvent the wheel. I was just trying to roll it my way.
The Standard Matrix
The orthographic projection matrix commonly found in OpenGL documentation looks like this:
| 2/(R-L) 0 0 -(R+L)/(R-L) |
| 0 2/(T-B) 0 -(T+B)/(T-B) |
| 0 0 -2/(F-N) -(F+N)/(F-N) |
| 0 0 0 1 |
I wanted to understand where this comes from rather than just memorize it.
My Derivation Approach
My goal was to map the near plane (N) to -1 and the far plane (F) to +1. My methodology:
- Add half the range:
(F - N) / 2 - Subtract F
- Divide by
(F - N) / 2
Verification with example values (N=2, F=6):
- For z = 2: produces -1 ✓
- For z = 6: produces +1 ✓
The Z-Mapping Equation
This gives the NDC z value:
z_ndc = (2z - (F + N)) / (F - N)
Expanded:
z_ndc = (2 / (F - N)) * z - (F + N) / (F - N)
Formal Derivation
Using a linear function f(z) = Az + B with constraints:
-1 = A * N + B1 = A * F + B
Solving yields:
A = 2 / (F - N)
B = -(F + N) / (F - N)
This produces the identical Z-row found in the standard orthographic matrix. The derivation matched — I had arrived at the same place by following the math rather than memorizing the formula.
Why This Matters
Exploration and understanding fundamentals often teaches more than rote memorization. When you derive something yourself, even if the result is already known, you now own the intuition behind it. You can reconstruct it when you forget, and extend it when you need to.