private void OnGUI() { if (GUI.Button(new Rect(5, 5, 100, 30), "Calc")) { // Calculate the distance in km between locations. float distance = OnlineMapsUtils.DistanceBetweenPoints(userCoordinares, markerCoordinates).magnitude; Debug.Log("Distance: " + distance); int zoom = 15; int maxX = 1 << zoom; // Calculate the tile position of locations. Vector2 userTile = OnlineMapsUtils.LatLongToTilef(userCoordinares, zoom); Vector2 markerTile = OnlineMapsUtils.LatLongToTilef(markerCoordinates, zoom); // Calculate the angle between locations. float angle = OnlineMapsUtils.Angle2D(userTile, markerTile); if (Mathf.Abs(userTile.x - markerTile.x) > maxX / 2) { angle = 360 - angle; } Debug.Log("Angle: " + angle); // Calculate relative angle between locations. float relativeAngle = angle - compassTrueHeading; Debug.Log("Relative angle: " + relativeAngle); } }
private void OnGUI() { if (GUI.Button(new Rect(5, 5, 100, 30), "Calc")) { // Calculate the distance in km between locations. float distance = OnlineMapsUtils.DistanceBetweenPoints(userCoordinares, markerCoordinates).magnitude; Debug.Log("Distance: " + distance); int zoom = 15; int maxX = 1 << (zoom - 1); // Calculate the tile position of locations. double userTileX, userTileY, markerTileX, markerTileY; OnlineMaps.instance.projection.CoordinatesToTile(userCoordinares.x, userCoordinares.y, zoom, out userTileX, out userTileY); OnlineMaps.instance.projection.CoordinatesToTile(markerCoordinates.x, markerCoordinates.y, zoom, out markerTileX, out markerTileY); // Calculate the angle between locations. double angle = OnlineMapsUtils.Angle2D(userTileX, userTileY, markerTileX, markerTileY); if (Math.Abs(userTileX - markerTileX) > maxX) { angle = 360 - angle; } Debug.Log("Angle: " + angle); // Calculate relative angle between locations. double relativeAngle = angle - compassTrueHeading; Debug.Log("Relative angle: " + relativeAngle); } }
private void OnMapClick() { control.GetCoords(out targetLng, out targetLat); if (targetMarker == null) { targetMarker = OnlineMapsMarker3DManager.CreateItem(targetLng, targetLat, targetPrefab); targetMarker.scale = targetScale; } else { targetMarker.SetPosition(targetLng, targetLat); } double tx1, ty1, tx2, ty2; map.projection.CoordinatesToTile(lng, lat, map.zoom, out tx1, out ty1); map.projection.CoordinatesToTile(targetLng, targetLat, map.zoom, out tx2, out ty2); rotation = (float)OnlineMapsUtils.Angle2D(tx1, ty1, tx2, ty2) - 90; if (!OnlineMapsKeyManager.hasGoogleMaps) { Debug.LogWarning("Please enter Map / Key Manager / Google Maps"); return; } OnlineMapsGoogleDirections request = new OnlineMapsGoogleDirections(OnlineMapsKeyManager.GoogleMaps(), new Vector2((float)lng, (float)lat), control.GetCoords()); request.OnComplete += OnRequestComplete; request.Send(); }
public override void LookToCoordinates(OnlineMapsVector2d coordinates) { double p1x, p1y, p2x, p2y; map.projection.CoordinatesToTile(coordinates.x, coordinates.y, 20, out p1x, out p1y); map.projection.CoordinatesToTile(longitude, latitude, 20, out p2x, out p2y); rotation = Quaternion.Euler(0, (float)(OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y) - 90), 0); }
public override void LookToCoordinates(Vector2 coordinates) { double p1x, p1y, p2x, p2y; map.projection.CoordinatesToTile(coordinates.x, coordinates.y, 20, out p1x, out p1y); map.projection.CoordinatesToTile(longitude, latitude, 20, out p2x, out p2y); rotation = (float)(1.25 - OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y) / 360); }
private void Update() { if (pointIndex == -1) { return; } // Start point Vector3 p1 = points[pointIndex]; // End point Vector3 p2 = points[pointIndex + 1]; // Total step distance float stepDistance = OnlineMapsUtils.DistanceBetweenPoints(p1, p2).magnitude; // Total step time float totalTime = stepDistance / speed * 3600; // Current step progress progress += Time.deltaTime / totalTime; if (progress < 1) { marker.position = Vector2.Lerp(p1, p2, progress); // Orient marker if (orientMarkerOnNextPoint) { marker.rotation = 1.25f - OnlineMapsUtils.Angle2D((Vector2)p1, (Vector2)p2) / 360f; } } else { marker.position = p2; pointIndex++; progress = 0; if (pointIndex >= points.Count - 1) { Debug.Log("Finish"); pointIndex = -1; } else { // Orient marker if (orientMarkerOnNextPoint) { marker.rotation = 1.25f - OnlineMapsUtils.Angle2D((Vector2)p2, (Vector2)points[pointIndex + 1]) / 360; } } } if (lookToMarker) { OnlineMaps.instance.position = marker.position; } OnlineMaps.instance.Redraw(); }
private void OnMapClick() { control.GetCoords(out targetLng, out targetLat); if (targetMarker == null) { targetMarker = OnlineMapsMarker3DManager.CreateItem(targetLng, targetLat, targetPrefab); targetMarker.scale = targetScale; } else { targetMarker.SetPosition(targetLng, targetLat); } double tx1, ty1, tx2, ty2; map.projection.CoordinatesToTile(lng, lat, map.zoom, out tx1, out ty1); map.projection.CoordinatesToTile(targetLng, targetLat, map.zoom, out tx2, out ty2); rotation = (float)OnlineMapsUtils.Angle2D(tx1, ty1, tx2, ty2) - 90; hasTargetPoint = true; if (lineRenderer == null) { GameObject go = new GameObject("LineRenderer"); go.transform.SetParent(transform, false); lineRenderer = go.AddComponent <LineRenderer>(); lineRenderer.material = lineRendererMaterial; #if UNITY_2017_3_OR_NEWER lineRenderer.positionCount = 2; lineRenderer.widthCurve = AnimationCurve.Constant(0, 1, 10); #elif UNITY_2017_1_OR_NEWER lineRenderer.positionCount = 2; lineRenderer.widthCurve = AnimationCurve.Linear(0, 10, 1, 10); #else lineRenderer.SetVertexCount(2); lineRenderer.SetWidth(10, 10); #endif } else { lineRenderer.enabled = true; } Vector3 p1 = control.GetWorldPosition(lng, lat); lineRenderer.SetPosition(0, p1); lineRenderer.SetPosition(1, p1); lineRendererProgress = 0; }
private void Update() { double lookProgress = progress + 0.001; double tiltProgress = progress + 0.001; Point position = GetPointByProgress(progress); Point lookPosition = GetPointByProgress(lookProgress); Point tiltPosition = GetPointByProgress(tiltProgress); speed += accelerationCurve.Evaluate(speed / maxSpeed) * Time.deltaTime; if (speed > lookPosition.relativeSpeed * maxSpeed) { speed = lookPosition.relativeSpeed * maxSpeed; } double offset = Time.deltaTime * speed / 3600; progress += offset / totalDistance; double p1x, p1y, p2x, p2y; map.projection.CoordinatesToTile(position.longitude, position.latitude, map.zoom, out p1x, out p1y); map.projection.CoordinatesToTile(lookPosition.longitude, lookPosition.latitude, map.zoom, out p2x, out p2y); targetRotation = (float)OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y); map.projection.CoordinatesToTile(tiltPosition.longitude, tiltPosition.latitude, map.zoom, out p2x, out p2y); float tiltRotation = (float)OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y); tilt = tiltRotation - airplane.transform.rotation.eulerAngles.y; Vector3 p = OnlineMapsTileSetControl.instance.GetWorldPosition(position.longitude, position.latitude); altitude = position.relativeAltitude * maxAltitude; float elevation = OnlineMapsElevationManagerBase.GetUnscaledElevation(p.x, p.z); p.x = -1024; float zoom = altitudeZoomCurve.Evaluate(altitude / maxAltitude); p.y = Mathf.Max(altitude, elevation) * OnlineMapsElevationManagerBase.GetBestElevationYScale(); p.z = 1024; airplane.transform.position = p; airplane.transform.rotation = Quaternion.Euler(0, Mathf.LerpAngle(airplane.transform.rotation.eulerAngles.y, targetRotation, Time.deltaTime), 0); float s = 1 / Mathf.Pow(2, 15 - map.floatZoom); transform.localScale = new Vector3(s, s, s); internalGO.transform.localRotation = Quaternion.Euler(tilt, 0, 0); map.SetPositionAndZoom(position.longitude, position.latitude, zoom); OnlineMapsCameraOrbit.instance.rotation = new Vector2(OnlineMapsCameraOrbit.instance.rotation.x, airplane.transform.rotation.eulerAngles.y + 90); }
private double Angle(Vector2 userCoordinares, Vector2 markerCoordinates) { int zoom = 15; int maxX = 1 << (zoom - 1); double userTileX, userTileY, markerTileX, markerTileY; OnlineMapsProjection projection = MapManager.Instance.map.projection; projection.CoordinatesToTile(userCoordinares.x, userCoordinares.y, zoom, out userTileX, out userTileY); projection.CoordinatesToTile(markerCoordinates.x, markerCoordinates.y, zoom, out markerTileX, out markerTileY); // Calculate the angle between locations. double angle = OnlineMapsUtils.Angle2D(userTileX, userTileY, markerTileX, markerTileY); return(angle); }
private void Start() { map = OnlineMaps.instance; if (points == null) { points = new List <Point>(); } if (points.Count == 0) { points.Add(new Point(OnlineMaps.instance.position)); } Point p1 = points[0]; Point p2 = points[1]; double p1x, p1y, p2x, p2y; map.projection.CoordinatesToTile(p1.longitude, p1.latitude, map.zoom, out p1x, out p1y); map.projection.CoordinatesToTile(p2.longitude, p2.latitude, map.zoom, out p2x, out p2y); targetRotation = (float)OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y) - 90; transform.rotation = Quaternion.Euler(0, targetRotation, 0); distances = new List <double>(); totalDistance = 0; for (int i = 1; i < points.Count; i++) { p1 = points[i - 1]; p2 = points[i]; double dx, dy; OnlineMapsUtils.DistanceBetweenPoints(p1.longitude, p1.latitude, p2.longitude, p2.latitude, out dx, out dy); double stepDistance = Math.Sqrt(dx * dx + dy * dy); distances.Add(stepDistance); totalDistance += stepDistance; } }
private void Update() { if (pointIndex == -1) { return; } // Start point OnlineMapsVector2d p1 = points[pointIndex]; // End point OnlineMapsVector2d p2 = points[pointIndex + 1]; // Total step distance double dx, dy; OnlineMapsUtils.DistanceBetweenPoints(p1.x, p1.y, p2.x, p2.y, out dx, out dy); double stepDistance = Math.Sqrt(dx * dx + dy * dy); // Total step time double totalTime = stepDistance / speed * 3600; // Current step progress progress += Time.deltaTime / totalTime; OnlineMapsVector2d position; if (progress < 1) { position = OnlineMapsVector2d.Lerp(p1, p2, progress); marker.SetPosition(position.x, position.y); // Orient marker if (orientMarkerOnNextPoint) { marker.rotation = 1.25f - OnlineMapsUtils.Angle2D((Vector2)p1, (Vector2)p2) / 360f; } } else { position = p2; marker.SetPosition(position.x, position.y); pointIndex++; progress = 0; if (pointIndex >= points.Length - 1) { Debug.Log("Finish"); pointIndex = -1; } else { // Orient marker if (orientMarkerOnNextPoint) { marker.rotation = 1.25f - OnlineMapsUtils.Angle2D(p2, points[pointIndex + 1]) / 360; } } } if (lookToMarker) { OnlineMaps.instance.SetPosition(position.x, position.y); } OnlineMaps.instance.Redraw(); }
private bool CreateHouseWallVerticles(float baseHeight, List <Vector3> baseVertices, List <Vector3> vertices, List <Vector2> uvs) { float topPoint = baseHeight * OnlineMapsBuildings.instance.heightScale; int baseVerticesCount = baseVertices.Count; Vector3 pp = Vector3.zero; Vector3 ptv = Vector3.zero; for (int i = 0; i <= baseVerticesCount; i++) { int j = i; if (j >= baseVerticesCount) { j -= baseVerticesCount; } Vector3 p = baseVertices[j]; Vector3 tv = new Vector3(p.x, topPoint, p.z); if (i > 0) { vertices.Add(pp); vertices.Add(ptv); vertices.Add(p); vertices.Add(tv); } pp = p; ptv = tv; } float currentDistance = 0; int countVertices = vertices.Count; int fourthVerticesCount = countVertices / 4; perimeter = 0; for (int i = 0; i < fourthVerticesCount; i++) { int i1 = i * 4; int i2 = i * 4 + 2; float magnitude = (vertices[i1] - vertices[i2]).magnitude; perimeter += magnitude; } float prevDistance = 0; for (int i = 0; i < fourthVerticesCount; i++) { int i1 = i * 4; int i2 = i * 4 + 2; float magnitude = (vertices[i1] - vertices[i2]).magnitude; float prevU = prevDistance / perimeter; currentDistance += magnitude; prevDistance = currentDistance; float curU = currentDistance / perimeter; uvs.Add(new Vector2(prevU, 0)); uvs.Add(new Vector2(prevU, 1)); uvs.Add(new Vector2(curU, 0)); uvs.Add(new Vector2(curU, 1)); } int southIndex = -1; float southZ = float.MaxValue; for (int i = 0; i < baseVerticesCount; i++) { if (baseVertices[i].z < southZ) { southZ = baseVertices[i].z; southIndex = i; } } int prevIndex = southIndex - 1; if (prevIndex < 0) { prevIndex = baseVerticesCount - 1; } int nextIndex = southIndex + 1; if (nextIndex >= baseVerticesCount) { nextIndex = 0; } float angle1 = OnlineMapsUtils.Angle2D(baseVertices[southIndex], baseVertices[nextIndex]); float angle2 = OnlineMapsUtils.Angle2D(baseVertices[southIndex], baseVertices[prevIndex]); return(angle1 < angle2); }
/// <summary> /// Creates a new building, based on Open Street Map. /// </summary> /// <param name="container">Reference to OnlineMapsBuildings.</param> /// <param name="way">Way of building.</param> /// <param name="nodes">Nodes obtained from Open Street Maps.</param> /// <returns>Building instance.</returns> public static OnlineMapsBuildingBase Create(OnlineMapsBuildings container, OnlineMapsOSMWay way, Dictionary <string, OnlineMapsOSMNode> nodes) { if (CheckIgnoredBuildings(way)) { return(null); } if (usedNodes == null) { usedNodes = new List <OnlineMapsOSMNode>(30); } else { usedNodes.Clear(); } way.GetNodes(nodes, usedNodes); List <Vector3> points = GetLocalPoints(usedNodes); if (points.Count < 3) { return(null); } if (points[0] == points[points.Count - 1]) { points.RemoveAt(points.Count - 1); } if (points.Count < 3) { return(null); } for (int i = 0; i < points.Count; i++) { int prev = i - 1; if (prev < 0) { prev = points.Count - 1; } int next = i + 1; if (next >= points.Count) { next = 0; } float a1 = OnlineMapsUtils.Angle2D(points[prev], points[i]); float a2 = OnlineMapsUtils.Angle2D(points[i], points[next]); if (Mathf.Abs(a1 - a2) < 5) { points.RemoveAt(i); i--; } } if (points.Count < 3) { return(null); } Vector4 cp = new Vector4(float.MaxValue, float.MaxValue, float.MinValue, float.MinValue); for (int i = 0; i < points.Count; i++) { Vector3 point = points[i]; if (point.x < cp.x) { cp.x = point.x; } if (point.z < cp.y) { cp.y = point.z; } if (point.x > cp.z) { cp.z = point.x; } if (point.z > cp.w) { cp.w = point.z; } } Vector3 centerPoint = new Vector3((cp.z + cp.x) / 2, 0, (cp.y + cp.w) / 2); for (int i = 0; i < points.Count; i++) { points[i] -= centerPoint; } bool generateWall = true; if (way.HasTagKey("building")) { string buildingType = way.GetTagValue("building"); if (buildingType == "roof") { generateWall = false; } } float baseHeight = 15; float roofHeight = 0; OnlineMapsBuildingMaterial material = GetRandomMaterial(container); Material wallMaterial; Material roofMaterial; Vector2 scale = Vector2.one; if (defaultShader == null) { defaultShader = Shader.Find("Diffuse"); } if (material != null) { if (material.wall != null) { wallMaterial = Instantiate(material.wall) as Material; } else { wallMaterial = new Material(defaultShader); } if (material.roof != null) { roofMaterial = Instantiate(material.roof) as Material; } else { roofMaterial = new Material(defaultShader); } scale = material.scale; } else { if (defaultWallMaterial == null) { defaultWallMaterial = new Material(defaultShader); } if (defaultRoofMaterial == null) { defaultRoofMaterial = new Material(defaultShader); } wallMaterial = Instantiate(defaultWallMaterial) as Material; roofMaterial = Instantiate(defaultRoofMaterial) as Material; } RoofType roofType = RoofType.flat; AnalizeHouseTags(way, ref wallMaterial, ref roofMaterial, ref baseHeight); AnalizeHouseRoofType(way, ref baseHeight, ref roofType, ref roofHeight); GameObject houseGO = CreateGameObject(way.id); MeshRenderer renderer = houseGO.AddComponent <MeshRenderer>(); MeshFilter meshFilter = houseGO.AddComponent <MeshFilter>(); Mesh mesh = new Mesh { name = way.id }; meshFilter.sharedMesh = mesh; renderer.sharedMaterials = new [] { wallMaterial, roofMaterial }; OnlineMapsBuildingBuiltIn building = houseGO.AddComponent <OnlineMapsBuildingBuiltIn>(); building.way = way; building.nodes = usedNodes; houseGO.transform.localPosition = centerPoint; houseGO.transform.localRotation = Quaternion.Euler(Vector3.zero); houseGO.transform.localScale = Vector3.one; Vector2 centerCoords = Vector2.zero; float minCX = float.MaxValue, minCY = float.MaxValue, maxCX = float.MinValue, maxCY = float.MinValue; foreach (OnlineMapsOSMNode node in usedNodes) { Vector2 nodeCoords = node; centerCoords += nodeCoords; if (nodeCoords.x < minCX) { minCX = nodeCoords.x; } if (nodeCoords.y < minCY) { minCY = nodeCoords.y; } if (nodeCoords.x > maxCX) { maxCX = nodeCoords.x; } if (nodeCoords.y > maxCY) { maxCY = nodeCoords.y; } } building.id = way.id; building.initialZoom = OnlineMaps.instance.zoom; building.centerCoordinates = new Vector2((maxCX + minCX) / 2, (maxCY + minCY) / 2); building.boundsCoords = new Bounds(building.centerCoordinates, new Vector3(maxCX - minCX, maxCY - minCY)); int wallVerticesCount = (points.Count + 1) * 2; int roofVerticesCount = points.Count; int verticesCount = wallVerticesCount + roofVerticesCount; int countTriangles = wallVerticesCount * 3; if (vertices == null) { vertices = new List <Vector3>(verticesCount); } else { vertices.Clear(); } if (uvs == null) { uvs = new List <Vector2>(verticesCount); } else { uvs.Clear(); } if (wallTriangles == null) { wallTriangles = new List <int>(countTriangles); } else { wallTriangles.Clear(); } if (roofTriangles == null) { roofTriangles = new List <int>(); } else { roofTriangles.Clear(); } if (generateWall) { building.CreateHouseWall(points, baseHeight, wallMaterial, scale); } building.CreateHouseRoof(points, baseHeight, roofHeight, roofType); if (building.hasErrors) { OnlineMapsUtils.DestroyImmediate(building.gameObject); return(null); } mesh.vertices = vertices.ToArray(); mesh.uv = uvs.ToArray(); mesh.subMeshCount = 2; mesh.SetTriangles(wallTriangles.ToArray(), 0); mesh.SetTriangles(roofTriangles.ToArray(), 1); mesh.RecalculateBounds(); mesh.RecalculateNormals(); building.buildingCollider = houseGO.AddComponent <MeshCollider>(); (building.buildingCollider as MeshCollider).sharedMesh = mesh; return(building); }
public override void LookToCoordinates(Vector2 coordinates) { rotation = 1.25f - OnlineMapsUtils.Angle2D(coordinates, position) / 360; }
private void Update() { if (pointIndex == -1) { return; } // Start point OnlineMapsVector2d p1 = points[pointIndex]; // End point OnlineMapsVector2d p2 = points[pointIndex + 1]; double p1x, p1y, p2x, p2y; map.projection.CoordinatesToTile(p1.x, p1.y, map.zoom, out p1x, out p1y); map.projection.CoordinatesToTile(p2.x, p2.y, map.zoom, out p2x, out p2y); // Total step distance double dx, dy; OnlineMapsUtils.DistanceBetweenPoints(p1.x, p1.y, p2.x, p2.y, out dx, out dy); double stepDistance = Math.Sqrt(dx * dx + dy * dy); // Total step time double totalTime = stepDistance / speed * 3600; // Current step progress progress += Time.deltaTime / totalTime; OnlineMapsVector2d position; if (progress < 1) { position = OnlineMapsVector2d.Lerp(p1, p2, progress); marker.SetPosition(position.x, position.y); // Orient marker targetRotation = (float)OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y) - 90; } else { position = p2; marker.SetPosition(position.x, position.y); pointIndex++; progress = 0; if (pointIndex >= points.Length - 1) { Debug.Log("Finish"); pointIndex = -1; } else { OnlineMapsVector2d p3 = points[pointIndex + 1]; map.projection.CoordinatesToTile(p2.x, p2.y, map.zoom, out p1x, out p1y); map.projection.CoordinatesToTile(p3.x, p3.y, map.zoom, out p2x, out p2y); targetRotation = (float)OnlineMapsUtils.Angle2D(p1x, p1y, p2x, p2y) - 90; } } marker.rotationY = Mathf.LerpAngle(marker.rotationY, targetRotation, Time.deltaTime * 10); marker.GetPosition(out lng, out lat); map.SetPosition(lng, lat); }
private bool CreateHouseWallVerticles(float baseHeight, List <Vector3> baseVerticles, List <Vector3> vertices, List <Vector2> uvs) { float topPoint = baseHeight * OnlineMapsBuildings.instance.heightScale; int baseVerticesCount = baseVerticles.Count; for (int i = 0; i <= baseVerticesCount; i++) { int j = i; if (j >= baseVerticesCount) { j -= baseVerticesCount; } Vector3 p = baseVerticles[j]; Vector3 tv = new Vector3(p.x, topPoint, p.z); vertices.Add(p); vertices.Add(tv); } float currentDistance = 0; int countVertices = vertices.Count; int halfVerticesCount = countVertices / 2; perimeter = 0; for (int i = 0; i <= halfVerticesCount; i++) { int i1 = i * 2; int i2 = i * 2 + 2; while (i1 >= countVertices) { i1 -= countVertices; } while (i2 >= countVertices) { i2 -= countVertices; } float sqrMagnitude = (vertices[i1] - vertices[i2]).sqrMagnitude; perimeter += sqrMagnitude; } perimeter = Mathf.Sqrt(perimeter); for (int i = 0; i <= halfVerticesCount; i++) { int i1 = i * 2; int i2 = i * 2 + 2; while (i1 >= countVertices) { i1 -= countVertices; } while (i2 >= countVertices) { i2 -= countVertices; } float magnitude = (vertices[i1] - vertices[i2]).magnitude; if (i < halfVerticesCount) { float curU = currentDistance / perimeter; uvs.Add(new Vector2(curU, 0)); uvs.Add(new Vector2(curU, 1)); } currentDistance += magnitude; } int southIndex = -1; float southZ = float.MaxValue; for (int i = 0; i < baseVerticesCount; i++) { if (baseVerticles[i].z < southZ) { southZ = baseVerticles[i].z; southIndex = i; } } int prevIndex = southIndex - 1; if (prevIndex < 0) { prevIndex = baseVerticesCount - 1; } int nextIndex = southIndex + 1; if (nextIndex >= baseVerticesCount) { nextIndex = 0; } float angle1 = OnlineMapsUtils.Angle2D(baseVerticles[southIndex], baseVerticles[nextIndex]); float angle2 = OnlineMapsUtils.Angle2D(baseVerticles[southIndex], baseVerticles[prevIndex]); return(angle1 < angle2); }
private bool CreateHouseWallVerticles(float baseHeight, Vector3[] baseVerticles, List <Vector3> vertices, List <Vector2> uvs) { float topPoint = baseHeight * OnlineMapsBuildings.instance.heightScale; foreach (Vector3 p in baseVerticles) { AddHouseWallVerticle(vertices, p, topPoint); } AddHouseWallVerticle(vertices, baseVerticles[0], topPoint); perimeter = 0; for (int i = 0; i <= vertices.Count / 2; i++) { int i1 = Mathf.RoundToInt(Mathf.Repeat(i * 2, vertices.Count)); int i2 = Mathf.RoundToInt(Mathf.Repeat((i + 1) * 2, vertices.Count)); perimeter += (vertices[i1] - vertices[i2]).magnitude; } float currentDistance = 0; for (int i = 0; i < vertices.Count / 2; i++) { int i1 = Mathf.RoundToInt(Mathf.Repeat(i * 2, vertices.Count)); int i2 = Mathf.RoundToInt(Mathf.Repeat((i + 1) * 2, vertices.Count)); float curU = currentDistance / perimeter; uvs.Add(new Vector2(curU, 0)); uvs.Add(new Vector2(curU, 1)); currentDistance += (vertices[i1] - vertices[i2]).magnitude; } int southIndex = -1; float southZ = float.MaxValue; for (int i = 0; i < baseVerticles.Length; i++) { if (baseVerticles[i].z < southZ) { southZ = baseVerticles[i].z; southIndex = i; } } int prevIndex = southIndex - 1; if (prevIndex < 0) { prevIndex = baseVerticles.Length - 1; } int nextIndex = southIndex + 1; if (nextIndex >= baseVerticles.Length) { nextIndex = 0; } float angle1 = OnlineMapsUtils.Angle2D(baseVerticles[southIndex], baseVerticles[nextIndex]); float angle2 = OnlineMapsUtils.Angle2D(baseVerticles[southIndex], baseVerticles[prevIndex]); return(angle1 < angle2); }