2

So, I have a 2d hex grid, where each hex is either a wall or a path, and I'd like to implement line-of-sight (in the sense of "a hex is visible from another hex if you can draw a straight line from any part of the start hex to any part of the end hex without touching any wall hexes (where the edges and vertices of a hex are considered touching that hex)").

Raycasting from a single point in the starting hex is slow and inaccurate. I thought about raycasting from every vertex of the starting hex, but that is even slower, and there are cases where it still doesn't work (mainly on larger grids)

There ought to be an algorithm for doing this that is better. I mean, it's essentially "just" a floodfill with restrictions. Any suggestions?

TLW
  • 1,373
  • 9
  • 22
  • Eric Lippert wrote [a series of blog posts about this problem](http://blogs.msdn.com/b/ericlippert/archive/2011/12/12/shadowcasting-in-c-part-one.aspx), except with a square grid instead of a hex grid. It should point at a lot of useful resources and concepts for you. – Craig Gidney Dec 31 '14 at 16:39
  • this may be useful, Eric Lippert is worth following as he is a valuable resource. http://blogs.msdn.com/b/ericlippert/archive/2011/12/12/shadowcasting-in-c-part-one.aspx – Sorceri Dec 31 '14 at 16:41
  • @Strilanc Love it!! I recommend to everyone to follow Eric. – Sorceri Dec 31 '14 at 16:42
  • @Strilanc I've seen that before, thank you for linking for it, but it does not cover anywhere near the same problem. In particular, it assumes that you are in the center of whatever grid space you are in. If there is an expansion that covers "anywhere-to-anywhere" visibility, please elaborate! – TLW Dec 31 '14 at 18:12

0 Answers0