public static void Calculate3(IntVector3 viewerLocation, int visionRange, VisionMap visibilityMap, IntSize3 mapSize, Func<IntVector3, bool> blockerDelegate) { visibilityMap.Clear(); if (blockerDelegate(viewerLocation) == true) return; var g = new IntGrid3(new IntVector3(), mapSize); g = g.Offset(-viewerLocation.X, -viewerLocation.Y, -viewerLocation.Z); var vr = new IntVector3(visionRange, visionRange, visionRange); g = g.Intersect(new IntGrid3(vr, -vr)); int visionRangeSquared = (visionRange + 1) * (visionRange + 1); // +1 to get a bit bigger view area foreach (var dst in g.Range()) { if (dst.LengthSquared > visionRangeSquared) continue; bool vis = FindLos3(viewerLocation, dst, blockerDelegate); visibilityMap[dst] = vis; // XXX Cheat a bit so that the floor will be visible if (vis && dst.Z == 0 && viewerLocation.Z > 1) { visibilityMap[dst.SetZ(dst.Z - 1)] = true; } } }
public static void Calculate3(IntVector3 viewerLocation, int visionRange, VisionMap visibilityMap, IntSize3 mapSize, Func <IntVector3, bool> blockerDelegate) { visibilityMap.Clear(); if (blockerDelegate(viewerLocation) == true) { return; } var g = new IntGrid3(new IntVector3(), mapSize); g = g.Offset(-viewerLocation.X, -viewerLocation.Y, -viewerLocation.Z); var vr = new IntVector3(visionRange, visionRange, visionRange); g = g.Intersect(new IntGrid3(vr, -vr)); int visionRangeSquared = (visionRange + 1) * (visionRange + 1); // +1 to get a bit bigger view area foreach (var dst in g.Range()) { if (dst.LengthSquared > visionRangeSquared) { continue; } bool vis = FindLos3(viewerLocation, dst, blockerDelegate); visibilityMap[dst] = vis; // XXX Cheat a bit so that the floor will be visible if (vis && dst.Z == 0 && viewerLocation.Z > 1) { visibilityMap[dst.SetZ(dst.Z - 1)] = true; } } }