Cub3D is a first-person 3D game inspired by Wolfenstein 3D.
It uses a technique called Raycasting to transform a 2D map into a 3D world.
This project teaches:
- Computer graphics & rendering 🖥️
- Math behind projections 📐
- Handling input (keyboard/mouse) 🎮
- Efficient algorithms & optimization 🚀
Raycasting sends imaginary rays from the player’s camera field of view.
Each ray:
- Moves forward step-by-step
- Stops when it hits a wall
- Measures distance to that wall
📌 Closer walls look bigger,
📌 Farther walls look smaller.
This creates the illusion of 3D from a 2D grid
To detect collisions efficiently, we use DDA, which:
- Steps ray grid cell by grid cell
- Checks only necessary positions
- Avoids expensive per-pixel calculations
Ensures:
- Smooth performance
- Fast wall detection
- Accurate rendering
The .cub file contains:
- Wall textures
- Floor & ceiling colors
- Map layout
Example:
111111
100001
1000N1
111111Map requirements:
- Must be fully closed by walls (
1) - Only one player start position (N, S, E, W)
- Valid characters:
1→ Wall0→ Empty spaceN S E W→ Player spawn + direction- Space allowed as padding (but boundaries must still be walls)
❌ If the map is invalid → Program exits with an error
| Key | Action |
|---|---|
| W / A / S / D | Move forward / left / backward / right |
| ← / → | Rotate view direction |
| ESC | Exit the game |
Smooth movement and rotation for a realistic FPS feeling
make./cub3D maps/example.cub- Raycasting part: Mohammad Emran (me)
- Parsing part: Ahmad Saade [@AhmadSaadeh03]
