예제 #1
0
    ///////////////////////////////////////////////////////////////////////////

    public float[] CalculateLineOfSight(Vector3 eyepos, FogOfWarPlane plane)
    {
        if (LineOfSightMask == 0)
        {
            return(null);
        }

        if (_Distances == null)
        {
            _Distances = new float[256];
        }

        if (plane == FogOfWarPlane.XZ) // 3D
        {
            if (CalculateLineOfSight(eyepos, Radius, LineOfSightPenetration, LineOfSightMask, _Distances, Vector3.up, Vector3.forward))
            {
                return(_Distances);
            }
        }
        else if (plane == FogOfWarPlane.XY) // 3D
        {
            if (CalculateLineOfSight(eyepos, Radius, LineOfSightPenetration, LineOfSightMask, _Distances, Vector3.back, Vector3.up))
            {
                return(_Distances);
            }
        }
        return(null);
    }
예제 #2
0
    ///////////////////////////////////////////////////////////

    /// <summary>
    /// Sets fog map paramets.
    /// </summary>
    /// <param name="fogMan"></param>
    public void Set(FogManager fogMan)
    {
        Resolution    = fogMan.MapResolution;
        Size          = fogMan.MapSize;
        Offset        = fogMan.MapOffset;
        PixelSize     = Resolution.x / Size;
        PixelCount    = Resolution.x * Resolution.y;
        Plane         = fogMan.Plane;
        FilterMode    = fogMan.FilterMode;
        MultiThreaded = fogMan.MultiThreaded;
    }
예제 #3
0
        public FogOfWarShape GetShape(FogOfWar fow, FogOfWarPhysics physics, FogOfWarPlane plane)
        {
            FogOfWarShape shape = CreateShape(fow);

            if (shape == null)
            {
                return(null);
            }
            shape.lineOfSight  = CalculateLineOfSight(physics, shape.eyePosition, plane);
            shape.visibleCells = null;
            return(shape);
        }
예제 #4
0
 public void Set(FogOfWar fow)
 {
     resolution    = fow.mapResolution;
     size          = fow.mapSize;
     offset        = fow.mapOffset;
     pixelSize     = resolution.x / size;
     pixelCount    = resolution.x * resolution.y;
     plane         = fow.plane;
     physics       = fow.physics;
     filterMode    = fow.filterMode;
     multithreaded = fow.multithreaded;
 }
예제 #5
0
    ///////////////////////////////////////////////////////////////////////////

    /// <summary>
    /// Returns fog of war line of sight shape.
    /// </summary>
    /// <param name="fow"></param>
    /// <param name="plane"></param>
    /// <returns></returns>
    public FogShape GetShape(FogManager fow, FogOfWarPlane plane)
    {
        FogShape shape = CreateShape(fow);

        if (shape == null)
        {
            return(null);
        }

        shape.LineOfSight  = CalculateLineOfSight(shape.EyePosition, plane);
        shape.VisibleCells = null;
        return(shape);
    }
        public static Vector3 FogPlaneToWorld(float x, float y, float z, FogOfWarPlane plane)
        {
            if (plane == FogOfWarPlane.YZ)
            {
                return(new Vector3(z, x, y));
            }
            else if (plane == FogOfWarPlane.XZ)
            {
                return(new Vector3(x, z, y));
            }

            Debug.LogError("FogOfWarPlane is an invalid value!");
            return(Vector3.zero);
        }
        // gets a transform's forward direction on a fog plane
        public static Vector2 TransformFogPlaneForward(Transform transform, FogOfWarPlane plane)
        {
            if (plane == FogOfWarPlane.YZ)
            {
                return(new Vector2(transform.up.z, transform.up.y).normalized);
            }
            else if (plane == FogOfWarPlane.XZ)
            {
                return(new Vector2(transform.forward.x, transform.forward.z).normalized);
            }

            Debug.LogError("FogOfWarPlane is an invalid value!");
            return(Vector2.zero);
        }
        // converts world position to fog plane pos where x and y are on the plane
        public static Vector2 WorldToFogPlane(Vector3 position, FogOfWarPlane plane)
        {
            if (plane == FogOfWarPlane.YZ)
            {
                return(new Vector2(position.y, position.z));
            }
            else if (plane == FogOfWarPlane.XZ)
            {
                return(new Vector2(position.x, position.z));
            }

            Debug.LogError("FogOfWarPlane is an invalid value!");
            return(Vector2.zero);
        }
예제 #9
0
        public FogOfWarShape GetShape(FogOfWarPhysics physics, FogOfWarPlane plane)
        {
            FogOfWarShape shape = CreateShape();

            if (shape == null)
            {
                return(null);
            }

            if (cellBased)
            {
                shape.lineOfSight  = null;
                shape.visibleCells = CalculateLineOfSightCells(physics, shape.eyePosition);
            }
            else
            {
                shape.lineOfSight  = CalculateLineOfSight(physics, shape.eyePosition, plane);
                shape.visibleCells = null;
            }
            return(shape);
        }
예제 #10
0
        public float[] CalculateLineOfSight(FogOfWarPhysics physicsmode, Vector3 eyepos, FogOfWarPlane plane)
        {
            if (lineOfSightMask == 0)
            {
                return(null);
            }

            if (_distances == null)
            {
                _distances = new float[256];
            }

            if (physicsmode == FogOfWarPhysics.Physics2D)
            {
                if (CalculateLineOfSight2D(eyepos, radius, lineOfSightPenetration, lineOfSightMask, _distances))
                {
                    return(_distances);
                }
            }
            else if (plane == FogOfWarPlane.XZ) // 3D
            {
                if (CalculateLineOfSight3D(eyepos, radius, lineOfSightPenetration, lineOfSightMask, _distances, Vector3.up, Vector3.forward))
                {
                    return(_distances);
                }
            }
            else if (plane == FogOfWarPlane.XY) // 3D
            {
                if (CalculateLineOfSight3D(eyepos, radius, lineOfSightPenetration, lineOfSightMask, _distances, Vector3.back, Vector3.up))
                {
                    return(_distances);
                }
            }
            return(null);
        }
예제 #11
0
 public static Vector2 WorldToFog(Vector3 wpos, FogOfWarPlane plane, Vector2 offset, Vector2i resolution, float size)
 {
     return(WorldToFog(WorldToFogPlane(wpos, plane), offset, resolution, size));
 }
예제 #12
0
        public float[] CalculateLineOfSight(FogOfWarPhysics physicsmode, Vector3 eyepos, FogOfWarPlane plane)
        {
            if (lineOfSightMask == 0)
            {
                return(null);
            }

            if (_distances == null)
            {
                _distances = new float[256];
            }
            if (CalculateLineOfSight3D(eyepos, radius, lineOfSightPenetration, lineOfSightMask, _distances, Vector3.up, Vector3.forward))
            {
                return(_distances);
            }
            return(null);
        }
 public static Vector3 FogPlaneToWorld(Vector3 fpos, FogOfWarPlane plane)
 {
     return(FogPlaneToWorld(fpos.x, fpos.y, fpos.z, plane));
 }