Cub3D is a 3D raycasting project implemented in C using the MiniLibX graphics library. Developed for the 42 network, it renders a 3D view of a 2D map and allows player navigation through a virtual environment.
- Raycasting engine: Renders a pseudo-3D scene from a 2D map.
- Map parsing: Validates map files and detects player starting positions via functions such as
find_char. - Player movement: Supports forward, backward, and lateral movement along with rotation.
- Cross-platform support: Uses different MiniLibX implementations for macOS (
mlx_mac/mlx.h) and Linux (mlx_linux/mlx.h). - Custom utilities: Includes helper functions for graphics, vector math, and more from
cub3d.h.
cub3d/
โโโ cub3d # Main project directory and executable target
โโโ include # Header files (e.g. [cub3d.h](include/cub3d.h))
โโโ libft # Custom library (Libft implementation)
โโโ mlx_linux # MiniLibX implementation for Linux
โโโ mlx_mac # MiniLibX implementation for macOS
โโโ src # Source code (e.g. [utils.c](src/parsing/utils.c))
โโโ Makefile # Build configuration and targets
โโโ .vscode # VSCode configurations (launch.json, settings.json)
- XQuartz
- Xcode command line tools
- GCC and Make
- X11 libraries:
libxext-dev,libx11-dev,libbsd-dev, etc.
For Ubuntu/Debian, install dependencies with:
sudo apt-get install gcc make libxext-dev libx11-dev libbsd-devRun the following command in the project root to compile the project:
makeThe appropriate MiniLibX library will be selected based on your operating system. The executable will be created as defined in the Makefile.
Launch the game with:
./cub3d [map_file]- [map_file]: Path to a valid map file containing characters for walls (
1), empty spaces (0), and a single player starting position marked with one ofN,S,E, orW.
If the map contains any invalid character, functions like find_char will print an error.
Controls vary by operating system (see key mappings in cub3d.h):
- Movement: Typically use WASD keys (or corresponding macOS keys) for forward, backward, left, and right movement.
- Rotation: Use the arrow keys.
- Exit: Press the Escape key.
- This project can display debug info (e.g., FPS, raycasting details) when enabled.
- Modify debug flags as needed in your configuration.
This project is released under the BSD 2-Clause License. See mlx_linux/LICENSE for details.
- MiniLibX: A simple X-Window Interface Library, see mlx_linux/README.md for more info.
- Libft: Utility functions and data structures used throughout the project.