1. Defining the space – Defining the 3D space
In the end, instead of using the world space to 2D space algorithm above, we can use the following 3D to
screen algorithm:
1.
2.
3.
4.
Transform points from world space to clip space
Pick the points z coordinate of which is between znear and zfar
Project transformed points onto the projection plane
Transform projected points to screen space
Transforming between 3D spaces
In this section I will only discuss about transforming world space to clip space because that is what you will
want to do most of the time.
All proper transformations in 3D spaces consist of two operations. Firstly we translate (move) the point
relatively to another point, and secondly we orient the point relatively to another orientation. In our case
we need to translate points relatively to camera’s position in world space and orient them relatively to
camera’s orientation in world space.
In modern 3D graphics there is so called 4x4 “lookAt –matrix” which takes camera’s position and orientation vector, and transforms the point to clip space. In fact, in proper 3D graphics ALL translations, rotations,
and scales are done with 4x4 matrices. Unfortunately for us computing them is time and performance consuming, and these are two things we need the most. We can avoid complicated math using the fact that in
2D rotations are A LOT easier to compute. To use 2D rotations in 3D we need to “lock” two axes leaving
only one to rotate around. Since we really would like to turn right and left, we could make it possible only
rotate around the y axis (right and left), and “lock” x and z axes. This way we can perform 2D rotations
around a single axis and think of 3D world as 2D by looking down the y axis. Also locking it allows us to represent orientation as a single angle instead of vectors or quaternions.
Therefore let: