// Update is called once per frame
    void Update()
    {
        RaycastHit hit;
        Vector3 rayPosition = new Vector3(transform.position.x, 10000, transform.position.z);
        if (Physics.Raycast(rayPosition, -Vector3.up, out hit)) {
            transform.position = new Vector3(transform.position.x, hit.point.y+1f, transform.position.z);
        }

        GeoUTMConverter gc = new GeoUTMConverter();
        gc.ToLatLon (initialX + x, initialZ + z, localzone, GeoUTMConverter.Hemisphere.Northern);
        fakeLat = gc.Latitude;
        fakeLon = gc.Longitude;

        if (Input.GetKey(KeyCode.W)) {
            rigidbody.AddForce(100 * transform.forward);
        }
        if (Input.GetKey(KeyCode.S)) {
            rigidbody.AddForce(10 * -transform.forward);
        }
        if (Input.GetKey(KeyCode.A)) {
            transform.eulerAngles = new Vector3(transform.eulerAngles.x,transform.eulerAngles.y-1f, transform.eulerAngles.z);
        }
        if (Input.GetKey(KeyCode.D)) {
            transform.eulerAngles = new Vector3(transform.eulerAngles.x,transform.eulerAngles.y+1f, transform.eulerAngles.z);
        }

        x = transform.position.x;
        z = transform.position.z;
    }
    void loadXML()
    {
        // DestroyObject(go);
        //if (done || !GetComponent<MapChunkManager>().isReady)
        //   return;
        PolyLine pl = new PolyLine("TESTINGTRACER");
        pl.heigth = 1;
        pl.width = 3;
        pl.material = Resources.Load("Materials/blinker") as Material;
        float offsetPositionX = GetComponent<MapChunkManager>().offsetX;
        float offsetPositionZ = GetComponent<MapChunkManager>().offsetZ;
        pl.SetOffset(offsetPositionX, offsetPositionZ);

        XmlDocument XMLFile = new XmlDocument();
        XMLFile.LoadXml(gpsLog.text);
        XmlNodeList coords = XMLFile.GetElementsByTagName("trkpt");
        List<Node> nodes = new List<Node>();
        GeoUTMConverter convertor;
        foreach (XmlNode coord in coords) {
            // coord.Attributes["lat"].Value
            // coord.Attributes["lon"].Value
            Node n = new Node();
            n.lat = double.Parse(coord.Attributes["lat"].Value);
            n.lon = double.Parse(coord.Attributes["lon"].Value);
            convertor = new GeoUTMConverter();
            convertor.ToUTM(n.lat,n.lon);
            n.northing = convertor.Y;
            n.easthing = convertor.X;
            nodes.Add(n);
        }

        for (int a = 0; a < nodes.Count -1; a++) {
            Node n = nodes[a];

            Vector3 position = new Vector3((float)(n.easthing - offsetPositionX), 99999, (float)(n.northing - offsetPositionZ));
            float baseHeight = 0;
            RaycastHit hit;

            if (Physics.Raycast(position, -Vector3.up, out hit, Mathf.Infinity)) {
                baseHeight = hit.point.y;
            }
            n.height = baseHeight + 1f;
            pl.Add(n);

        //            Debug.Log("Node is " + (float)(n.easthing - offsetPositionX) + "|" + (float)(n.northing - offsetPositionZ) + "|" + n.height);
        //            Color random = new Color(((float)n.easthing % 255) / 255f, ((float)n.northing % 255) / 255f, ((float)n.easthing % 255) / 255f);
        //            Debug.DrawLine(new Vector3((float)nodes[a].easthing - offsetPositionX, 200, (float)nodes[a].northing - offsetPositionZ), new Vector3((float)nodes[a + 1].easthing - offsetPositionX, 200, (float)nodes[a + 1].northing - offsetPositionZ), random,300);
        }

        //		foreach (Node node in nodes) {
        //			pl.Add (node);
        //		}
        GameObject go = new GameObject();
        go.transform.position = transform.position;
        pl.Close(go);
        done = true;
    }
 // Use this for initialization
 void Start()
 {
     GeoUTMConverter gc = new GeoUTMConverter();
     gc.ToUTM(initialFakeLat, initialFakeLon);
     initialX = (float)gc.X;
     initialZ = (float)gc.Y;
     RaycastHit hit;
     Vector3 rayPosition = new Vector3(0, 10000, 0);
     if (Physics.Raycast(rayPosition, -Vector3.up, out hit)) {
         transform.position = new Vector3(0, hit.point.y, 0);
     }
 }
    private void computeCorrectedSize(string minLon, string minLat, string maxLon, string maxLat)
    {
        GeoUTMConverter bl = new GeoUTMConverter();
        bl.ToUTM(double.Parse(minLat),double.Parse(minLon));

        GeoUTMConverter tr = new GeoUTMConverter();
        tr.ToUTM(double.Parse(maxLat), double.Parse(maxLon));

        double width = tr.X - bl.X;
        double heigth = tr.Y - bl.Y;

        Debug.Log("W " + width + " H " + heigth );

        mq_computedSize = (int)(mq_defaultSize * (width / heigth));
    }
Example #5
0
    // Use this for initialization
    public void Start()
    {
        Input.compass.enabled = true;
        playerConverter = new GeoUTMConverter();
        transform.position = new Vector3(0,20,0);
        if(Settings.useGPS)
        {
            Input.location.Start();
        }
        else
        {
            if(Settings.startLat != 0 && Settings.startLon != 0)
            {
                initialFakeLat = Settings.startLat;
                initialFakeLon = Settings.startLon;
            }
            playerConverter.ToUTM(initialFakeLat,initialFakeLon);
            x = (float)(playerConverter.X / GeoUTMConverter.Precision);
            z = (float)(playerConverter.Y / GeoUTMConverter.Precision);
            zone = (int)playerConverter.Zone;

        }
    }
Example #6
0
    public MapManager(XmlDocument XMLFile)
    {
        XmlNode node = XMLFile["osm"];
        Debug.Log(node.InnerText);

        nm = new NodeManager();
        nodes = new List<Node>();
        ways = new List<Way>();
        trees = new List<Node>();

        // How to traverse nodes in the file
        // (this loops over just the declaration and the root, since they are the only
        // two top-level children of the XmlDocument object)
        foreach (XmlElement cnode in node.ChildNodes)
        {

            if(cnode.LocalName == "node")
            {
                Node tempNode = new Node();
                tempNode.id = long.Parse(cnode.GetAttribute("id"));

                tempNode.changeset = long.Parse(cnode.GetAttribute("changeset"));

                tempNode.lat = double.Parse(cnode.GetAttribute("lat"));

                tempNode.lon = double.Parse(cnode.GetAttribute("lon"));

                tempNode.timestamp = cnode.GetAttribute("timestamp");

                tempNode.uid = long.Parse(cnode.GetAttribute("uid"));

                tempNode.user = cnode.GetAttribute("user");

                tempNode.version = int.Parse(cnode.GetAttribute("version"));

                convertor = new GeoUTMConverter();

                convertor.ToUTM(tempNode.lat,tempNode.lon);

                tempNode.northing = convertor.Y;

                tempNode.easthing = convertor.X;

                XmlNode xmlNode = cnode as XmlNode;

                foreach (XmlElement xmlNodeRef in xmlNode.ChildNodes)
                {
                    if(xmlNodeRef.LocalName == "tag")
                    {
                        string key = xmlNodeRef.GetAttribute("k");
                        string value = xmlNodeRef.GetAttribute("v");

                        if (key.Contains("natural"))
                        {
                            if (value.Contains("tree"))
                            {
                                tempNode.type = NodeType.Tree;
                                trees.Add(tempNode);
                            }
                        }
                    }
                }

                nm.nodes[tempNode.id] = tempNode;

                nodes.Add(tempNode);
            }
            if(cnode.LocalName == "way")
            {
                GeoUTMConverter converter = new GeoUTMConverter();
                XmlNode xmlWay = cnode as XmlNode;
                Way tempWay = new Way();
                tempWay.type = WayType.Residential;
                tempWay.changeset = long.Parse(cnode.GetAttribute("changeset"));
                tempWay.id = long.Parse(cnode.GetAttribute("id"));
                tempWay.timestamp = cnode.GetAttribute("timestamp");
                tempWay.uid = long.Parse(cnode.GetAttribute("uid"));
                tempWay.user = cnode.GetAttribute("user");
                tempWay.version = int.Parse(cnode.GetAttribute("version"));

                bool toAdd = true;
                foreach (XmlElement xmlNodeRef in xmlWay.ChildNodes)
                {
                    if(xmlNodeRef.LocalName == "nd")
                    {
                        long nodeRef = long.Parse(xmlNodeRef.GetAttribute("ref"));
                        Node tempNode = nm.nodes[nodeRef];

                        tempWay.nodes.Add(tempNode);
                    }
                    if(xmlNodeRef.LocalName == "tag")
                    {
                        string key = xmlNodeRef.GetAttribute("k");
                        string value = xmlNodeRef.GetAttribute("v");
                        if(key.Contains("building"))
                        {
                            tempWay.type = WayType.Building;
                        }
                        if(key.Contains("amenity"))
                        {
                            if(value.Contains("parking"))
                                tempWay.type = WayType.Parking;
                        }
                        if(key.Contains ("landuse"))
                        {
                            if(value.Contains("grass"))
                            {
                                tempWay.type = WayType.Park;
                            }
                        }
                        if(key.Contains("highway"))
                        {
                            tempWay.type = WayType.Residential;
                            if(value.Contains("residential"))
                            {
                                tempWay.type = WayType.Residential;
                            }
                            else if(value.Contains("footway"))
                            {
                                tempWay.type = WayType.Footway;
                            }
                            else if(value.Contains("motorway"))
                            {
                                tempWay.type = WayType.Motorway;
                            }
                        }

                        if(key.Contains("leisure"))
                        {
                            if(value.Contains("park"))
                            {
                                tempWay.type = WayType.Park;
                            }
                        }
                        if(key.Contains("waterway"))
                        {
                            if(value.Contains("river"))
                                tempWay.type = WayType.River;
                            if (value.Contains("riverbank"))
                                tempWay.type = WayType.RiverBank;
                        }
                        if(key.Contains("bridge"))
                        {
                            tempWay.height += 3;
                        }
                        if(key.Contains("name"))
                        {
                            tempWay.name = value;
                        }
                        if(key.Contains("height"))
                        {
                            tempWay.height = int.Parse(Regex.Replace(value, "[^-,.0-9]", "")); // Remove everything non-numeric
                        }
                        if(key.Contains("area"))
                        {
                            toAdd = false;
                        }
                        if(key.Contains ("natural"))
                        {
                            if (value.Contains("water"))
                                tempWay.type = WayType.RiverBank;
                        }
                    }

                }

                if(toAdd)
                ways.Add(tempWay);
            }
        }
    }
Example #7
0
    // Use this for initialization
    IEnumerator Start()
    {
        layerMask = 1 << 8;
        wayList = new List<long>();
        //StartCoroutine(LoadChunk(-8.6f,41.1767f,-8.55f,41.1923f));
        MapChunkLoader.precision = GeoUTMConverter.Precision;
        GeoUTMConverter latlon2Utm = new GeoUTMConverter();
        latlon2Utm.ToUTM((minimumLat+maximumLat)/2f,(minimumLon+maximumLon)/2f);

        transform.position = new Vector3(((float)latlon2Utm.X - offsetPositionX), -0.1f, ((float)latlon2Utm.Y - offsetPositionZ));

        //GeoUTMConverter bottomLeft = new GeoUTMConverter();
        //GeoUTMConverter topRight = new GeoUTMConverter();
        //bottomLeft.ToUTM(minimumLat,minimumLon);
        //topRight.ToUTM(maximumLat,maximumLon);
        GameObject floor = new GameObject();
        floor.name = "Ground";
        floor.isStatic = true;
        /*GoogleElevation ge = new GoogleElevation();

        ge.coordinates.Add(minimumLat);
        ge.coordinates.Add(minimumLon);

        ge.coordinates.Add(minimumLat);
        ge.coordinates.Add(maximumLon);

        ge.coordinates.Add(maximumLat);
        ge.coordinates.Add(maximumLon);

        ge.coordinates.Add(maximumLat);
        ge.coordinates.Add(minimumLon);

        */
        //ge.SyncGetHeights();
        //yield return StartCoroutine(ge.GetHeights());

        //Mesh msh = CreateGroundWithHeights((float)(topRight.X-bottomLeft.X)/1.9f,(float)(topRight.Y-bottomLeft.Y)/1.9f,ge.heights);
        CreateGround cg = new CreateGround();
        cg.maxLat = maximumLat + 0.001f;
        cg.maxLon = maximumLon + 0.001f;
        cg.minLat = minimumLat - 0.001f;
        cg.minLon = minimumLon - 0.001f;
        cg.numberOfDivisions = numberOfDivisions;

        MeshFilter mf = floor.AddComponent<MeshFilter>();
        mf.mesh = cg.GetGroundMesh() ;
        MeshRenderer mr = floor.AddComponent<MeshRenderer>();
        mr.material = groundMaterial;
        floor.transform.position = transform.position;
        floor.transform.parent = transform;
        floor.layer = LayerMask.NameToLayer("RayCast");

        MeshCollider m = floor.AddComponent<MeshCollider>();

        yield return StartCoroutine(LoadChunk(minimumLon,minimumLat,maximumLon,maximumLat));
    }
Example #8
0
    void CreateVertexes()
    {
        GeoUTMConverter off = new GeoUTMConverter();

        vertexes = new List<Vector3>();
        for(int i = 0; i < coordinates.Count; i+=2)
        {
            GeoUTMConverter conv = new GeoUTMConverter();
            conv.ToUTM(coordinates[i], coordinates[i + 1]);
            vertexes.Add(new Vector3((float)(conv.X ), heigths[i / 2], (float)(conv.Y )));
        }
    }
    void LoadUnloadChunks()
    {
        player = currentPlayer.GetComponent<Player>();
        GeoUTMConverter conv = new GeoUTMConverter();
        conv.ToUTM(player.initialFakeLat,player.initialFakeLon);
        offsetX = (float)conv.X;
        offsetZ = (float)conv.Y;

        List<GameObject> newMapChunks = new List<GameObject>();

        for(int i = 0; i < mapChunks.Count; i++)
        {
            MapChunkLoader mc = mapChunks[i].GetComponent<MapChunkLoader>();
            mc.toUnload = true;
        }

        int centerLat = (int)((player.fakeLat - player.initialFakeLat) / chunkStep);
        int centerLon = (int)((player.fakeLon - player.initialFakeLon) / chunkStep);
        float newLat = (float)(player.initialFakeLat + (float)(centerLat*chunkStep));
        float newLon = (float)(player.initialFakeLon + (float)(centerLon*chunkStep));

        for (int a = -numChunks; a <= numChunks; a+=2)
        {
            for (int b = -numChunks; b <= numChunks; b+=2)
            {
                bool hasChunk = false;
                for(int i = 0; i < mapChunks.Count; i++)
                {
                    MapChunkLoader mc = mapChunks[i].GetComponent<MapChunkLoader>();
                    if (mc.Contains((float)(newLat + (b - 0.5f) * chunkStep), (float)(newLon + (a - 0.5f) * chunkStep)))
                    {
                        mc.toUnload = false;
                        hasChunk = true;
                        break;
                    }
                }
                if(!hasChunk)
                {
                    GameObject go = new GameObject();
                    go.name = "World Chunk";
                    go.isStatic = true;
                    MapChunkLoader mcl = go.AddComponent<MapChunkLoader>();
                    go.AddComponent<TaskExecutorScript>();
                    mcl.groundMaterial = groundMaterial;
                    mcl.buildingMaterial = buildingMaterial;
                    mcl.roadMaterial = roadMaterial;
                    mcl.mapManager = this;
                    mcl.treePrefab = treePrefab;
                    mcl.maximumLat = newLat + (b+1.0f)*chunkStep;
                    mcl.maximumLon = newLon + (a+1.0f)*chunkStep;
                    mcl.minimumLat = newLat + (b-1.0f)*chunkStep;
                    mcl.minimumLon = newLon + (a-1.0f)*chunkStep;
                    mcl.numberOfDivisions = numberOfDivisions;

                    mcl.offsetPositionX = offsetX;
                    mcl.offsetPositionZ = offsetZ;
                    go.transform.parent = this.transform;

                    newMapChunks.Add(go);
                }
            }
        }
        for(int i = 0; i < mapChunks.Count; i++)
        {
            MapChunkLoader mc = mapChunks[i].GetComponent<MapChunkLoader>();
            if(mc.toUnload)
            {
                for (int a = 0; a < mc.wayList.Count; a+=0)
                {
                    long item = mc.wayList[a];
                    if (mapHash.Remove(item) <= 0)
                    {
                        GameObject go = GameObject.Find(item.ToString());
                        Destroy(go);

                    }
                    mc.wayList.Remove(item);
                }

                if(mapChunks[i].transform.childCount == 1)
                {
                    Destroy(mapChunks[i]);
                    mapChunks.Remove(mapChunks[i]);

                }

            }
        }

        for(int i = 0; i < newMapChunks.Count; i++)
        {
            mapChunks.Add(newMapChunks[i]);
        }
    }
    // Use this for initialization
    IEnumerator Start()
    {
        Loom.Current.GetComponent<Loom>();
        layerMask = 1 << 8;
        wayList = new List<long>();
        //StartCoroutine(LoadChunk(-8.6f,41.1767f,-8.55f,41.1923f));
        MapChunkLoader.precision = GeoUTMConverter.Precision;
        GeoUTMConverter latlon2Utm = new GeoUTMConverter();
        latlon2Utm.ToUTM((minimumLat+maximumLat)/2f,(minimumLon+maximumLon)/2f);

        transform.position = new Vector3(((float)latlon2Utm.X - offsetPositionX), -0.1f, ((float)latlon2Utm.Y - offsetPositionZ));

        GameObject floor = new GameObject();
        floor.name = "Ground";
        floor.isStatic = true;

        CreateGround cg = new CreateGround();
        cg.maxLat = maximumLat + 0.01f * (maximumLat - minimumLat); //0.0001f;
        cg.maxLon = maximumLon + 0.01f * (maximumLat - minimumLat);
        cg.minLat = minimumLat - 0.01f * (maximumLat - minimumLat);
        cg.minLon = minimumLon - 0.01f * (maximumLat - minimumLat);
        cg.numberOfDivisions = numberOfDivisions;

        MeshFilter mf = floor.AddComponent<MeshFilter>();

        MeshRenderer mr = floor.AddComponent<MeshRenderer>();
        mr.material = groundMaterial;
        floor.transform.position = transform.position;
        floor.transform.parent = transform;
        floor.layer = LayerMask.NameToLayer("RayCast");

        string floorPath = Application.persistentDataPath + "Assets/Resources/Objs/" + cg.maxLat + "I" + cg.maxLon + ".obj";

        if (!File.Exists(floorPath)) // If the file isn't cached we calculate everything and then we cache it
        {
            mf.sharedMesh = cg.GetGroundMesh();
            if (exportObjs)
            {
                ObjExporter oe = new ObjExporter();
                oe.MeshToFile(mf, floorPath);
            }
        }
        else
        {
            ObjImporter oi = new ObjImporter();
            StartCoroutine(oi.FileToMesh("file://" + floorPath));

            while (oi._myMesh == null)
            {
                yield return null;
            }

            mf.sharedMesh = oi._myMesh;
            Debug.LogWarning("Loaded Ground Chunk from cache");
        }

        //Texture2D t = new Texture2D(1024, 1024);

        MapTexture mt = new MapTexture();
        mt.getTexture(cg.minLon.ToString(), cg.minLat.ToString(), cg.maxLon.ToString(), cg.maxLat.ToString(),Application.persistentDataPath,mr.material);
        while (mt.texture == null)
        {
            yield return null;
        }

        //t.LoadImage(mt.ReadFully(mt.mq_dataStream));
        //mr.material.SetTexture("_MainTex", t);

        MeshCollider m = floor.AddComponent<MeshCollider>();
        Loom l = Loom.Current;
        LoadChunk(minimumLon, minimumLat, maximumLon, maximumLat);

        //StartCoroutine();
    }