/// <summary> /// Force function to intersect way1 and way2 according to leftright or rightleft orientation /// </summary> private intersectionside forcedIntersectWay(int way1No, int way2No, IntersectionNode intersection, LineSegment segment1, LineSegment segment2, Vector3 fwd1, Vector3 fwd2, bool leftright) { int highwayIndex1 = getHighwayIndex(intersection.wayIds[way1No]); int highwayIndex2 = getHighwayIndex(intersection.wayIds[way2No]); Vector2 intersect = new Vector2(); if(leftright) { Geometry.getVectorIntersection(ref intersect, segment1.Left1, segment1.Left2, fwd1, segment2.Right1, segment2.Right2, fwd2); if (intersect.magnitude == 0) throw new System.InvalidOperationException("Intersection Failed!"); Vector3 newVertex = new Vector3(intersect.x, terrain.getTerrainHeight2(intersect.y + terrain.terrainInfo.shiftZ, intersect.x + terrain.terrainInfo.shiftX), intersect.y); applyIntersection(way1No, way2No, highwayIndex1, highwayIndex2, newVertex, intersection, true); intersectionside s = new intersectionside(); s.vertex = newVertex; s.leftright = leftright; s.success = true; return s; } else { Geometry.getVectorIntersection(ref intersect, segment1.Right1, segment1.Right2, fwd1, segment2.Left1, segment2.Left2, fwd2); if (intersect.magnitude == 0) throw new System.InvalidOperationException("Intersection Failed!"); Vector3 newVertex = new Vector3(intersect.x, terrain.getTerrainHeight2(intersect.y + terrain.terrainInfo.shiftZ, intersect.x + terrain.terrainInfo.shiftX), intersect.y); applyIntersection(way1No, way2No, highwayIndex1, highwayIndex2, newVertex, intersection, false); intersectionside s = new intersectionside(); s.vertex = newVertex; s.leftright = leftright; s.success = true; return s; } }
/// <summary> /// Tries to intersect way1 and way2 (if the angle <180) /// </summary> private intersectionside intersectWay(int way1No, int way2No, IntersectionNode intersection, LineSegment segment1, LineSegment segment2,Vector3 fwd1, Vector3 fwd2,double angle) { int highwayIndex1 = getHighwayIndex(intersection.wayIds[way1No]); int highwayIndex2 = getHighwayIndex(intersection.wayIds[way2No]); Vector2 intersect = new Vector2(); if (Geometry.getHalfVectorIntersection(ref intersect, segment1.Left1, segment1.Left2, fwd1, segment2.Right1, segment2.Right2, fwd2)) { Vector3 newVertex = new Vector3(intersect.x, terrain.getTerrainHeight2(intersect.y + terrain.terrainInfo.shiftZ, intersect.x + terrain.terrainInfo.shiftX), intersect.y); applyIntersection(way1No, way2No,highwayIndex1,highwayIndex2, newVertex, intersection, true); intersectionside s = new intersectionside(); s.vertex = newVertex; s.leftright = true; s.success = true; return s; } else if (Geometry.getHalfVectorIntersection(ref intersect, segment1.Right1, segment1.Right2, fwd1, segment2.Left1, segment2.Left2, fwd2)) { Vector3 newVertex = new Vector3(intersect.x, terrain.getTerrainHeight2(intersect.y + terrain.terrainInfo.shiftZ, intersect.x + terrain.terrainInfo.shiftX), intersect.y); applyIntersection(way1No, way2No,highwayIndex1,highwayIndex2, newVertex, intersection, false); intersectionside s = new intersectionside(); s.vertex = newVertex; s.leftright = false; s.success = true; return s; } else { throw new System.InvalidOperationException("Bormal Intersection Failed!!"); Debug.Log("------------------------------"); intersectionside s = new intersectionside(); s.vertex = new Vector3(0, 0, 0); s.leftright = false; s.success = false; return s; } }