Cub3D is a 3D graphical project developed at 42 School, inspired by the classic game Wolfenstein 3D. It serves as an introduction to raycasting, a rendering technique that projects a 3D environment from a 2D map. Built in C using the MiniLibX library, this project helps students understand the fundamentals of graphics programming, mathematical projections, and game mechanics.
At its core, cub3d turns a simple 2D map into a real-time, first-person 3D perspective using raycasting. This technique involves casting rays from the playerโs viewpoint and detecting wall collisions to render vertical lines of varying height โ simulating depth.
This project also introduces:
- Parsing and validating configuration files (
.cub) - Texture mapping
- Real-time rendering
- Keyboard input handling
The .cub map file provides layout data, texture paths, and player orientation. After parsing, the game engine uses raycasting to draw a 3D projection of the map from the player's perspective.
Raycasting sends out one ray per vertical pixel column on the screen. Each ray travels forward in small steps until it hits a wall in the 2D map.
To efficiently detect wall collisions, we use Digital Differential Analysis (DDA):
- It steps through the grid square-by-square,
- Stops when a wall is detected,
- Then computes the distance to that wall,
- Which determines the height of the vertical stripe to draw on screen.
This is repeated for every screen column, forming a 3D illusion.
- 2D map parsing from a
.cubconfiguration file - Real-time raycasting engine for a first-person 3D view
- Basic player controls (WASD for movement, arrows for rotation)
- Texture mapping for walls
- Floor and ceiling color rendering
- Collision detection to prevent walking through walls
- Minimal graphics using MiniLibX (no OpenGL or external engines)
You need a Unix-based system (Linux/macOS) and the MiniLibX library (included in the repo or linked automatically).
git clone https://github.com/Inzagini/cub3D.git
cd cub3d
make- W: Move the player forward.
- S: Move the player backward.
- A: Rotate the player to the left (turn the viewpoint).
- D: Rotate the player to the right (turn the viewpoint).
- Left Arrow: Look to the left (rotate view left).
- Right Arrow: Look to the right (rotate view right).
- Esc: Quit the game.
- Izagini GitHub Profile
- paul42b GitHub Profile
Thanks to 42 School for this challenging project! ๐