Gesticulations and Other Geekery » Page 'Ray casting in Scala'

Ray casting in Scala

Ray casting is an old rendering technique used in early “3D” games like Wolfenstein 3D. Today it is nothing much, but implementing it will test your knowledge of trig and binary rounding issues. The real reason I wrote it though was because I have tried to implment a raycasting engine several times before and failed. Until now! So it was a matter of geek pride to go back to this problem and defeat it.

I implemented the engine in as functional a way as possible. I think it came out fairly well. I did not optimize anything for performance. So I used Double values for the most part. This is very different than most implementations you see online that implement the entire algorithm with ints and use look up tables for the trig functions. One issue that I had run into before is that because parts of the algorithm are fundamentally quantized (the map cells) floating point can actually cause problems like disappearing walls or holes in walls. I was able to work around these issues through the creative use of rounding and a fudge factor (to make sure the value was on the correct side of a boundry). Regardless it works now and I’m glad I defeated the algorithm.

The project is available in github:

Posted in Scala

One comment to “Ray casting in Scala”

Leave a comment