A simple 3D raycasting engine built with C++ and SDL2, inspired by classic games like Wolfenstein 3D.
This project implements a raycasting renderer that creates a pseudo-3D perspective from a 2D map. The engine uses the DDA (Digital Differential Analysis) algorithm to cast rays and render walls with different colors and shading based on orientation.
- Real-time 3D rendering using raycasting
- Player movement (WASD controls)
- Camera rotation (arrow keys)
- Collision detection
- Multiple wall types with different colors
- Dynamic lighting (walls appear darker on certain sides)
- Interactive map manipulation (spacebar)
- C++ compiler with C++17 support (g++)
- SDL2 library
- Make
Linux (Ubuntu/Debian):
sudo apt-get install libsdl2-devmacOS:
brew install sdl2Windows: Download SDL2 development libraries from libsdl.org
Clone the repository and build using Make:
makeThis will compile the source files and create the raycaster executable.
To clean build artifacts:
make cleanAfter building, run the executable:
./raycaster- W - Move forward
- S - Move backward
- A - Strafe left
- D - Strafe right
- Left Arrow - Turn left
- Right Arrow - Turn right
- Spacebar - Interact with map
- Close window - Exit
.
├── include/ # Header files
│ ├── Engine.h # Main rendering engine
│ ├── Map.h # Map data structure
│ └── Player.h # Player movement and camera
├── src/ # Source files
│ ├── Engine.cpp
│ ├── Map.cpp
│ ├── Player.cpp
│ └── main.cpp
├── obj/ # Compiled object files
├── Makefile # Build configuration
└── raycaster # Executable (after build)
The raycaster works by:
- Casting a ray for each vertical line on the screen
- Using DDA algorithm to trace rays through the 2D grid
- Calculating wall distances to determine wall height
- Rendering vertical lines with heights based on distance
- Applying color and shading based on wall type and orientation
The map is a 24x24 grid where each cell can be empty (0) or contain different wall types (1, 2, 3).
This project is open source and available for educational purposes.