This code example presents a basic 3D renderer in Python, coded with pygame library. It was inspired by a very nice tutorial on basic 3D rendering in Python authored by Auctux
- Load pygame library and set the basic settings like screen size, title,etc.
- Encode cube geometry as a multidimensional list of vertex positions
- Define rotation matrices by with respect to each axis, and combine them into a single rotation matrix
- Multiply the rotation matrix with projection matrix (which maps 3D points onto a 2D surface)
- Mark the calculated 2D points with circles
- Draw the cube sides as polygons in 2D space
Rendered cube as output:
Full source code can be found on GitHub.
Another great place to learn more about basic rendering and ray tracing is Darko Supe's Youtube channel.