Example #1
0
    void MakeBuilding(Relation relation, GameObject buildingPrefab)
    {
        GameObject newBuilding = (GameObject)Instantiate(buildingPrefab, new Vector3(), Quaternion.identity);

        if (relation.tags.ContainsKey("name"))
        {
            newBuilding.name = relation.tags["name"];
        }
        else
        {
            newBuilding.name = "relation:" + relation.id.ToString();
        }
        roadNetworkBuilding tempBuilding = newBuilding.GetComponent <roadNetworkBuilding>();

        tempBuilding.cornerNodeLists = new List <List <roadNetworkIntersection> >();
        foreach (List <long> way in relation.outerNodeIndices)
        {
            int index = tempBuilding.cornerNodeLists.Count;
            tempBuilding.cornerNodeLists.Add(new List <roadNetworkIntersection>());
            for (int i = 0; i < way.Count - 1; i++)            //OSM will always have the first and last nodes repeated.
            {
                roadNetworkIntersection tempNode = nodeList[way[i]].intersection;
                tempBuilding.cornerNodeLists[index].Add(tempNode);
            }
        }
        tempBuilding.HoleNodeLists = new List <List <roadNetworkIntersection> >();
        foreach (List <long> way in relation.innerNodeIndices)
        {
            int index = tempBuilding.HoleNodeLists.Count;
            tempBuilding.HoleNodeLists.Add(new List <roadNetworkIntersection>());
            for (int i = 0; i < way.Count - 1; i++)            //OSM will always have the first and last nodes repeated.
            {
                roadNetworkIntersection tempNode = nodeList[way[i]].intersection;
                tempBuilding.HoleNodeLists[index].Add(tempNode);
            }
        }
        double height;
        string heightString;

        if (relation.tags.TryGetValue("height", out heightString))
        {
            height = ConvertToMeters(heightString);
        }
        else if ((relation.tags.TryGetValue("building:levels", out heightString)) && Double.TryParse(heightString, out height))
        {
            height *= levelHeight;
        }
        else if (relation.tags.ContainsKey("building"))
        {
            height = 6;
        }
        else
        {
            height = 0.0f;
        }
        tempBuilding.height = (float)height;
        relation.building   = tempBuilding;
        buildingList.Add(tempBuilding);
    }
Example #2
0
 public float getWidthRight(roadNetworkIntersection requester)
 {
     if (requester == destination)
     {
         return(widthLeft);
     }
     return(widthRight);
 }
Example #3
0
 public roadNetworkIntersection getOtherIntersection(roadNetworkIntersection input)
 {
     if (input == origin)
     {
         return(destination);
     }
     if (input == destination)
     {
         return(origin);
     }
     return(null);
 }
Example #4
0
    void MakeRoads(Way way)
    {
        for (int i = 0; i < way.nodeIndices.Count - 1; i++)
        {
            roadNetworkIntersection tempNode = nodeList[way.nodeIndices[i]].intersection;
            roadNetworkIntersection nextNode = nodeList[way.nodeIndices[i + 1]].intersection;
            GameObject newRoad = (GameObject)Instantiate(roadObject, tempNode.gameObject.transform.position, Quaternion.identity);
            if (way.tags.ContainsKey("name"))
            {
                newRoad.name = way.tags["name"];
            }
            else
            {
                newRoad.name = "way:" + way.id.ToString();
            }
            roadNetworkRoad tempRoad = newRoad.GetComponent <roadNetworkRoad>();
            tempRoad.origin      = tempNode;
            tempRoad.destination = nextNode;

            double width;
            string widthString;
            string highwayString;
            if (way.tags.TryGetValue("width", out widthString))
            {
                width = ConvertToMeters(widthString);
            }
            else if (way.tags.TryGetValue("lanes", out widthString) && Double.TryParse(widthString, out width))
            {
                width *= 3;
            }
            else if (way.tags.TryGetValue("highway", out highwayString))
            {
                width = GetDefaultWidth(highwayString);
            }
            else
            {
                width = 1;
            }

            tempRoad.widthLeft  = (float)(width / 2);
            tempRoad.widthRight = (float)(width / 2);
            tempRoad.EnsureConnections();
            way.roadList.Add(tempRoad);
        }
    }
Example #5
0
 public bool IsConnected(roadNetworkIntersection inter)
 {
     return(inter == origin || inter == destination);
 }
Example #6
0
 public roadNetworkRoad(roadNetworkIntersection creator)
 {
     origin = creator;
 }
Example #7
0
 public void setEndPoints(Vector3 leftPoint, Vector3 midPoint, Vector3 rightPoint, roadNetworkIntersection source)
 {
     if (source == origin)
     {
         originLeftPoint  = leftPoint;
         originMidPoint   = midPoint;
         originRightPoint = rightPoint;
     }
     if (source == destination)
     {
         destinationLeftPoint  = rightPoint;
         destinationMidPoint   = midPoint;
         destinationRightPoint = leftPoint;
     }
 }