Skip to content

michmos/raycaster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

89 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

raycaster

cub3d1-ezgif com-optimize(1)cub3d2-ezgif com-optimize

About

This project is the 42 project cub3d. The goal of this project is to build a raycasting engine inspired by Wolfenstein 3D, rendering a first-person view of a maze from a 2D map. The program reads a .cub configuration file defining textures, colors, and the map layout, then uses DDA raycasting to project textured 3D walls in real-time.

Features

  • Raycasting with DDA (Digital Differential Analyzer) algorithm for grid intersection detection
  • Textured walls (4 directional textures: NO, SO, WE, EA)
  • Graphics via MLX42
  • Configurable floor & ceiling colors (RGB)
  • Smooth movement (WASD) and rotation (arrow keys)
  • Collision system with configurable hitbox
  • Distance-based shading for depth effectPlan
  • Real-time minimap
  • Robust .cub file parsing with descriptive error messages

Algorithm

Raycasting is a pipeline of trigonometry problems solved for each of the 1024 vertical screen columns for each frame:

  1. DDA: find the closest ray intersection with a wall
  2. Fish-eye correction: compute the actual distance to remove the spherical distortion
  3. Wall-height scaling: compute the wall height based on the distance of the wall
  4. Texture selection: select the correct texture (N/S/E/W) based on the intersection and the viewing angle
  5. Texture slicing: scale the texture to fill the wall
  6. Shading: darken rgba of computed pixel based on the distance

Utilization

  1. Cloning:

    git clone https://github.com/michmos/raycaster.git && cd raycaster && make
  2. Running: Run the executable with a .cub map file as argument:

    ./cub3d maps/all_walls.cub
    

    Choose any map from the maps/ directory or create your own.

  3. Controls:

    Key Action
    W/A/S/D Move forward / strafe left / backward / strafe right
    ← → Rotate view left / right
    ESC Quit the game

About

raycasting engine using DDA

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors