Recently I've been trying to implement OpenGL perspective projection matrix, but stuck at understanding of how to derive projected Z value. Here's an example of it
Derivation of $x$ and $y$ values is pretty straightforward. Firstly, I need to project point onto near plane like so: $x_p=nx/z$ where $n$ is distance to near plane, and remap $x$ from $l<=x<=r$ to $-1<=x<=1$. Same steps for $y$, but $z$ has differences. I cannot just perform same steps for it as I did for $x$ and $y$ by solving simple inequalities. Question here: why I cannot just simply calculate it by solving inequality of type $n<=z<=f$, but rather must solve these equations: $-n=pn+q$ and $f=pf+q$ (assuming I want to map $z$ into $[-1;1]$ range)? Is there some geometric meaning for that?
Source for matrix derivation that I was using: https://www.codeguru.com/cpp/misc/misc/graphics/article.php/c10123/Deriving-Projection-Matrices.htm#page-3
