This is a small project I built in order to learn about and experiment with homogeneous coordinates, transformation matrices and perspective projection.
- the
$x$ -coordinate is unchanged and doesn’t influence the result - the
$y$ and$z$ components are projected onto the rotated basis vectors-
$\mathbf{\hat{i}}$ is simply rotated by$\theta$ -
$\mathbf{\hat{j}}$ can be determined by rotating$\mathbf{\hat{i}}$ by$90°$
-
- thus the resulting rotation matrix is:
-
translation is done by performing a shear transformation in the
$4^{th}$ dimension of the homogeneous coordinate system -
to do this, we project our point onto the modified basis vector of the
$4^{th}$ dimension
- we want to project our points onto our projection window
- the height and the width of the projection window should range from
$[-1; +1]$ , because this is easier to work with - for the
$y$ -axis, we can simply define that our projection window ranges from$-1$ to$+1$ - doing the same for the
$x$ -axis would not work, since our screen is not necessarily square - thus we need to introduce an aspect ratio
$ar = \frac{w}{h}$ - for the
$x$ -axis, we now simple define that our projection window ranges from$-ar$ to$+ar$ - by dividing the
$x$ -values by the aspect ratio, we get our desired range of$[-1; +1]$
- for orthographic projection, we simply ignore the
$z$ component - this means that there is no depth perception
- we simply need to account for the aspect ratio
- here we want to introduce depth perception, thus objects farther away should appear smaller
- we first define a field of view
$\alpha$ (see Perspective Projection - OGL dev for a visualisation) - in order to get the projected
$y$ component$y_p$ , we can use the rule of similar triangles ($z_{near}$ is the distance from the camera to the projection window):
- determining
$x_p$ works exactly the same, but we have to account for the aspect ratio as well:
- since the
$y$ -coordinate of the top of the projection window is 1, we can calculate the distance$z_{near}$ from the camera to the projection window as follows:
- putting everything together, we arrive at the following projection matrix: