Raycasting Engine

GitHub →

Raycasting was used in early video games to create the illusion of 3D while using a 2D world. I was interested in this implementation, so I decided to build my own engine to explore how it worked.

I used Processing as a platform to explore the mechanics of a raycaster without having to build basic graphics components from scratch. A year later, I (separately) built a 2D/3D graphics engine from scratch.

An early version is shown here: An early version of the program

The implementation of the engine is actually quite simple, consisting of four objects:
  • Main: handles setup, key inputs, and rendering of the final image
  • Boundary: allows defining boundaries (walls) between specified coordinate pairs
  • Ray: an “imaginary” object that is shot out from the Player in a range of angles, calculating distance to the nearest wall
  • Player: handles the Player’s movement, casting Rays to Boundaries and returning a list of walls to be rendered

The final product implements a top-down and first-person view to visualize what the program is doing. There are additional features, including a title screen, sound effects, and enemies that you can defeat. However, the algorithm and rendering technique remains the same.

A screenshot of the program