Esempio n. 1
0
    void CreateShape(OSMBounds bounds)
    {
        vertices = new Vector3[(xSize + 1) * (zSize + 1)];
        FindMinMax(elevations);

        for (int i = 0, z = 0; z <= zSize; z++)
        {
            for (int x = 0; x <= xSize; x++)
            {
                vertices[i] = new Vector3((float)(bounds.terrainX + xstep * x), (float)(elevations[x, z] - minHeight), (float)(bounds.terrainY + zstep * z));
                i++;
            }
        }

        triangles = new int[xSize * zSize * 6];
        int vert = 0;
        int tris = 0;

        for (int z = 0; z < zSize; z++)
        {
            for (int x = 0; x < xSize; x++)
            {
                triangles[tris + 0] = vert + 0;
                triangles[tris + 1] = vert + xSize + 1;
                triangles[tris + 2] = vert + 1;
                triangles[tris + 3] = vert + 1;
                triangles[tris + 4] = vert + xSize + 1;
                triangles[tris + 5] = vert + xSize + 2;

                vert++;
                tris += 6;
            }
            vert++;
        }
    }
Esempio n. 2
0
        public static void SetUpBounds(OSMBounds bounds, double scale)
        {
            centreLatLon_ = new Vector2((float)(bounds.minlon + bounds.maxlon) / 2f, (float)(bounds.minlat + bounds.maxlat) / 2f);

            double lat     = Deg2rad(centreLatLon_.y);
            double radius  = WGS84EarthRadius(lat);
            double pradius = radius * Math.Cos(lat);

            double scaleX = scale * GameSizeGameCoordinates / Rad2deg(GameSizeMetres / pradius);
            double scaleY = scale * GameSizeGameCoordinates / Rad2deg(GameSizeMetres / radius);

            scale_ = new Vector2((float)scaleX, (float)scaleY);
        }
Esempio n. 3
0
 // Start is called before the first frame update
 public void OnMapLoaded(OSMBounds bounds)
 {
     mesh         = new Mesh();
     meshRenderer = GetComponent <MeshRenderer>();
     GetComponent <MeshFilter>().mesh = mesh;
     xSize = optimizer + 1;
     zSize = optimizer + 1;
     xstep = bounds.terrainXsize / optimizer;
     zstep = bounds.terrainYsize / optimizer;
     Interpolate(bounds);
     CreateShape(bounds);
     UpdateMesh();
 }
Esempio n. 4
0
    public MapNode(XmlNode node, OSMBounds bounds)
    {
        latitude  = GetAttribute <float>("lat", node.Attributes);
        id        = GetAttribute <long>("id", node.Attributes);
        longitude = GetAttribute <float>("lon", node.Attributes);

        X = MercatorProjection.lonToX(longitude);
        Y = MercatorProjection.latToY(latitude);

        XmlNodeList tags = node.SelectNodes("tag");

        foreach (XmlNode tag in tags)
        {
            string key = GetAttribute <string>("k", tag.Attributes);
            if (key == "natural")
            {
                isTree = true;
            }
        }
    }
Esempio n. 5
0
    double[,] GetElevation(OSMBounds bounds)
    {
        double maxX = bounds.maxLon;
        double minX = bounds.minLon;
        double maxY = bounds.maxLat;
        double minY = bounds.minLat;

        double deltaX = maxX - minX;
        double deltaY = maxY - minY;
        double stepX  = deltaX / optimizer;
        double stepY  = deltaY / optimizer;

        for (int x = 0; x <= optimizer + 1; x++)
        {
            Xs.Add(minX + stepX * x);
        }
        for (int y = 0; y <= optimizer + 1; y++)
        {
            Ys.Add(minY + stepY * y);
        }
        locationsJson = new LocationsJSON(Xs, Ys);
        return(locationsJson.elevations);
    }
Esempio n. 6
0
 void SetBounds(XmlNode boundsNode)
 {
     bounds = new OSMBounds(boundsNode, actualBounds); //todo change bounds from theoretical to actual
 }
Esempio n. 7
0
 void Interpolate(OSMBounds bounds)
 {
     elevations = GetElevation(bounds);
 }
Esempio n. 8
0
 void SetBounds(XmlNode xmlNode)
 {
     bounds = new OSMBounds(xmlNode);
 }