Exemplo n.º 1
0
    public void BuildPath()
    {
        List <Vector3> path = city.metricConstraint.ProcessPathNoEndpoints(startPosition, endPosition);

        Intersection start = exposedHead;
        Intersection end   = exposedChild;

        if (exposedHead == null) //initialized with Init(Intersection, Intersection);
        {
            start = CigenFactory.CreateOrMergeIntersection(startPosition, city);
        }
        if (exposedChild == null)
        {
            end = CigenFactory.CreateOrMergeIntersection(endPosition, city);
        }

        Intersection curr = start;

        foreach (Vector3 v in path)
        {
            Intersection newIntersection = CigenFactory.CreateOrMergeIntersection(v, city);
            CigenFactory.CreateRoad(curr, newIntersection);
            curr = newIntersection;
        }
        CigenFactory.CreateRoad(curr, end);
    }
Exemplo n.º 2
0
 public void Init(Vector3 position, CitySettings settings)
 {
     transform.position = position;
     this.settings      = settings;
     metricConstraint   = MetricFactory.Process(this.settings.metric, settings);
     origin             = CigenFactory.CreateOrMergeIntersection(RandomLocalPosition(), this);
 }
Exemplo n.º 3
0
    public Intersection CreateIntersectionAtPositionOnRoad(Vector3 position, Road road)
    {
        Intersection newIntersection = CigenFactory.CreateOrMergeIntersection(position, this);
        Intersection parent          = road.parentNode;
        Intersection child           = road.childNode;

        road.Remove();
        CigenFactory.CreateRoad(parent, newIntersection);
        CigenFactory.CreateRoad(newIntersection, child);
        return(newIntersection);
    }
Exemplo n.º 4
0
    public void AddRandomIntersectionToRoadNetwork()
    {
        Vector3 p1 = RandomLocalPosition();

        Vector3      bestPositionForIntersection = Vector3.one * float.MaxValue;
        Road         roadToConnectTo             = null;
        Intersection intersectionToConnectTo     = null;
        object       cmpr = null;

        {
            object[] data = ClosestPointOnRoadNetwork(p1);
            bestPositionForIntersection = (Vector3)data[0];
            cmpr = data[1];
        }
        if (bestPositionForIntersection != Vector3.one * float.MaxValue)
        {
            if (IsValidRoad(bestPositionForIntersection, p1))
            {
                Intersection q1 = CigenFactory.CreateOrMergeIntersection(p1, this);

                if (cmpr is Intersection)
                {
                    intersectionToConnectTo = (Intersection)cmpr;
                }

                if (cmpr is Road)
                {
                    roadToConnectTo         = (Road)cmpr;
                    intersectionToConnectTo = CreateIntersectionAtPositionOnRoad(bestPositionForIntersection, roadToConnectTo);
                }

                if (intersectionToConnectTo != null)
                {
                    CigenFactory.CreatePath(q1, intersectionToConnectTo);
                }
            }
        }
    }