Skip to content

Latest commit

 

History

22 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by ccastro and samamaev.

cub3D - My First RayCaster with miniLibX

Description

cub3D is a 3D graphical game engine built in C, inspired by the legendary 1992 game Wolfenstein 3D by Id Software. The goal of the project is to create a dynamic first-person perspective inside a maze using ray-casting algorithms.

The application reads a scene description file (.cub), parses configuration options (wall textures for North, South, East, and West faces, floor/ceiling colors, and map geometry), and renders a real-time textured 3D view using the miniLibX graphics library.

Key Features

  • Real-Time 3D Raycasting Engine: Uses Digital Differential Analysis (DDA) to calculate wall intersections, ray distances, and perspective projection.
  • Directional Wall Texturing: Maps distinct XPM texture images to North, South, East, and West wall faces.
  • Dynamic Field of View: Focal-length adjusted raycasting math to preserve proper block aspect ratios regardless of window dimensions.
  • Smooth Player Controls: Real-time movement (WASD) with wall collision padding and view rotation (Left/Right arrows).
  • Robust .cub Scene Parsing: Full validation of map closure, player spawn point, color boundaries, and texture file paths with explicit error reporting (Error\n...).

Instructions

Prerequisites

  • Operating System: Linux (X11 / XQuartz setup required for miniLibX)
  • Compiler: cc
  • Libraries: make, libXext, libX11, libm

Compilation

Clone the repository and compile the project using the provided Makefile:

# Compile the executable
make

# Clean object files
make clean

# Clean object files and binary
make fclean

# Rebuild the project completely
make re

Execution

Run cub3D by passing a valid .cub scene file as the single argument:

./cub3D maps/map.cub

Controls

Input Action
W Move Forward
S Move Backward
A Strafe Left
D Strafe Right
Left Arrow Rotate View Left
Right Arrow Rotate View Right
ESC Exit Game Cleanly
Red Cross (X) Close Window and Exit

Map Configuration Format (.cub)

Scene files must follow this format:

NO ./textures/north_wall.xpm
SO ./textures/south_wall.xpm
WE ./textures/west_wall.xpm
EA ./textures/east_wall.xpm

F 220,100,0
C 225,30,0

111111
100101
101001
1100N1
111111
  • Identifiers: NO, SO, WE, EA (Wall Texture Paths), F (Floor RGB), C (Ceiling RGB).
  • Map Characters:
    • 1: Wall
    • 0: Empty Walkable Space
    • N, S, E, W: Player Spawn position and facing orientation (North, South, East, West).

Resources

References & Documentation

AI Assistance Declaration

In accordance with Chapter IV (AI Instructions) of the 42 curriculum:

  • Code Optimization & Diagnostics: AI was used to diagnose perspective rendering issues (wall aspect ratio / focal length formula adjustments for square window dimensions).
  • Documentation: AI assisted in formatting and generating this README.md file in accordance with 42 curriculum requirements.
  • Code Review: AI was utilized as a pair-programming partner to audit error handling, memory safety, and evaluation requirements before defense submission.

About

This project is inspired by the world-famous Wolfenstein 3D game, which is considered the first FPS ever created. It will enable you to explore ray-casting. Your goal will be to make a dynamic view inside a maze, where you will have to find your way.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages