How does this bresenham code even work?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
prixt
Prole
Posts: 26
Joined: Sat Sep 12, 2015 5:53 am

How does this bresenham code even work?

Post 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.
marco.lizza
Citizen
Posts: 52
Joined: Wed Dec 23, 2015 4:03 pm

Re: How does this bresenham code even work?

Post 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?
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest