Page 1 of 1
How does this bresenham code even work?
Posted: Thu Feb 25, 2016 12:38 pm
by prixt
https://github.com/kikito/bresenham.lua ... senham.lua
I understand what the bresenham algorithm is and how it works, but I just cannot wrap my head around why this code actually works.
Re: How does this bresenham code even work?
Posted: Thu Feb 25, 2016 1:41 pm
by marco.lizza
This is, quite frankly, the Lua statement-to-statement adaptation of a standard implementation of the (integer based) Bresenham line algorithm.
The only difference from the line-plotting case is that you are calling a callback function to check for visibility occlusion and test whether the line from point (x0,y0) to point (x1,y1) do not cross any "wall".
By the way, I implemented a LOS algorithm in a very similar way.
What puzzles you the most?