This project has been created as part of the 42 curriculum by ccastro and samamaev.
cub3D is a 3D graphical game engine built in C, inspired by the legendary 1992 game Wolfenstein 3D by Id Software. The goal of the project is to create a dynamic first-person perspective inside a maze using ray-casting algorithms.
The application reads a scene description file (.cub), parses configuration options (wall textures for North, South, East, and West faces, floor/ceiling colors, and map geometry), and renders a real-time textured 3D view using the miniLibX graphics library.
- Real-Time 3D Raycasting Engine: Uses Digital Differential Analysis (DDA) to calculate wall intersections, ray distances, and perspective projection.
- Directional Wall Texturing: Maps distinct XPM texture images to North, South, East, and West wall faces.
- Dynamic Field of View: Focal-length adjusted raycasting math to preserve proper block aspect ratios regardless of window dimensions.
- Smooth Player Controls: Real-time movement (WASD) with wall collision padding and view rotation (Left/Right arrows).
- Robust
.cubScene Parsing: Full validation of map closure, player spawn point, color boundaries, and texture file paths with explicit error reporting (Error\n...).
- Operating System: Linux (X11 / XQuartz setup required for miniLibX)
- Compiler:
cc - Libraries:
make,libXext,libX11,libm
Clone the repository and compile the project using the provided Makefile:
# Compile the executable
make
# Clean object files
make clean
# Clean object files and binary
make fclean
# Rebuild the project completely
make reRun cub3D by passing a valid .cub scene file as the single argument:
./cub3D maps/map.cub| Input | Action |
|---|---|
W |
Move Forward |
S |
Move Backward |
A |
Strafe Left |
D |
Strafe Right |
Left Arrow |
Rotate View Left |
Right Arrow |
Rotate View Right |
ESC |
Exit Game Cleanly |
Red Cross (X) |
Close Window and Exit |
Scene files must follow this format:
NO ./textures/north_wall.xpm
SO ./textures/south_wall.xpm
WE ./textures/west_wall.xpm
EA ./textures/east_wall.xpm
F 220,100,0
C 225,30,0
111111
100101
101001
1100N1
111111
- Identifiers:
NO,SO,WE,EA(Wall Texture Paths),F(Floor RGB),C(Ceiling RGB). - Map Characters:
1: Wall0: Empty Walkable SpaceN,S,E,W: Player Spawn position and facing orientation (North, South, East, West).
- Lode's Computer Graphics Tutorial - Raycasting: Fundamental guide on raycasting math, DDA algorithms, and camera planes.
- Wolfenstein 3D Bible & Tech Specs: Historical implementation context.
- 42 miniLibX Documentation: Reference for window management, X11 events, and pixel buffer rendering.
In accordance with Chapter IV (AI Instructions) of the 42 curriculum:
- Code Optimization & Diagnostics: AI was used to diagnose perspective rendering issues (wall aspect ratio / focal length formula adjustments for square window dimensions).
- Documentation: AI assisted in formatting and generating this README.md file in accordance with 42 curriculum requirements.
- Code Review: AI was utilized as a pair-programming partner to audit error handling, memory safety, and evaluation requirements before defense submission.