See it in the room

C · MiniLibX · raycasting · 42 Common Core

cub3D

A first-person 3D maze drawn with raycasting, in C, with doors, a minimap and mouse look.

The problem

The problem

Turn a 2D map file into a textured first-person view in real time, and refuse any map file that is broken.

What I built

  • A raycaster with a different texture for each wall direction (north, south, east, west).
  • A scene parser for texture paths and floor and ceiling colours.
  • Bonus: mouse look, wall collision, doors, an animated sprite and a minimap.

Technical decisions

  • An iterative, queue-based flood fill checks that every reachable cell is closed in by walls.
  • The map is padded to a rectangle before validation, so edge checks stay simple.
  • Doors are only accepted between two walls.

What makes it hard

  • Proving a map is closed without recursion that could overflow the stack on a large map.
  • Mapping the right column of a texture onto each ray hit.

What I can do because of it

  • Validate untrusted input before using it.
  • Use the maths behind real-time rendering: vectors, angles, projection.
  • Keep a frame loop fast in plain C.