void DrawOnMap(string text, Vector3 position, int panelwidth)
        {
            Vector2  normalizedfogpos = (FogOfWarConversion.WorldToFogPlane(position, _fog.plane) - _fog.mapOffset) / _fog.mapSize + new Vector2(0.5f, 0.5f);
            Vector2i mappos           = new Vector2i(normalizedfogpos * (panelwidth - 20));

            GUI.Label(new Rect(10 + mappos.x - 10, Screen.height - mappos.y - 10, 20, 20), text);
        }
            public DrawInfo(FogOfWarMap map, FogOfWarShape shape, float xradius, float yradius)
            {
                // convert size to fog space
                fogForward   = shape.foward;
                forwardAngle = FogOfWarUtils.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 = FogOfWarConversion.WorldToFog(FogOfWarConversion.WorldToFogPlane(shape.eyePosition, map.plane) + relativeoffset, map.offset, map.resolution, map.size);
                fogEyePos    = new Vector2i(FogOfWarConversion.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 = FogOfWarConversion.SnapToNearestFogPixel(fogCenterPos);
                    fogEyePos    = new Vector2i(FogOfWarConversion.SnapToNearestFogPixel(FogOfWarConversion.WorldToFog(shape.eyePosition, map.offset, map.resolution, map.size)));

                    Vector2i pos = new Vector2i(Mathf.RoundToInt(fogCenterPos.x), Mathf.RoundToInt(fogCenterPos.y));
                    Vector2i rad = new Vector2i(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));
                }
            }
Beispiel #3
0
        // Converts a world position to a fog pixel position. Values will be between 0 and mapResolution.
        public Vector2i WorldPositionToFogPosition(Vector3 position)
        {
            Vector2 fogplanepos = FogOfWarConversion.WorldToFogPlane(position, plane);
            Vector2 mappos      = FogOfWarConversion.WorldToFog(fogplanepos, mapOffset, mapResolution, mapSize);

            return(new Vector2i(mappos));
        }
Beispiel #4
0
        public Vector2i WorldPositionToFogPosition(Vector3 position)
        {
            Vector2 mappos = FogOfWarConversion.WorldToFogPlane(position, plane) - mapOffset;

            mappos.Scale(mapResolution.vector2 / mapSize);

            Vector2i mapposi = new Vector2i(mappos);

            mapposi += new Vector2i(mapResolution.x >> 1, mapResolution.y >> 1);
            return(mapposi);
        }
            public DrawInfo(FogOfWarMap map, FogOfWarShape shape)
            {
                // convert size to fog space
                Vector2 radius = shape.CalculateRadius() * map.pixelSize;

                fogForward = shape.foward;
                Vector2 relativeoffset;

                if (shape.absoluteOffset)
                {
                    forwardAngle   = 0;
                    relativeoffset = shape.offset;
                }
                else
                {
                    forwardAngle = FogOfWarUtils.ClockwiseAngle(Vector2.up, fogForward) * Mathf.Deg2Rad;
                    float sin = Mathf.Sin(-forwardAngle);
                    float cos = Mathf.Cos(-forwardAngle);
                    relativeoffset = new Vector2(shape.offset.x * cos - shape.offset.y * sin, shape.offset.x * sin + shape.offset.y * cos);
                }

                fogCenterPos = FogOfWarConversion.WorldToFog(FogOfWarConversion.WorldToFogPlane(shape.eyePosition, map.plane) + relativeoffset, map.offset, map.resolution, map.size);
                fogEyePos    = FogOfWarConversion.WorldToFog(shape.eyePosition, map.plane, map.offset, map.resolution, map.size).ToInt();

                // find ranges
                if (shape.visibleCells == null)
                {
                    xMin = Mathf.Max(0, Mathf.RoundToInt(fogCenterPos.x - radius.x));
                    xMax = Mathf.Min(map.resolution.x - 1, Mathf.RoundToInt(fogCenterPos.x + radius.x));
                    yMin = Mathf.Max(0, Mathf.RoundToInt(fogCenterPos.y - radius.y));
                    yMax = Mathf.Min(map.resolution.y - 1, Mathf.RoundToInt(fogCenterPos.y + radius.y));
                }
                else
                {
                    fogCenterPos = FogOfWarConversion.SnapToNearestFogPixel(fogCenterPos);
                    fogEyePos    = FogOfWarConversion.SnapToNearestFogPixel(FogOfWarConversion.WorldToFog(shape.eyePosition, map.offset, map.resolution, map.size)).ToInt();

                    Vector2Int pos = fogCenterPos.ToInt();
                    Vector2Int rad = radius.ToInt();
                    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));
                }
            }
 void FillShape(FogOfWarShape shape)
 {
     if (antiFlicker)
     {
         // snap to nearest fog pixel
         shape.eyePosition = FogOfWarConversion.SnapWorldPositionToNearestFogPixel(FogOfWarConversion.WorldToFogPlane(_transform.position, FogOfWar.current.plane), FogOfWar.current.mapOffset, FogOfWar.current.mapResolution, FogOfWar.current.mapSize);
         shape.eyePosition = FogOfWarConversion.FogPlaneToWorld(shape.eyePosition.x, shape.eyePosition.y, _transform.position.y, FogOfWar.current.plane);
     }
     else
     {
         shape.eyePosition = _transform.position;
     }
     shape.foward = _transform.forward;
     shape.offset = offset;
     shape.radius = radius;
 }
Beispiel #7
0
 void FillShape(FogOfWar fow, FogOfWarShape shape)
 {
     if (antiFlicker)
     {
         // snap to nearest fog pixel
         shape.eyePosition = FogOfWarConversion.SnapWorldPositionToNearestFogPixel(fow, FogOfWarConversion.WorldToFogPlane(_transform.position, fow.plane), fow.mapOffset, fow.mapResolution, fow.mapSize);
         shape.eyePosition = FogOfWarConversion.FogPlaneToWorld(shape.eyePosition.x, shape.eyePosition.y, _transform.position.y, fow.plane);
     }
     else
     {
         shape.eyePosition = _transform.position;
     }
     shape.brightness     = brightness;
     shape.foward         = FogOfWarConversion.TransformFogPlaneForward(_transform, fow.plane);
     shape.absoluteOffset = absoluteOffset;
     shape.offset         = offset;
     shape.radius         = circleRadius;
     shape.size           = boxSize;
 }