Skip to content
/ cub3D Public

๐Ÿบ Cub3d is a 3D raycasting engine project from 42 School, inspired by Wolfenstein 3D. It simulates a first-person perspective by casting rays and detecting wall collisions, teaching the basics of 3D rendering and game development in C with the MiniLibX library.

Notifications You must be signed in to change notification settings

Inzagini/cub3D

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸบCub3D

Cub3D is a 3D graphical project developed at 42 School, inspired by the classic game Wolfenstein 3D. It serves as an introduction to raycasting, a rendering technique that projects a 3D environment from a 2D map. Built in C using the MiniLibX library, this project helps students understand the fundamentals of graphics programming, mathematical projections, and game mechanics.


๐Ÿง  Concept

At its core, cub3d turns a simple 2D map into a real-time, first-person 3D perspective using raycasting. This technique involves casting rays from the playerโ€™s viewpoint and detecting wall collisions to render vertical lines of varying height โ€” simulating depth.

This project also introduces:

  • Parsing and validating configuration files (.cub)
  • Texture mapping
  • Real-time rendering
  • Keyboard input handling

๐Ÿš€ How It Works

The .cub map file provides layout data, texture paths, and player orientation. After parsing, the game engine uses raycasting to draw a 3D projection of the map from the player's perspective.

๐Ÿ“ก Raycasting & DDA Explained

Raycasting sends out one ray per vertical pixel column on the screen. Each ray travels forward in small steps until it hits a wall in the 2D map.

To efficiently detect wall collisions, we use Digital Differential Analysis (DDA):

  • It steps through the grid square-by-square,
  • Stops when a wall is detected,
  • Then computes the distance to that wall,
  • Which determines the height of the vertical stripe to draw on screen.

This is repeated for every screen column, forming a 3D illusion.


โœจ Key Features (Mandatory Part)

  • 2D map parsing from a .cub configuration file
  • Real-time raycasting engine for a first-person 3D view
  • Basic player controls (WASD for movement, arrows for rotation)
  • Texture mapping for walls
  • Floor and ceiling color rendering
  • Collision detection to prevent walking through walls
  • Minimal graphics using MiniLibX (no OpenGL or external engines)

๐Ÿ›  Installation & Usage

Prerequisites

You need a Unix-based system (Linux/macOS) and the MiniLibX library (included in the repo or linked automatically).

Clone and Build

git clone https://github.com/Inzagini/cub3D.git
cd cub3d
make

๐ŸŽฎ Gameplay Instructions

  • W: Move the player forward.
  • S: Move the player backward.
  • A: Rotate the player to the left (turn the viewpoint).
  • D: Rotate the player to the right (turn the viewpoint).
  • Left Arrow: Look to the left (rotate view left).
  • Right Arrow: Look to the right (rotate view right).
  • Esc: Quit the game.

๐Ÿ‘จโ€๐Ÿ’ป Authors

๐ŸŒŸ Acknowledgments

Thanks to 42 School for this challenging project! ๐ŸŽ“

About

๐Ÿบ Cub3d is a 3D raycasting engine project from 42 School, inspired by Wolfenstein 3D. It simulates a first-person perspective by casting rays and detecting wall collisions, teaching the basics of 3D rendering and game development in C with the MiniLibX library.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •