How to compute A and B in projection matrix I'm trying to compute a projection matrix to transform from view space to NDC with a near clip plane at -1 and far plane at +1. The general form of this matrix (disregarding aspect ratio and focal length) should be

$\begin{bmatrix}1&amp;0&amp;0&amp;0\\0&amp;1&amp;0&amp;0\\0&amp;0&amp;A&amp;B\\0&amp;0&amp;-1&amp;0\end{bmatrix}$

I followed SongHo's guide at http://www.songho.ca/opengl/gl_projectionmatrix.html which sets $A=-(f+n)/(f-n)$ and $B=-2fn/(f-n)$. 

However, setting the near clip plane at $n=-1$ and $f=-10$ (in view space) and using these $A$ and $B$, I get points with $z$ values on the interval $[-1, -10]$ transformed to $[3.04, 1.04]$ (after homogenisation). 

When I do the derivations myself, I'd like to set $A=(n+f)/(n-f)$ and $B=(-2fn)/(n-f)$ instead, which indeed transforms to $[-1,1]$ instead.

Am I doing something wrong?
Note: I'll be using column vector notation (eg. $Ax=y$), thus if you are using row notation, transpose the matrix and multiply from the left instead of the right. (eg. $y=x^TA^T$)

A perspective transformation matrix transforms a view frustum into a rectangular view volume. Note that the resulting view volume might not be a cube and might not be centered at 0.

One example of a perspective transformation matrix. There are many more, and yours is included.

Let $l=left,\\ r = right,\\ b = bottom,\\ t = top,\\ n = near,\\ f = far$

$M_{persp}=\begin{bmatrix}
1&amp; &amp; &amp; \\
 &amp;1&amp; &amp; \\
 &amp; &amp;\frac{n+f}{n}&amp;-f\\
 &amp; &amp;\frac{1}{n}&amp; 
\end{bmatrix}$

Since the resulting view volume is not the canonical view volume, we need to apply another matrix.

A orthographic transformation matrix transforms a rectangular view volume into a cubic view volume with two corners at (-1, -1, -1) and (1, 1, 1), which happens to be the canonical view volume.

Intuitively it will need one translation and one scaling.

$\text{T}_{ortho} = S\left(\frac{2}{r-l},\frac{2}{t-b},\frac{2}{n-f}\right)T\left(\frac{-(l+r)}{2},\frac{-(b+t)}{2}\frac{-(n+f)}{2}\right)$

$M_{ortho} = 
\begin{bmatrix}
    \frac{2}{r-l}&amp; &amp; &amp; \\
    &amp; \frac{2}{t-b} &amp; &amp; \\
    &amp; &amp; \frac{2}{n-f} &amp; \\
    &amp; &amp; &amp; 1
\end{bmatrix}
\begin{bmatrix}
    1 &amp; &amp; &amp; \frac{-(l+r)}{2} \\
    &amp; 1 &amp; &amp; \frac{-(b+t)}{2} \\
    &amp; &amp; 1 &amp; \frac{-(n+f)}{2} \\
    &amp; &amp; &amp; 1
\end{bmatrix}
$

$M_{ortho} = 
\begin{bmatrix}
    \frac{2}{r-l}&amp; &amp; &amp; -\frac{l+r}{r-l} \\
    &amp; \frac{2}{t-b} &amp; &amp; -\frac{t+b}{t-b} \\
    &amp; &amp; \frac{2}{n-f} &amp; -\frac{n+f}{n-f}\\
    &amp; &amp; &amp; 1
\end{bmatrix}
$

Now you can combine them together to form a perspective projection matrix.

$M_{proj} = M_{ortho}M_{persp}$

$M_{proj} = 
\begin{bmatrix}
    \frac{2}{r-l}&amp; &amp; &amp; -\frac{l+r}{r-l} \\
    &amp; \frac{2}{t-b} &amp; &amp; -\frac{t+b}{t-b} \\
    &amp; &amp; \frac{2}{n-f} &amp; -\frac{n+f}{n-f}\\
    &amp; &amp; &amp; 1
\end{bmatrix}
\begin{bmatrix}
1&amp; &amp; &amp; \\
 &amp;1&amp; &amp; \\
 &amp; &amp;\frac{n+f}{n}&amp;-f\\
 &amp; &amp;\frac{1}{n}&amp; 
\end{bmatrix}$

$M_{proj} = 
\begin{bmatrix}
    \frac{2n}{r-l}&amp; &amp; \frac{l+r}{l-r} &amp; \\
    &amp; \frac{2n}{t-b} &amp; \frac{b+t}{b-t} &amp; \\
    &amp; &amp; \frac{n+f}{n-f} &amp; \frac{2fn}{f-n}\\
    &amp; &amp; 1 &amp;
\end{bmatrix}$

If you have a free-moving camera you will need a camera matrix too, thus the final projection matrix centered on the camera is.

$M_{proj} = M_{ortho}M_{persp}M_{camera}$