MA
MatthieuGillieron/cub3d
A simple 3D game engine using raycasting, inspired by Wolfenstein 3D
Cub3D - 3D Raycasting Engine
A 3D game engine inspired by Wolfenstein 3D, built from scratch using raycasting techniques
Features โข Installation โข Usage โข Documentation โข Technical Details
๐ฏ Overview
Cub3D is a 3D raycasting engine that creates a first-person perspective game similar to the classic Wolfenstein 3D. This project demonstrates advanced graphics programming concepts, mathematical algorithms, and real-time rendering techniques using the MLX graphics library.
๐ฎ Key Features
- Real-time 3D Rendering using raycasting algorithm
- Textured Walls with XPM image support
- Smooth Player Movement with collision detection
- Configurable Maps via .cub configuration files
- Cross-platform Compatibility (macOS/Linux)
- Optimized Performance for 60+ FPS gameplay
๐ Quick Start
Prerequisites
- GCC compiler with C99 support
- Make build system
- MLX Library (included)
- macOS or Linux operating system
Installation
# Clone the repository
git clone https://github.com/yourusername/cub3d.git
cd cub3d
# Build the project
make
# Run with a map file
./cub3d maps/test.cubControls
| Key | Action |
|---|---|
W |
Move forward |
S |
Move backward |
A |
Strafe left |
D |
Strafe right |
โ |
Rotate left |
โ |
Rotate right |
ESC |
Exit game |
๐ Project Structure
cub3d/
โโโ ๐ Makefile # Build configuration
โโโ ๐ includes/ # Header files
โ โโโ cube3d.h # Main header
โโโ ๐ src/ # Source code
โ โโโ ๐ events/ # Input handling
โ โโโ ๐ init/ # Initialization
โ โโโ ๐ movement/ # Player movement
โ โโโ ๐ parsing/ # File parsing
โ โโโ ๐ raycasting/ # 3D rendering
โ โโโ ๐ render/ # Graphics output
โ โโโ ๐ utils/ # Utilities
โโโ ๐ docs/ # Documentation
โโโ ๐ maps/ # Game maps (.cub)
โโโ ๐ textures/ # Wall textures (.xpm)
โโโ ๐ libft/ # Custom C library
โโโ ๐ mlx/ # Graphics library
๐จ Map Configuration
.cub File Format
NO ./textures/north.xpm
SO ./textures/south.xpm
WE ./textures/west.xpm
EA ./textures/east.xpm
F 220,100,0
C 225,30,0
111111
100001
101001
1000N1
111111
Configuration Elements
- NO/SO/WE/EA: Texture paths for each wall direction
- F: Floor color (RGB format)
- C: Ceiling color (RGB format)
- Map Grid:
1= Wall0= Empty spaceN/S/E/W= Player start position and direction
๐ง Technical Implementation
Core Technologies
- Language: C (C99 standard)
- Graphics: MLX (MiniLibX)
- Mathematics: Trigonometry, Linear Algebra
- Algorithms: DDA, Raycasting, Texture Mapping
Architecture Overview
graph TD
A[Main Loop] --> B[Event Handling]
A --> C[Raycasting Engine]
A --> D[Rendering Pipeline]
B --> E[Keyboard Input]
B --> F[Window Events]
C --> G[Ray Calculation]
C --> H[Wall Detection]
C --> I[Distance Calculation]
D --> J[Texture Mapping]
D --> K[Pixel Drawing]
D --> L[Frame Buffer]
Performance Metrics
- Frame Rate: 60+ FPS
- Resolution: 800x600 (configurable)
- Memory Usage: < 50MB
- CPU Usage: Optimized for real-time rendering
๐ Documentation
Module Documentation
| Module | Description | Documentation |
|---|---|---|
| Events | Input and window management | ๐ Events Docs |
| Movement | Player movement mechanics | ๐ Movement Docs |
| Raycasting | 3D rendering algorithm | ๐ Raycasting Docs |
| Parsing | File parsing and validation | ๐ Parsing Docs |
| Render | Graphics rendering pipeline | ๐ Render Docs |
| Init | System initialization | ๐ Init Docs |
| Utils | Utility functions | ๐ Utils Docs |
Complete Project Overview
๐ Project Overview - Comprehensive technical documentation
๐ ๏ธ Build System
Makefile Targets
make # Build the project
make clean # Remove object files
make fclean # Remove all generated files
make re # Rebuild from scratch
make leaks # Run with memory leak detectionCompilation Flags
- -Wall -Wextra -Werror: Strict error checking
- 42 Norm Compliant: Follows 42 School coding standards
- Optimized Build: Performance-focused compilation
๐งช Testing
Map Validation
- โ Wall enclosure verification
- โ Player position validation
- โ Texture file existence
- โ Color format validation
Performance Testing
- โ Frame rate monitoring
- โ Memory leak detection
- โ Input responsiveness
- โ Rendering efficiency
Sample Maps
| Map | Description | Difficulty |
|---|---|---|
simple.cub |
Basic rectangular room | Beginner |
complex.cub |
Multi-room layout | Intermediate |
maze.cub |
Challenging maze | Advanced |
๐ฏ Learning Objectives
This project demonstrates mastery of:
- Graphics Programming: Real-time 3D rendering
- Mathematical Concepts: Trigonometry, vector mathematics
- Algorithm Implementation: DDA, raycasting
- Memory Management: Efficient resource handling
- System Programming: Low-level graphics operations
- Software Architecture: Modular design patterns
๐ค Contributing
Development Guidelines
- Follow 42 Norm: Strict adherence to coding standards
- Modular Design: Keep functions focused and reusable
- Error Handling: Comprehensive error checking
- Documentation: Clear code documentation
- Testing: Validate all changes thoroughly
Code Style
// Function naming: lowercase with underscores
int calculate_distance(t_player *player, t_wall *wall);
// Structure naming: s_ prefix for struct, t_ for typedef
typedef struct s_game
{
void *mlx;
void *win;
t_img img;
} t_game;๐ License
This project is part of the 42 School curriculum. Educational use only.
๐ Acknowledgments
- 42 School for the project specifications
- MLX Library developers for the graphics framework
- Wolfenstein 3D for the original raycasting inspiration
- John Carmack for pioneering 3D graphics techniques
Built with โค๏ธ at 42 School