Skip to content

Y4SS3R3/Cub3d42

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

139 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

This project has been created as part of the 42 curriculum by ymassiou.

SpinRoam - 3D Ray-Caster Engine

Description

SpinRoam is a first-person perspective graphical engine built from scratch in C. Inspired by the 1992 classic Wolfenstein 3D, this project uses ray-casting principles to transform a 2D map into a dynamic 3D view. It focuses on the practical application of mathematics and trigonometry to create an efficient rendering system within a maze environment.

The engine is built using the miniLibX graphical library, handling window management, real-time events, and pixel-level manipulation.

Features

Mandatory Requirements

  • Ray-Casting Engine: Renders a "realistic" 3D view of a maze from a first-person perspective.
  • Wall Textures: Displays different textures based on wall orientation (North, South, East, West).
  • Environment Coloring: Configurable floor and ceiling colors parsed from the scene description.
  • Scene Parsing: Robust parsing of .cub files, including map validation (ensuring the map is closed/surrounded by walls) and texture/color configurations.
  • Smooth Controls: Real-time movement and rotation without input lag.

Bonus Features

  • Wall Collisions: Prevents the player from walking through walls by calculating potential coordinates before movement.
  • Minimap System: A real-time 2D overlay showing the player's position, orientation, and the surrounding environment.
  • Mouse Rotation: Allows the player to look around naturally using the mouse.
  • Animated Sprites: Integration of dynamic, animated objects within the 3D world to enhance the atmosphere.

Controls

Key Action
W, A, S, D Move and strafe through the maze
Left / Right Arrows Look left and right
Mouse Rotate the camera view
ESC Close the window and exit cleanly

Getting Started

Prerequisites

  • GCC compiler.
  • Standard C libraries.
  • miniLibX (X11 or Metal version depending on the OS).

Compilation

The project includes a Makefile with the following rules:

make          # Compiles the mandatory part
make bonus    # Compiles with bonus features
make clean    # Removes object files
make fclean   # Removes object files and the executable
make re       # Recompiles the project

Usage

Run the program by passing a valid scene description file as an argument:

./cub3D maps/maze.cub

Technical Highlights

  • Digital Differential Analysis (DDA): Efficient wall distance calculation to avoid the high cost of standard trigonometric functions per ray.

  • Texture Mapping: Precise mapping of 2D textures to 3D vertical strips by calculating the exact horizontal offset on the wall during intersection.

  • Mathematical Foundation: Heavy reliance on trigonometry for handling player rotation, field-of-view (FOV) casting, and movement vectors.

  • Event Handling: Implementation of non-blocking key hooks and mouse tracking for a seamless user experience.

Resources

Releases

No releases published

Packages

 
 
 

Contributors