WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

kingkururu/raycast_test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Raycasting Demo Piece

A simulated 3D graphics demo built with C++ and SFML, showcasing raycasting techniques for creating pseudo-3D environments from 2D map data. This demo explores the fundamental graphics rendering approach used in classic games like Doom and Wolfenstein 3D.

Image

Features

  • Raycasting Engine: Renders 3D-looking environments from 2D tile maps
  • Player Movement: W and S keys for forward/backward
  • Camera Rotation: A and D keys for left/right view rotation
  • Distance-Based Rendering: Walls appear taller when closer, shorter when farther
  • Fisheye Correction: Geometric accuracy using trigonometric functions
  • Collision Detection: Player restricted to walkable black tiles
  • Mini-Map Visualization: Real-time representation of player position and rays
  • Performance Optimized: Efficient ray casting with boundary collision

Technical Implementation

Core Raycasting Algorithm

The raycasting system casts rays at regular intervals across the player's field of view to calculate distances to wall surfaces. Each ray's intersection with walls determines the height of vertical slices rendered on screen, creating a 3D perspective effect.

Key Components

  • Ray Casting: Measures distances to walls using trigonometric calculations
  • Vertical Slice Rendering: Draws walls as rectangles with heights based on distance
  • Fisheye Correction: Corrects distortion using cosine of angle between ray and viewing direction
  • Collision System: Integrated with tile-based map for movement restrictions
  • Map Visualization: Mini-map window showing real-time ray intersections

Graphics Rendering

  • Distance-Based Shading: Walls become darker with distance for depth illusion
  • Geometric Accuracy: Trigonometric functions ensure proper perspective
  • Boundary Detection: Rays stop at wall intersections for accurate measurements
  • View Frustum: Field of view calculations for realistic 3D projection

Project Structure

/raycast_test
│
├── src/                      # Source files
│   ├── main.cpp              # Main entry point of the game
│   └── game/                 # Core engine functionalities
│       ├── globals/          # Constants and flags
│       ├── core/             # Game loop and state management
│       ├── physics/          # Physics and collision detection
│       ├── camera/           # Window and view management
│       ├── utils/            # Utility functions
│       └── scenes/           # Scene management
│
├── assets/                   # Game assets
│   ├── fonts/                # Text files and sources
│   ├── sound/                # Sound effects
│   ├── tiles/                # Tiles and tilemaps
│   └── sprites/              # Sprite images
│
├── libs/                      # External libraries
│   └── logging/               # Logging system
│
├── Makefile                   # Build instructions
└── README.md                  # Project documentation

Prerequisites

  • Compiler: Requires clang++ (or g++) with C++17 support
  • SFML: Simple and Fast Multimedia Library for graphics and windowing
  • Custom Game Framework: Built on top of the SFML Game Framework

Building & Running

Installation

  1. Clone the Repository:

    git clone https://github.com/kingkururu/raycast_test
    cd raycast_test (location will be different)
  2. Build and Run the Demo:

    make test
  3. Clean the Build:

    make clean

Alternative Setup (macOS with Homebrew)

  1. Install SFML:

    # Install Homebrew if not already installed
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
    
    # Install SFML
    brew install sfml@2
    brew install .... (other missing libraries)
  2. Configure PATH (add to ~/.zshrc or ~/.bash_profile):

    export PATH="/opt/homebrew/bin:$PATH"
    export PATH="/opt/homebrew/opt/sfml@2/bin:$PATH"
    export PATH="path to other libraries if any of them is missing)

Raycasting Algorithm

The demo implements a raycasting system that:

  1. Casts rays at regular intervals across the player's field of view
  2. Calculates intersection points with wall tiles
  3. Measures distances to determine wall heights
  4. Applies fisheye correction for geometric accuracy
  5. Renders vertical slices with distance-based shading

Performance Optimizations

  • Boundary Optimization: Rays terminate at first wall intersection
  • Trigonometric Efficiency: Optimized angle calculations
  • Memory Management: Efficient tile map data structures
  • Render Culling: Only visible portions are rendered

Advanced Features

  • Real-time Ray Visualization: Mini-map shows active rays during casting
  • Distance-Based Shading: Walls darken with distance for depth perception
  • Smooth Movement: Collision detection allows fluid player movement
  • Geometric Accuracy: Proper trigonometric calculations for realistic perspective
  • Optimized Rendering: Efficient algorithms for real-time performance

Tools Used

Assets Credits

About

Raycast demo for 3D simulation using SFML and C++

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published