In this project, I applied some basic linear algebra concepts that I just learnt to implement a simple 3D render of a prism.
The method used to display and animate a 3D object is simple:
- Declare the vertices of the 3D object (in homogeneous coordinates),
- Define the faces by listing which vertices form each face,
- Apply a rotation transformation to spin the object around its center,
- Translate the object along the Z-axis to place it inside the viewable frustum,
- Apply a perspective projection to simulate depth,
- Convert the projected coordinates from normalized device space to window space (screen scaling),
- Draw the edges by connecting the vertices according to the face definitions,
- Display the current buffer onto the screen,
- Update the rotation angle and repeat the whole process for the next frame.
No optimizations
cargo runOptimized
cargo run --releaseYou can change the prism's rotation speed directly in main.rs:
// Rotation speed
const THETA_ITERS: f32 = 0.01;main→ main loop and variable initializationsdot_product→ single point precision matrix multiplicationdraw_line→ given two points it draws a line in a 2D matrixdraw→ draws the pixels in the window buffer
