Jump to content

  • Log In with Google      Sign In   
  • Create Account


Scienthsine

Member Since 25 Sep 2008
Offline Last Active Sep 25 2012 09:16 AM

#4982969 How to get the number of solid tiles between two points?

Posted by Scienthsine on 23 September 2012 - 11:14 AM

The picture actually looks like it's using Bresenham's algorithm. Notice how it favors one axis (Y) over the other (X)? Even though the actual line covers some tiles by almost half, they aren't in red, while others are barely covered and are in red. It's iterating over Y with error accumulation in X.u

Basically forget the pixel level of it all. Your creating a line between two tiles. Using Bresenhams algorithm over the tiles is the same as using it over pixels.

Now, as others have said, if your really just wanting 'the number of solid tiles between two points' and your counting the tiles in red in the photo, then it is just the greater of the absolute of the difference in Y or X. (As defined by the outer loop in the algorithm.)


PARTNERS