/////////////////////////////////////////////////////////////////////////// bool LineOfSightCanSee(FogShape shape, Vector2 offset, float fogradius) { if (shape.LineOfSight == null) { return(true); } float idx = FogTools.ClockwiseAngle(Vector2.up, offset) * shape.LineOfSight.Length / 360.0f; if (idx < 0) { idx += shape.LineOfSight.Length; } // sampling float value; if (_Map.FilterMode == FilterMode.Point) { value = shape.LineOfSight[Mathf.RoundToInt(idx) % shape.LineOfSight.Length]; } else { int idxlow = Mathf.FloorToInt(idx); int idxhigh = (idxlow + 1) % shape.LineOfSight.Length; value = Mathf.LerpUnclamped(shape.LineOfSight[idxlow], shape.LineOfSight[idxhigh], idx % 1); } float dist = value * fogradius; return(offset.sqrMagnitude < dist * dist); }
// FUNCTIONS /////////////////////////////////////////////////////////////////////////// public DrawInfo(FogMap map, FogShape shape, float xradius, float yradius) { // convert size to fog space fogForward = shape.Forward; forwardAngle = FogTools.ClockwiseAngle(Vector2.up, fogForward) * Mathf.Deg2Rad; float sin = Mathf.Sin(-forwardAngle); float cos = Mathf.Cos(-forwardAngle); Vector2 relativeoffset = new Vector2(shape.Offset.x * cos - shape.Offset.y * sin, shape.Offset.x * sin + shape.Offset.y * cos); fogCenterPos = FogConversion.WorldToFog(FogConversion.WorldToFogPlane(shape.EyePosition, map.Plane) + relativeoffset, map.Offset, map.Resolution, map.Size); fogEyePos = new Vector2_1(FogConversion.WorldToFog(shape.EyePosition, map.Plane, map.Offset, map.Resolution, map.Size)); // find ranges if (shape.VisibleCells == null) { xMin = Mathf.Max(0, Mathf.RoundToInt(fogCenterPos.x - xradius)); xMax = Mathf.Min(map.Resolution.x - 1, Mathf.RoundToInt(fogCenterPos.x + xradius)); yMin = Mathf.Max(0, Mathf.RoundToInt(fogCenterPos.y - yradius)); yMax = Mathf.Min(map.Resolution.y - 1, Mathf.RoundToInt(fogCenterPos.y + yradius)); } else { fogCenterPos = FogConversion.SnapToNearestFogPixel(fogCenterPos); fogEyePos = new Vector2_1(FogConversion.SnapToNearestFogPixel(FogConversion.WorldToFog(shape.EyePosition, map.Offset, map.Resolution, map.Size))); Vector2_1 pos = new Vector2_1(Mathf.RoundToInt(fogCenterPos.x), Mathf.RoundToInt(fogCenterPos.y)); Vector2_1 rad = new Vector2_1(Mathf.RoundToInt(xradius), Mathf.RoundToInt(yradius)); xMin = Mathf.Max(0, Mathf.RoundToInt(pos.x - rad.x)); xMax = Mathf.Min(map.Resolution.x - 1, Mathf.RoundToInt(pos.x + rad.x)); yMin = Mathf.Max(0, Mathf.RoundToInt(pos.y - rad.y)); yMax = Mathf.Min(map.Resolution.y - 1, Mathf.RoundToInt(pos.y + rad.y)); } }