I have been looking at Line of Sight algorithms in between all the Christmas preparations. There are currently two options that are looking interesting.
The first algorithm is FOV using recursive shadowcasting by Björn Bergström. The article is presented in an easy to read format and the demo application shows exactly the kind of behaviour I’m looking for.
I’ll probably first do a direct port of the code to c# and then look at rewriting it from scratch. I don’t know why, but that’s how I like to learn new things. I might do another article series if I get inspired.
The second algorithm is something I spotted on r.g.r.d. in the following thread by C Miller. This article is titled Modelling Rays for Line of Sight in an Object-Rich World. Again the algorithm is set out in a understandable manner and the source code provided (java) is simple to convert to c#.
In fact, I’ve already done an implementation using this algorithm. I’ve got my little @ running around on maps generated using the random dungeon generation code.
Out the box the algorithm works fine except for a few tiles that are being displayed even though they shouldn’t be visible. I don’t think that its a problem with the algorithm itself, but rather that I’m not interpreting the results correctly.
I’ll get back to this once I’ve implemented the shadowcasting algorithm. I might design the code so that I can easily swap out the two algorithms, but I’m not sure I’ll ever need too.
In the mean time. Merry Christmas.