ProjectsSystems, network & algorithms
Cub3D
A raycaster in C
- Period
- Jul 2025
- Context
- 42 curriculum
- Team
- group
- Grade
- 125/100
- C
- Low-level
- Algorithms
- Graphics
- Imperative programming
- Mathematics
A raycaster in C, in the spirit of Wolfenstein 3D: a two-dimensional map, displayed as if you were walking through it in first person. Built by two people, with the MiniLibX.
The principle
There is no real 3D: for each column of pixels, a ray is cast from the player across the 2D map. The DDA (Digital Differential Analyzer) algorithm moves that ray from one grid line to the next, so the first wall is found without testing every point.
The distance to the wall, corrected to avoid the “fish-eye” effect, gives the height of the wall slice to draw. The face that was hit (north, south, east, west) picks the texture.
What we added
Parsing of the .cub file cleanly rejects any malformed or open map. As extras: a real-time minimap, an animated sprite, mouse-controlled camera (without the pointer escaping the window), doors you can open and close, and collisions that stop you from walking through walls.
What I took away
- A little well-placed trigonometry replaces a lot of computation.
- Rendering a frame every time forces you to think about the cost of each operation.