Cub3D is a graphical project that creates a dynamic 3D perspective inside a maze using ray-casting techniques. The project is inspired by the world-famous game Wolfenstein 3D, which was the first FPS ever. This project explores fundamental algorithms in computer graphics and provides hands-on experience with texture mapping, player movement, and collision detection.
- Raycasting Engine: Real-time 3D rendering using raycasting algorithm
- Texture Mapping: Wall textures loaded from XPM files
- Minimap: Real-time minimap showing player position and orientation
- Player Movement: Smooth movement in 4 directions with collision detection
- Mouse Control: Look around using mouse movements
- Customizable Maps: Parse and render custom maps from
.cubfiles - Floor & Ceiling Colors: Configurable RGB colors for floor and ceiling
- Memory Management: Garbage collector for safe memory handling
- Operating System: Linux
- Compiler: gcc
- Libraries:
- MiniLibX
- X11
- Xext
- Math library
-
Clone the repository
git clone https://github.com/yssrexe/Cub3d.git cd Cub3d -
Install MiniLibX (if not already installed)
# For Ubuntu/Debian sudo apt-get install libx11-dev libxext-dev libbsd-dev -
Compile the project
make
This will create an executable called cub3d.
Run the program with a map file as an argument:
./cub3d maps/map.cubThe map file must contain the following elements:
F R,G,B # Floor color (RGB values 0-255)
C R,G,B # Ceiling color (RGB values 0-255)
NO ./path # North wall texture
SO ./path # South wall texture
WE ./path # West wall texture
EA ./path # East wall texture
111111111111 # Map (must be surrounded by walls '1')
100000000011
100000000001
10N000000001 # N/S/E/W: Player starting position and orientation
111111111111
Map Characters:
1- Wall0- Empty space (walkable)N/S/E/W- Player starting position (North/South/East/West orientation)- Map must be closed/surrounded by walls
Wor↑- Move forwardSor↓- Move backwardA- Move leftD- Move right←- Rotate camera left→- Rotate camera rightESC- Exit game
- Move mouse left/right to rotate camera view
Cub3d/
├── includes/ # Header files
│ ├── cub.h # Main header
│ ├── type.h # Type definitions
│ ├── libft.h # Library functions
│ └── rendering.h # Rendering functions
├── parsing/ # Map parsing and validation
├── rendring/ # Raycasting and rendering
├── tex_src/ # Texture management
├── minimap/ # Minimap rendering
├── get_next_line/ # File reading utility
├── LIBFT/ # Custom C library
├── maps/ # Map files and textures
├── main.c # Entry point
├── free_exit.c # Cleanup functions
└── Makefile # Build configuration
Raycasting is a rendering technique that creates a 3D perspective in a 2D map:
- Cast rays from the player's position in the direction they're looking
- Calculate distance to walls using DDA algorithm
- Project walls onto the screen based on distance (farther = smaller)
- Apply textures to wall surfaces
- Render floor and ceiling with solid colors
This technique is much faster than true 3D rendering, allowing smooth real-time performance.
make- Compile the projectmake clean- Remove object filesmake fclean- Remove object files and executablemake re- Recompile the projectmake bonus- Compile with bonus features
Test the program with different map configurations:
./cub3d maps/map.cubMake sure your maps:
- Are properly closed by walls
- Have valid floor/ceiling colors (0-255 RGB)
- Have exactly one player starting position
- Have valid texture paths
- Segmentation fault: Check map validity and ensure all textures exist
- Invalid colors: RGB values must be between 0-255
- Map not rendering: Ensure map is surrounded by walls (1)
- Textures not loading: Verify texture file paths are correct
- yael-yas - Developer
- souel-bo - Developer
This project is part of the 42 School curriculum. It aims to develop skills in:
- Computer graphics
- Algorithm optimization
- C programming
- Memory management
- Mathematical applications
This project is for educational purposes as part of the 42 School curriculum.