/// <summary> /// Lerp between the two sets of values /// </summary> /// <param name="cA">The from section</param> /// <param name="cB">The To section</param> /// <param name="v">The percentage between the first and the seconded</param> /// <returns>The cross section at the percentage</returns> public static ICrossSection Lerp(ICrossSection cA, ICrossSection cB, float v) { CrossSection cs = new CrossSection(); cs.RoadWidth = Mathf.Lerp(cA.RoadWidthValue, cB.RoadWidthValue, v); cs.WithCurb = cA.WithCurbValue; cs.CurbLipHeight = Mathf.Lerp(cA.CurbLipHeightValue, cB.CurbLipHeightValue, v); cs.CurbLipSlope = Mathf.Lerp(cA.CurbLipSlopeValue, cB.CurbLipSlopeValue, v); cs.CurbWidth = Mathf.Lerp(cA.CurbWidthValue, cB.CurbWidthValue, v); cs.CurbEdgeDrop = Mathf.Lerp(cA.CurbEdgeDropValue, cB.CurbEdgeDropValue, v); return(cs); }
/// <summary> /// Create the steet layout /// </summary> public void CreateStreetLayout(int subDivide) { if (_startRoadId == null) { return; } if (_endRoadId == null) { return; } RoadCrossSection rA = _startRoadId; ICrossSection crossSectionStart = _startCrossSection; if (crossSectionStart == null) { crossSectionStart = RoadConstructorHelper.CrossSectionDetails; } RoadCrossSection rB = _endRoadId; ICrossSection crossSectionEnd = _endCrossSection; if (crossSectionEnd == null) { crossSectionEnd = RoadConstructorHelper.CrossSectionDetails; } IMaterialFrequency materialFrequency = _materialFrequency; if (materialFrequency == null) { materialFrequency = RoadConstructorHelper.MaterialFrequencySet; } Vector3 len = rA.Middle - rB.Middle; float mag = len.magnitude; int sections = (int)(mag / crossSectionStart.RoadWidthValue); RoadCrossSection[] array = new RoadCrossSection[sections + 1]; string[] materialNames = new string[sections + 1]; float an = rB.Angle; Vector3 start = rB.Middle; if (sections < 2) { Vector3 another = rB.Middle; another = rA.Middle; RoadCrossSection rn = new RoadCrossSection(another, an, crossSectionStart, materialFrequency); _meshSection.AddBasicRoad(IntersectionManager.Instance.AddLinkedIntersecions(rB, rn), RoadConstructorHelper.GetMainMaterial(materialFrequency), 0); // TODO SubDivide return; } Vector3 gap = len / sections; float mag2 = gap.magnitude; for (int i = 0; i < sections + 1; i++) { ICrossSection crossSection = CrossSection.Lerp(crossSectionEnd, crossSectionStart, (mag2 * i) / mag); RoadCrossSection rn = new RoadCrossSection(start, an, crossSection, materialFrequency); array[i] = rn; start += gap; } RoadConstructorHelper.SetMaterialsArray(materialNames, materialFrequency); for (int i = 0; i < sections; i++) { _meshSection.AddBasicRoad(IntersectionManager.Instance.AddLinkedIntersecions(array[i], array[i + 1]), materialNames[i], subDivide); } }