static private void SmoothPath(ref List <Vector2> path, Cell[,] maze) { for (int i = 0; i < path.Count; i++) { while (i + 2 < path.Count) { VisibilityRay ray = new VisibilityRay(path[i], path[i + 2]); if (!CollisionUtils.RayMapIntersectionTest(ray, maze)) { path.RemoveAt(i + 1); } else { break; } } } }
public static bool RayMapIntersectionTest(VisibilityRay ray, Cell[,] maze) { // TODO // Optimize testing only against the possible instersection cells instead of the whole maze. // Use the Bresenham Line-Drawing Algorithm to find de cells to check. // http://playtechs.blogspot.cz/2007/03/raytracing-on-grid.html foreach (Cell cell in maze) { if (ray.AabbAabbIntersectionTest(cell)) { if (ray.SatIntersectionTest(cell)) { return(true); } } } return(false); }