Welcome to Cub3D
Cub3D is a 3D raycasting engine written in C that recreates the classic first-person perspective of games like Wolfenstein 3D. This project demonstrates fundamental computer graphics techniques, including raycasting algorithms, texture mapping, and real-time rendering.Cub3D is a 42 School project that explores raycasting principles without using external 3D rendering libraries.
What is Raycasting?
Raycasting is a rendering technique that creates a 3D perspective in a 2D map by casting rays from the player’s viewpoint. For each vertical line on the screen, a ray is cast into the game world to determine:- Distance to the nearest wall - determines the height of the wall slice
- Wall orientation - determines which texture to apply (North, South, East, or West)
- Texture coordinates - maps the correct portion of the texture to the wall
Key Features
Real-time 3D Rendering
Renders a 3D perspective at 1732x1000 resolution using raycasting algorithms implemented in
raycasting.cTexture Mapping
Supports XPM texture files for all four wall directions (North, South, East, West)
Smooth Movement
WASD movement and arrow key rotation with collision detection
Custom Map Format
Parse
.cub map files with configurable textures, colors, and layoutsTechnical Overview
Core Components
- Raycasting Engine (
raycasting.c:102-127) - Main rendering loop that casts rays across the screen width - DDA Algorithm (
raycasting.c:15-66) - Digital Differential Analysis for efficient grid traversal - Texture Mapping (
drawing.c) - Maps wall textures based on ray intersection points - Map Parser - Validates and loads
.cubmap files with texture paths and RGB color definitions
Window Resolution
The engine renders at a fixed resolution defined incub3d.h:30-31:
Field of View
The camera’s field of view is controlled by the plane vector perpendicular to the direction vector:Map File Format
Cub3D uses.cub files to define game worlds. Here’s an example from maps/COME.cub:
Map Elements:
NO/SO/WE/EA- Texture paths for North, South, West, East wallsF- Floor color in RGB format (0-255)C- Ceiling color in RGB format (0-255)1- Wall0- Empty spaceN/S/E/W- Player starting position and direction
Architecture
The project is structured around a centralt_map structure (cub3d.h:79-162) that contains:
- Map data and dimensions
- Player position and direction vectors
- Texture information for all four walls
- MLX window and image pointers
- Raycasting calculation variables
Next Steps
Installation
Set up dependencies and build the project
Quick Start
Run your first 3D scene in minutes