I need a custom projection matrix, which is orthographic in one dimension and perspective in the other.
That means I need to map the vertices of a trapezoidal prism in real world coordinate system to the vertices of a unit cube.
I tried to visualize it in the following image:
The red coordinates (in real world coordinate system) must be mapped to the green coordinates (unit cube).
What does the projection matrix look like?
After a bit of thought I think that it might be equally helpfull to find a transformation which compresses a cube on one side and forms the cube into a trapezoidal prism with a square base.
Is there a known transformation matrix for this?
In pursuit of this train of thought I found this image with a transformation of a square into a trapez on this site.

I know that this is only in 2D, but maybe it would be helpfull to now this transformation and expand it to my case with 3 dimensions.
What have I done already: My first try was to use a triangle prism as view frustum, so I asked this question. But when I used the projection matrix from the answer I got strange results (it seems like the projection was not perspective at all - neither in $x$ direction nor in $y$ direction). I thought, that this might be because I had no near clipping plane.
So I tried to use the equation given and tried to calculate the matrix by myself:
$$ \begin{align} A&= \begin{pmatrix}1&1&1&-1\\ \:1&1&-1&-1\\ \:1&-1&-1&1\\ \:1&1&1&1\end{pmatrix} \begin{pmatrix}r&r&r&l\\ \:n\cdot \:t&f\cdot \:t&-f\cdot \:t&-n\cdot \:t\\ \:n&f&f&n\\ \:1&1&1&1\end{pmatrix}^{-1} \\ A &= \begin{pmatrix}1&1&1&-1\\ \:1&1&-1&-1\\ \:1&-1&-1&1\\ \:1&1&1&1\end{pmatrix} \begin{pmatrix}-\frac{1}{-r+l}&0&\frac{1}{-f+n}&-\frac{lf-nr}{\left(-f+n\right)\left(-r+l\right)}\\ \frac{n}{f\left(-r+l\right)}&\frac{1}{2tf}&\frac{-f-n}{2f\left(-f+n\right)}&\frac{n\left(-nr+lf\right)}{f\left(-f+n\right)\left(-r+l\right)}\\ -\frac{n}{f\left(-r+l\right)}&-\frac{1}{2tf}&\frac{1}{2f}&\frac{nr}{f\left(-r+l\right)}\\ \frac{1}{-r+l}&0&0&-\frac{r}{-r+l}\end{pmatrix}\\ A&= \begin{pmatrix}-\frac{2}{-r+l}&0&0&\frac{l+r}{-r+l}\\ \frac{-2f+2n}{f\left(-r+l\right)}&\frac{1}{ft}&-\frac{1}{f}&\frac{lf-2nr+rf}{f\left(-r+l\right)}\\ 0&0&\frac{2}{-f+n}&-\frac{f+n}{-f+n}\\ 0&0&0&1\end{pmatrix} \end{align} $$
This seems correct for the four vertices with which I constructed my matrix, e.g. $A\begin{pmatrix}r\\nt\\n\end{pmatrix} = \begin{pmatrix}1\\1\\1\end{pmatrix}$
But when I try to transform the other four vertices I get wrong results:
$$ A\begin{pmatrix}l\\ft\\f\end{pmatrix} = \begin{pmatrix}-1\\\pmb{0.5}\\-1\end{pmatrix} should\;be \begin{pmatrix}-1\\1\\-1\end{pmatrix}\\ A\begin{pmatrix}l\\nt\\n\end{pmatrix} = \begin{pmatrix}-1\\\pmb{0.5}\\1\end{pmatrix} should\;be \begin{pmatrix}-1\\1\\1\end{pmatrix}\\ A\begin{pmatrix}r\\-nt\\n\end{pmatrix} = \begin{pmatrix}1\\\pmb{-0.5}\\1\end{pmatrix} should\;be \begin{pmatrix}1\\-1\\1\end{pmatrix}\\ A\begin{pmatrix}l\\-ft\\f\end{pmatrix} = \begin{pmatrix}-1\\\pmb{-1.5}\\-1\end{pmatrix} should\;be \begin{pmatrix}-1\\-1\\-1\end{pmatrix} $$
This is the point, where I don't know how to proceed to get it right. What is wrong with my calculations (I think I double-checked everything)?
I noticed that only the $y$ component is wrong, but I don't know how this could lead me into the right direction...
