Rotation Matrix:
For a 3-dimensional point, we have three angles to consider -
So we have a vector {x, y, z}. To rotate it, we need to mutiply the 3D Rotation Matrix with it.
$\alpha$ for x axis
$\beta$ for y-axis
$\theta$ for z-axis
Note: we can use these 3 matrices to calculate {x', y', z'} after rotation.
We just need to construct the first surface. Then the other 5 surfaces can be easily calculated by rotating the first surface. For example, the second surface are the rotation of 90 degrees of the first surface along the x or y axis.
Perspective Projection
-
We can imagine a virtual camera in front of the x-y axis plane, and set depth = 1 / z, z = z + distanceFromCam to simulate how we see the cube in the real world.
-
How to map 3-dimensional points to 2-dimensional points: According to Perspective Projection, x' = x * depth, y' = y * depth. In the program, we also need to adjust the position and size of the cube:
xp := width / 2 + horizontalOffset + K1 * ooz * x * 2
yp := height / 2 + K1 * ooz * y
- When one depth is less that the other depth, the bigger one can cover the smaller one.