Skip to content

A C++ and SDL2 raycasting engine inspired by Wolfenstein 3D

License

Notifications You must be signed in to change notification settings

Axl-91/raycaster

Repository files navigation

Raycaster

A C++ and SDL2 raycasting engine inspired by Wolfenstein 3D.

Status

Under active development.

Documentation and refactorings are in progress...

Requirements

  • C++11 compatible compiler
  • SDL2
  • SDL2_image
  • YAML-CPP
  • CMake

Install dependencies

sudo dnf install gcc-c++ cmake SDL2-devel SDL2_image-devel yaml-cpp-devel

Tutorial Path

Steps

  1. Player Movement: Initialize SDL project, create the player class, and implement basic movement and rotation controls
  2. Map Implementation: Create a 2D map system and implement collision detection to prevent walking through walls
  3. Basic Raycasting: Implement the raycasting algorithm - casting rays across the field of view to detect walls
  4. Raycasting Walls: Transform ray distances into 3D wall rendering, apply fisheye correction, and add directional shading for depth
  5. Textured Walls: Replace flat-colored walls with textures, implement texture sampling per ray, and align textures correctly on vertical and horizontal hits.
  6. Rendering Objects: Render sprites (objects) in the world, handle perspective scaling, visibility checks, and correct occlusion against walls.

Complete Implementation

Full Implementation: Fully-featured raycaster with HUD, weapons, and shooting mechanics. Use as reference or starting point for your own game.

Build and Run

# BUILD 
cmake -S . -B build
cd build
make

# RUN
./main

For a Debug build

cmake -S . -B build -DCMAKE_BUILD_TYPE=Debug

About

This is a recreational, step-by-step raycasting project.

The goal of this project is to learn and understand raycasting by building it gradually, experimenting with the math, and visualizing how each part of the algorithm works.

What is Raycasting?

Raycasting is a rendering technique that simulates 3D perspective by:

  1. Casting rays from the player's position
  2. Detecting wall intersections
  3. Drawing vertical slices based on distance
  4. Creating the illusion of 3D depth

Raycasting Bible

Triangle

Formulas


Wolf3D

About

A C++ and SDL2 raycasting engine inspired by Wolfenstein 3D

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published