My first RayCaster with miniLibX — 42 Network project
Cub3D is a 42 school project inspired by the legendary Wolfenstein 3D (1992) — the first-ever first-person shooter. Using raycasting, the program renders a dynamic 3D perspective view inside a maze defined by a 2D map file.
This project explores the foundations of computer graphics, trigonometry, and real-time rendering using the miniLibX graphics library.
- 🎯 Raycasting Engine — Real-time 3D rendering from a 2D map using the DDA algorithm
- 🧱 Textured Walls — Different textures for North, South, East, and West walls
- 🎨 Floor & Ceiling Colors — Configurable RGB colors for floor and ceiling
- 🕹️ Player Movement — Smooth WASD movement and arrow-key rotation
- 🗺️ Map Parsing — Load custom
.cubmap files with validation - 🚪 Collision Detection — Wall collision prevents walking through walls
- GCC compiler
- Make
- miniLibX (included or install via package manager)
- X11 libraries (
sudo apt install libx11-dev libxext-devon Ubuntu) - A UNIX-based OS (Linux / macOS)
git clone https://github.com/JMADIL/CUB3D.git
cd CUB3D
make./cub3d maps/map.cub| Key | Action |
|---|---|
W |
Move forward |
S |
Move backward |
A |
Strafe left |
D |
Strafe right |
← |
Rotate camera left |
→ |
Rotate camera right |
ESC |
Exit the game |
NO ./textures/north.xpm
SO ./textures/south.xpm
WE ./textures/west.xpm
EA ./textures/east.xpm
F 220,100,0
C 135,206,235
111111
100101
101001
1100N1
111111
| Symbol | Meaning |
|---|---|
1 |
Wall |
0 |
Empty space |
N/S/E/W |
Player start position + facing direction |
CUB3D/
├── Makefile # Build system
├── cub3d.c # Entry point & game loop
├── cub3d.h # Header with structs & prototypes
├── cub.cub # Sample map file
├── PROJECT_SUMMARY.md # Detailed project documentation
├── parsing/ # Map file parsing & validation
├── raycasting/ # Raycasting engine (DDA algorithm)
├── textures/ # Wall texture files (.xpm)
├── utils/ # Utility functions
├── libft/ # Custom C library (libft)
└── documentation/ # Additional docs & references
Player
│
╲ │ ╱ For each vertical column of the screen:
╲ │ ╱ 1. Cast a ray from the player
╲ │ ╱ 2. Find where the ray hits a wall (DDA)
╲ │ ╱ 3. Calculate the wall height based on distance
╲ │ ╱ 4. Draw the textured wall slice
╲ │ ╱ 5. Apply the correct texture (N/S/E/W)
╲│╱
══════════════ Result: A 3D perspective illusion
║ ║ from a 2D grid!
║ WALL ║
║ ║
══════════════
| Concept | Description |
|---|---|
| Raycasting | Rendering a 3D view from a 2D map using rays |
| DDA Algorithm | Efficient grid traversal for ray-wall intersection |
| Trigonometry | Angles, sine/cosine for movement and rotation |
| Texture Mapping | Applying 2D textures to 3D-rendered wall surfaces |
| miniLibX | Low-level graphics rendering and event handling |
| File Parsing | Reading and validating structured map files |
| Game Loop | Continuous rendering and input handling |
Adil Jamoun — @JMADIL
🏫 1337 Coding School (42 Network) — Morocco