Documents

Raycasting Logic: From 2D Map to 3D View

Our engine takes a simple 2D grid-based map and transforms it into an immersive 3D perspective using a raycasting algorithm. For each vertical column of the screen, the engine casts a ray from the player’s position into the map, calculating its path until it hits a wall. By measuring the distance each ray travels, we determine the height of the corresponding vertical stripe on the screen—closer walls appear taller while distant walls appear shorter. This process repeats for every column, creating the illusion of a three-dimensional environment from a flat 2D layout, allowing players to navigate and explore the world in real time.

Challenges: Overcoming the Hardest Bug

One of the most challenging bugs I faced while programming in C was the infamous “fisheye effect” in our raycasting engine. Initially, the walls near the edges of the screen appeared stretched or distorted, giving a warped perspective that broke immersion. This happened because rays were being projected directly onto the screen without correcting for the player’s viewing angle. To fix it, I had to calculate the perpendicular distance from the player to the wall for each ray, rather than using the direct distance along the ray. This small but crucial adjustment eliminated the fisheye distortion, producing a realistic and consistent 3D perspective. Debugging this issue taught me the importance of mathematical precision and careful vector