Exemplo n.º 1
0
 public void init(USlippyTile t, UPlayer p)
 {
     tile   = t;
     player = p;
     parser = new OSMParser(tile);
     parser.Start();
 }
Exemplo n.º 2
0
    public void set(GCS p, int _zoom)
    {
        USlippyTile a = GCS2Slippy(p, _zoom);

        x    = a.x;
        y    = a.y;
        zoom = _zoom;
    }
Exemplo n.º 3
0
 /// <summary>
 /// Returns an array with a heightmap on it
 /// </summary>
 /// <param name="tile">tile x, y and zoom</param>
 /// <returns></returns>
 public static byte[] getByteHeight(USlippyTile tile)
 {
     byte[] pngData;
     using (WebClient client = new WebClient())
     {
         string url = tile.getMapzenURLTerranium(UVariables.mapzenAPIKey);
         pngData = client.DownloadData(url);
     }
     return(pngData);
 }
Exemplo n.º 4
0
    public static GCS Slippy2GCS(USlippyTile tile)
    {
        GCS    p = new GCS();
        double n = Math.PI - ((2.0 * Math.PI * tile.y) / Math.Pow(2.0, tile.zoom));

        p.lon = (float)((tile.x / Math.Pow(2.0, tile.zoom) * 360.0) - 180.0);
        p.lat = (float)(180.0 / Math.PI * Math.Atan(Math.Sinh(n)));

        return(p);
    }
Exemplo n.º 5
0
 /// <summary>
 /// Returns an array with a heightmap on it
 /// </summary>
 /// <param name="tile">tile x, y and zoom</param>
 /// <returns></returns>
 public static byte[] getByteHeight(USlippyTile tile)
 {
     byte[] pngData;
     using (WebClient client = new WebClient())
     {
         string url = tile.getMapzenURLTerranium(UVariables.mapzenAPIKey);
         ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
         pngData = client.DownloadData(url);
     }
     return(pngData);
 }
Exemplo n.º 6
0
    /// <summary>
    /// Calculates the north-east (top-left) GCS minLat and maxLat
    /// to get the maxLat and maxLon of the current chunk
    /// </summary>
    public GCS getNorthEastGCS()
    {
        USlippyTile result = new USlippyTile(x, y, zoom);

        result.x += 1;
        result.y -= 1;
        if (result.x < 0 || result.y < 0)
        {
            return(null);
        }
        return(result.getGCS());
    }
Exemplo n.º 7
0
    void Update()
    {
        if (_clearHashMap)
        {
            clearHashMap();
            _clearHashMap = false;
        }

        if (playerIsInNewChunk())
        {
            /// chunk Position
            int x = UMaths.scaledFloor(chunkSize, transform.position.x);
            int y = UMaths.scaledFloor(chunkSize, transform.position.z);

            /// chunk number in the world starting from world position 0,0
            int xNum = (int)(x / chunkSize);
            int yNum = (int)(y / chunkSize);

            /// starting tile
            // Only for debug
            startTile = new USlippyTile(startLon, startLat, zoom);

            /// sapwn all the new needed chunks
            for (int i = -chunkAdjacentLayers; i <= chunkAdjacentLayers; i++)
            {
                for (int j = -chunkAdjacentLayers; j <= chunkAdjacentLayers; j++)
                {
                    USlippyTile sTile = new USlippyTile(xNum + i + startTile.x, yNum + j + startTile.y, zoom);

                    /// This line fix that world is flipped upside down
                    sTile.y = startTile.y + (startTile.y - sTile.y);

                    string key = genTerrainName(sTile.x, sTile.y);
                    if (!map.ContainsKey(key))
                    {
                        GameObject t = createTerrain(sTile, key);

                        Vector3 pos = new Vector3();
                        pos.Set(x + (i * chunkSize), 0, y + (j * chunkSize));
                        t.transform.position = pos;

                        map.Add(key, t);
                    }
                }
            }
            /// after spawning the new chunks, remove the olders that we dont need
            removeResidualChunks();
        }
    }
Exemplo n.º 8
0
    /// <summary>
    /// Returns a Texture2D with a heightmap on it
    /// </summary>
    /// <param name="tile">tile x, y and zoom</param>
    /// <returns></returns>
    public static Texture2D getHeight(USlippyTile tile)
    {
        Texture2D tex;

        using (WebClient client = new WebClient())
        {
            string url = tile.getMapzenURLTerranium(UVariables.mapzenAPIKey);
            ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;
            byte[] pngData = client.DownloadData(url);

            tex = new Texture2D(256, 256);
            tex.LoadImage(pngData);
            tex.Apply();
        }

        return(tex);
    }
Exemplo n.º 9
0
    /// <summary>
    /// Uses the OpenStreetMap API to get the desired data in a latitude and longitude bounds.
    /// </summary>
    /// <param name="tile">tile x, y and zoom</param>
    /// <returns>An XML with the OSM data</returns>
    public static XmlDocument getOSMXML(USlippyTile tile)
    {
        XmlDocument xml = new XmlDocument();

        using (WebClient client = new WebClient())
        {
            //tile.y
            USlippyTile copy = new USlippyTile(tile.x, tile.y, tile.zoom);
            copy.y += 1;
            GCS gcs = copy.getGCS();
            /// North-East USlippyTile's GCS
            GCS gcsNE = copy.getNorthEastGCS();
            //              # LefttLon #LowLat   #RightLon #HiLat
            //chunkLimits = [2.13078,  41.48236, 2.13454,  41.48593]
            string url = OSMApiCall + gcs.lon + "," + gcs.lat + "," + gcsNE.lon + "," + gcsNE.lat;
            xml.LoadXml(client.DownloadString(url));
        }
        return(xml);
    }
Exemplo n.º 10
0
    public GameObject createTerrain(USlippyTile tile, string key)
    {
        GameObject t = new GameObject(key);

        if (genTerrain)
        {
            /// crete the TerrainData
            TerrainData tData = new TerrainData();
            tData.size = new Vector3(chunkSize / 8, 0, chunkSize / 8); // don't know why 8, but terrain its 8 times bigger than this numbers

            /// add the terrain Collider and the Terrain based in the TerrainData
            TerrainCollider tColliderComp = t.AddComponent <TerrainCollider>();
            Terrain         tComp         = t.AddComponent <Terrain>();
            tColliderComp.terrainData = tData;
            tComp.terrainData         = tData;

            /// change the terrain material
            tComp.materialType = Terrain.MaterialType.BuiltInLegacySpecular;

            /// create and init the UTerrain that will load the height data
            UTerrain uTerrain = t.AddComponent <UTerrain>();
            uTerrain.init(tile, this);
        }

        if (genOSM)
        {
            /// create and init the UTerrain that will load the height data
            OSMChunk osmChunk = t.AddComponent <OSMChunk>();
            osmChunk.init(tile, this);
        }

        if (genOSM && debugOSM)
        {
            /// only for debug visualization
            OSMDebug visualization = t.AddComponent <OSMDebug>();
        }

        //t.AddComponent<AssignSplatMap>();

        return(t);
    }
Exemplo n.º 11
0
 public UTerrainLoader(USlippyTile t)
 {
     tile = t;
 }
Exemplo n.º 12
0
 public void init()
 {
     startTile = new USlippyTile(startLon, startLat, zoom);
     clearHashMap();
 }
Exemplo n.º 13
0
 public void init(USlippyTile t, UPlayer p)
 {
     tile   = t;
     player = p;
 }
Exemplo n.º 14
0
    /*public void load(string rawData)
     * {
     *  xmlData.LoadXml(rawData);
     * }*/

    public OSMParser(USlippyTile t)
    {
        tile = t;
    }