Git Product home page Git Product logo

raycaster's Introduction

Raycaster

Screen.Recording.2024-01-22.at.10.41.16.PM.mov

I really wanted to explore raycasting and some of the math behind it. So, I created this raycasting sandbox to experiment with it. On the left half of the screen, I have a top-down 2D view of the map with rays being casted from the player. On the right half, I implemented a 3D view of the scene using the euclidean distances I got from raycasting. The euclidean distances returned are converted to perpendicular distances with a bit of trignometry to get a less distorted image of the 3D space.

Movement and Keybindings

Movement is relative to the 2D top down view. To move around in the demo, use the WASD keys or the arrow keys. To rotate clockwise, use the F key or the Space key. To rotate counter-clockwise, use the G key.

Installation

Please install Golang 1.21 or higher. After doing so, either do go run main.go or go build main.go && ./main. The latter compiles the code into an executable and runs it. Note the above instructions should work on most MacOS and Linux machines.

Learnings

Using this much trignometry was quite fun, but it would have been easier to implement the caster with less of it it. To calculate the distance, we really only need to know how much the length of the ray increases whenever one of the components increases by 1. We can use this fact by determining which side the intersection occurs on, and, then, use the corresponding component. This might help reduce floating point errors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.