Files
cub3d/README.md
2026-02-07 10:59:11 +01:00

3.7 KiB
Raw Permalink Blame History

This project has been created as part of the 42 curriculum by amikhail and aortigos.

cub3d

Description

cub3D is a graphical programming project inspired by the classic game Wolfenstein 3D, one of the first First-Person Shooters ever created.

The objective of this project is to create a real-time 3D representation of a maze from a 2D map, using the ray-casting technique, written in C and rendered with MLX42.

The rendering is done column by column by casting rays from the player's point of view, detecting wall intersections, calculating distances, and projecting textured walls with proper persepective correction. Floor and ceiling colors are also rendered to complete the scene.

This project focuses on:

  • Low-level graphics programming
  • Mathematical projection and geometry
  • Parsing and validation
  • Real-time rendering performance

Features

  • Ray-casting rendering engine
  • Directional wall textures (North, South, East, West)
  • Floor and ceiling RGB colors
  • Player movement and camera rotation
  • Collision detection
  • Strict .cub file parsing and validation
  • Clean error handling and memory management
  • MLX42 rendering loop

Instructions

Requirements

  • Linux or macOS
  • CMake
  • MLX42 / MLX
  • C compiler (gcc or clang)

Compilation

Clone the repository and run:

make

This will:

  • Build MLX42
  • Compile libft, ft_printf, and get_next_line
  • Generate the cub3d executable

Execution

./cub3D assets/maps/map.cub

The program requires exactly one argument: a valid .cub map file.

Controls

Key Action
W Move forward
S Move backward
A Strafe left
D Strafe right
Rotate camera left
Rotate camera right
ESC Exit the program

Map configuration (.cub)

A .cub file contains:

  • Wall textures (NO, SO, WE, EA)
  • Floor and ceiling colors (RGB format)
  • Map layout, composed of:
    • 1 for walls
    • 0 for empty space
    • N, S, E or W for the player start position
  • Spaces are allowed and handled correctly

The map is strictly validated:

  • Exactly one player position
  • Map must be fully closed by walls
  • Only valid characters
  • No empty lines inside the map
  • RGB values between 0 and 255

Example:

111111
100001
1000N1
111111

Resources

The following resources were used during the development of this project to understand ray-casting, cub3D structure, and common mistakes:

AI Usage

AI tools were used only as assistance, specifically for:

  • Understanding ray-casting concepts
  • Improving documentation clarity
  • Reviewing logic and edge cases

All generated content was reviewed, understood, and manually implemented. No AI-generated code was copied blindly into the project.