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); }
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); }
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); }
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); } } } }