Create the three sides of your figure, add them to the list, run, and... here's your 3D visualization!
5 possible iterations, from simple to complex:
- Orthographic projection (top-down view)
- Horizontal movement (left to right)
- Full 3D rotation and translation
- color assignment
- Depth-based rendering using a Z-buffe
Each vertex is represented as a vector A = [aₓ, aᵧ, a𝓏]. To apply rotation, the vector is multiplied by rotation matrices. Matrix multiplication follows the associative property:
examples: (AT₁)T₂ = A(T₁T₂)
Moving the mouse on the x or y axis will trigger the listener to update the pixels.
To manage visibility and occlusion, the engine uses a Z-buffer. This is a 2D array that stores the depth value of the closest triangle rendered at each pixel.
- At initialization, the Z-buffer is filled with a maximum depth value.
- During rasterization, each triangle fragment is compared against the current depth value at its pixel.
- If the fragment is closer to the camera, the Z-buffer and pixel color are updated.
- If it is farther, the fragment is discarded. This technique ensures that only the front-most surfaces are visible, eliminating the need for manual geometry sorting. The Z-buffer is a standard feature in modern rendering pipelines and is essential for producing accurate and realistic 3D scenes.