protected void UpdateCameraPosition() { //if (cameraRotation.x > maxCameraRotationX) cameraRotation.x = 0; //changed value here //else if (cameraRotation.x < 0) cameraRotation.x = 0; float rx = 90 - 0; if (rx > 89.9) { rx = 89.9f; } double px = Math.Cos(rx * Mathf.Deg2Rad) * cameraDistance; double py = Math.Sin(rx * Mathf.Deg2Rad) * cameraDistance; double pz = Math.Cos(cameraRotation.y * Mathf.Deg2Rad) * px; px = Math.Sin(cameraRotation.y * Mathf.Deg2Rad) * px; Vector3 targetPosition = transform.position; if (this is OnlineMapsTileSetControl) { Vector3 offset = new Vector3(map.tilesetSize.x / -2, 0, map.tilesetSize.y / 2); OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance; if (control.smoothZoom && control.smoothZoomStarted) { targetPosition = originalPosition; } if (control.useElevation && control.elevationZoomRange.InRange(map.zoom)) { double tlx, tly, brx, bry; map.GetCorners(out tlx, out tly, out brx, out bry); float yScale = control.GetBestElevationYScale(tlx, tly, brx, bry); if (cameraAdjustTo == OnlineMapsCameraAdjust.maxElevationInArea) { offset.y = control.GetMaxElevationValue(yScale); } else { offset.y = control.GetElevationValue(targetPosition.x, targetPosition.z, yScale, tlx, tly, brx, bry); } } offset.Scale(control.smoothZoomStarted? control.originalScale: transform.lossyScale); targetPosition += transform.rotation * offset; } Vector3 oldPosition = activeCamera.transform.position; Vector3 newPosition = transform.rotation * new Vector3((float)px, (float)py, (float)pz) + targetPosition; activeCamera.transform.position = newPosition; activeCamera.transform.LookAt(targetPosition); if (oldPosition != newPosition && OnCameraControl != null) { OnCameraControl(); } }
private void UpdateCameraPosition() { if (cameraRotation.x > 80) { cameraRotation.x = 80f; } else if (cameraRotation.x < 0) { cameraRotation.x = 0; } float rx = 90 - cameraRotation.x; if (rx > 89.9) { rx = 89.9f; } double px = Math.Cos(rx * Mathf.Deg2Rad) * cameraDistance; double py = Math.Sin(rx * Mathf.Deg2Rad) * cameraDistance; double pz = Math.Cos(cameraRotation.y * Mathf.Deg2Rad) * px; px = Math.Sin(cameraRotation.y * Mathf.Deg2Rad) * px; Vector3 targetPosition = transform.position; if (this is OnlineMapsTileSetControl) { Vector3 offset = new Vector3(api.tilesetSize.x / -2, 0, api.tilesetSize.y / 2); OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance; if (control.smoothZoom && control.smoothZoomStarted) { targetPosition = control.originalPosition; } if (control.useElevation && control.elevationZoomRange.InRange(api.zoom)) { double tlx, tly, brx, bry; api.GetTopLeftPosition(out tlx, out tly); api.GetBottomRightPosition(out brx, out bry); float yScale = control.GetBestElevationYScale(tlx, tly, brx, bry); offset.y = control.GetMaxElevationValue(yScale); } targetPosition += transform.rotation * offset; } Vector3 oldPosition = activeCamera.transform.position; Vector3 newPosition = transform.rotation * new Vector3((float)px, (float)py, (float)pz) + targetPosition; activeCamera.transform.position = newPosition; activeCamera.transform.LookAt(targetPosition); if (oldPosition != newPosition && OnCameraControl != null) { OnCameraControl(); } }
public override void Update(double tlx, double tly, double brx, double bry, int zoom) { if (instance == null) { Debug.Log("No instance"); return; } if (!range.InRange(zoom)) { enabled = false; } else if (position.y > tly || position.y < bry) { enabled = false; } else if (tlx < brx && (position.x < tlx || position.x > brx)) { enabled = false; } else if (tlx > brx && position.x < tlx && position.x > brx) { enabled = false; } else { enabled = true; } if (!enabled) { return; } if (_prefab != prefab) { Reinit(tlx, tly, brx, bry, zoom); } double mx, my; OnlineMapsUtils.LatLongToTiled(position.x, position.y, zoom, out mx, out my); double ttlx, ttly, tbrx, tbry; OnlineMapsUtils.LatLongToTiled(tlx, tly, zoom, out ttlx, out ttly); OnlineMapsUtils.LatLongToTiled(brx, bry, zoom, out tbrx, out tbry); int maxX = (2 << zoom) / 2; OnlineMaps api = OnlineMaps.instance; Bounds bounds = api.GetComponent <Collider>().bounds; double sx = tbrx - ttlx; if (sx < 0) { sx += maxX; } double mpx = mx - ttlx; if (mpx < 0) { mpx += maxX; } double px = mpx / sx; double pz = (ttly - my) / (ttly - tbry); _relativePosition = new Vector3((float)px, 0, (float)pz); if (OnlineMapsControlBase.instance is OnlineMapsTileSetControl) { px = -api.tilesetSize.x / 2 - (px - 0.5) * api.tilesetSize.x; pz = api.tilesetSize.y / 2 + (pz - 0.5) * api.tilesetSize.y; } else { Vector3 center = bounds.center; Vector3 size = bounds.size; px = center.x - (px - 0.5) * size.x - api.transform.position.x; pz = center.z + (pz - 0.5) * size.z - api.transform.position.z; } Vector3 oldPosition = instance.transform.localPosition; float y = 0; if (OnlineMapsControlBase.instance is OnlineMapsTileSetControl) { OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance; y = control.GetElevationValue((float)px, (float)pz, control.GetBestElevationYScale(tlx, tly, brx, bry), tlx, tly, brx, bry); } Vector3 newPosition = new Vector3((float)px, y, (float)pz); instance.transform.localPosition = newPosition; if (oldPosition != newPosition && OnPositionChanged != null) { OnPositionChanged(this); } }
protected void InitLineMesh(List <Vector2> points, OnlineMapsTileSetControl control, out List <Vector3> verticles, out List <Vector3> normals, out List <int> triangles, out List <Vector2> uv, float weight, bool closed = false) { api.GetTopLeftPosition(out tlx, out tly); api.GetBottomRightPosition(out brx, out bry); if (brx < tlx) { brx += 360; } List <Vector2> localPoints = GetLocalPoints(points, closed); List <Vector2> activePoints = new List <Vector2>(); Rect mapRect = new Rect(0, 0, api.tilesetSize.x, api.tilesetSize.y); Vector2 lastPoint = Vector2.zero; Vector2 rightTop = new Vector2(api.tilesetSize.x, 0); Vector2 rightBottom = new Vector2(api.tilesetSize.x, api.tilesetSize.y); Vector2 leftBottom = new Vector2(0, api.tilesetSize.y); bestElevationYScale = control.GetBestElevationYScale(tlx, tly, brx, bry); verticles = new List <Vector3>(); normals = new List <Vector3>(); triangles = new List <int>(); uv = new List <Vector2>(); for (int i = 0; i < localPoints.Count; i++) { Vector2 p = localPoints[i]; if (lastPoint != Vector2.zero) { Vector2 crossTop, crossLeft, crossBottom, crossRight; bool hasCrossTop = OnlineMapsUtils.LineIntersection(lastPoint, p, Vector2.zero, rightTop, out crossTop); bool hasCrossBottom = OnlineMapsUtils.LineIntersection(lastPoint, p, leftBottom, rightBottom, out crossBottom); bool hasCrossLeft = OnlineMapsUtils.LineIntersection(lastPoint, p, Vector2.zero, leftBottom, out crossLeft); bool hasCrossRight = OnlineMapsUtils.LineIntersection(lastPoint, p, rightTop, rightBottom, out crossRight); List <Vector2> intersections = new List <Vector2>(); if (hasCrossTop) { intersections.Add(crossTop); } if (hasCrossBottom) { intersections.Add(crossBottom); } if (hasCrossLeft) { intersections.Add(crossLeft); } if (hasCrossRight) { intersections.Add(crossRight); } if (intersections.Count == 1) { activePoints.Add(intersections[0]); } else if (intersections.Count == 2) { int minIndex = ((lastPoint - intersections[0]).magnitude < (lastPoint - intersections[1]).magnitude)? 0: 1; activePoints.Add(intersections[minIndex]); activePoints.Add(intersections[1 - minIndex]); } } if (mapRect.Contains(p)) { activePoints.Add(p); } else if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref verticles, ref normals, ref triangles, ref uv, weight); } lastPoint = p; } if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref verticles, ref normals, ref triangles, ref uv, weight); } }
void Update() { const float maxTilt = 50; OnlineMaps api = OnlineMaps.instance; OnlineMapsTileSetControl control = OnlineMapsTileSetControl.instance; if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.A)) { tilt -= Time.deltaTime * tiltSpeed * maxTilt; } else if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.D)) { tilt += Time.deltaTime * tiltSpeed * maxTilt; } else if (tilt != 0) { float tiltOffset = Time.deltaTime * tiltSpeed * maxTilt; if (Mathf.Abs(tilt) > tiltOffset) { tilt -= tiltOffset * Mathf.Sign(tilt); } else { tilt = 0; } } tilt = Mathf.Clamp(tilt, -maxTilt, maxTilt); container.transform.localRotation = Quaternion.Euler(tilt, 0, 0); if (tilt != 0) { transform.Rotate(Vector3.up, tilt * rotateSpeed * Time.deltaTime); } double tlx, tly, brx, bry, dx, dy; api.GetTopLeftPosition(out tlx, out tly); api.GetBottomRightPosition(out brx, out bry); OnlineMapsUtils.DistanceBetweenPoints(tlx, tly, brx, bry, out dx, out dy); double mx = (brx - tlx) / dx; double my = (tly - bry) / dy; double v = (double)speed * Time.deltaTime / 3600.0; double ox = mx * v * Math.Cos(transform.rotation.eulerAngles.y * OnlineMapsUtils.Deg2Rad); double oy = my * v * Math.Sin((360 - transform.rotation.eulerAngles.y) * OnlineMapsUtils.Deg2Rad); px += ox; py += oy; api.SetPosition(px, py); Vector3 pos = transform.position; pos.y = altitude * control.GetBestElevationYScale(tlx, tly, brx, bry) * control.elevationScale; transform.position = pos; Camera.main.transform.position = transform.position - transform.rotation * cameraOffset; Camera.main.transform.LookAt(transform); }
/// <summary> /// Updates marker instance. /// </summary> /// <param name="tlx">Longitude of top-left corner of the map</param> /// <param name="tly">Latitude of top-left corner of the map</param> /// <param name="brx">Longitude of botton-right corner of the map</param> /// <param name="bry">Latitude of botton-right corner of the map</param> /// <param name="zoom">Zoom of the map</param> public override void Update(double tlx, double tly, double brx, double bry, int zoom) { if (!enabled) { return; } if (instance == null) { Init(map.transform); } if (control == null) { control = OnlineMapsControlBase3D.instance; } if (!range.InRange(zoom)) { visible = false; } else if (checkMapBoundaries) { if (latitude > tly || latitude < bry) { visible = false; } else if (tlx < brx && (longitude < tlx || longitude > brx)) { visible = false; } else if (tlx > brx && longitude < tlx && longitude > brx) { visible = false; } else { visible = true; } } else { visible = true; } if (!visible) { return; } if (_prefab != prefab) { Reinit(tlx, tly, brx, bry, zoom); } double mx, my; map.projection.CoordinatesToTile(longitude, latitude, zoom, out mx, out my); double ttlx, ttly, tbrx, tbry; map.projection.CoordinatesToTile(tlx, tly, zoom, out ttlx, out ttly); map.projection.CoordinatesToTile(brx, bry, zoom, out tbrx, out tbry); int maxX = 1 << zoom; Bounds bounds = control.cl.bounds; double sx = tbrx - ttlx; double mpx = mx - ttlx; if (sx < 0) { sx += maxX; } if (checkMapBoundaries) { if (mpx < 0) { mpx += maxX; } } else { double dx1 = Math.Abs(mpx - ttlx); double dx2 = Math.Abs(mpx - tbrx); double dx3 = Math.Abs(mpx - tbrx + maxX); if (dx1 > dx2 && dx1 > dx3) { mpx += maxX; } } double px = mpx / sx; double pz = (ttly - my) / (ttly - tbry); _relativePosition = new Vector3((float)px, 0, (float)pz); OnlineMapsTileSetControl tsControl = OnlineMapsTileSetControl.instance; if (tsControl != null) { px = -map.tilesetSize.x / 2 - (px - 0.5) * map.tilesetSize.x; pz = map.tilesetSize.y / 2 + (pz - 0.5) * map.tilesetSize.y; } else { Vector3 center = bounds.center; Vector3 size = bounds.size; px = center.x - (px - 0.5) * size.x / map.transform.lossyScale.x - map.transform.position.x; pz = center.z + (pz - 0.5) * size.z / map.transform.lossyScale.z - map.transform.position.z; } Vector3 oldPosition = instance.transform.localPosition; float y = 0; if (altitude.HasValue) { float yScale = control.GetBestElevationYScale(tlx, tly, brx, bry); y = altitude.Value * yScale; if (tsControl != null) { if (tsControl.elevationBottomMode == OnlineMapsTileSetControl.ElevationBottomMode.minValue) { y -= tsControl.elevationMinValue * yScale; } y *= tsControl.elevationScale; } } else if (tsControl != null) { y = tsControl.GetElevationValue((float)px, (float)pz, tsControl.GetBestElevationYScale(tlx, tly, brx, bry), tlx, tly, brx, bry); } Vector3 newPosition = new Vector3((float)px, y, (float)pz); if (oldPosition != newPosition) { instance.transform.localPosition = newPosition; //if (OnPositionChanged != null) OnPositionChanged(this); } }
protected void InitLineMesh(List<Vector2> points, OnlineMapsTileSetControl control, out List<Vector3> verticles, out List<Vector3> normals, out List<int> triangles, out List<Vector2> uv, float weight, bool closed = false) { api.GetTopLeftPosition(out tlx, out tly); api.GetBottomRightPosition(out brx, out bry); if (brx < tlx) brx += 360; List<Vector2> localPoints = GetLocalPoints(points, closed); List<Vector2> activePoints = new List<Vector2>(); Rect mapRect = new Rect(0, 0, api.tilesetSize.x, api.tilesetSize.y); Vector2 lastPoint = Vector2.zero; Vector2 rightTop = new Vector2(api.tilesetSize.x, 0); Vector2 rightBottom = new Vector2(api.tilesetSize.x, api.tilesetSize.y); Vector2 leftBottom = new Vector2(0, api.tilesetSize.y); bestElevationYScale = control.GetBestElevationYScale(tlx, tly, brx, bry); verticles = new List<Vector3>(); normals = new List<Vector3>(); triangles = new List<int>(); uv = new List<Vector2>(); for (int i = 0; i < localPoints.Count; i++) { Vector2 p = localPoints[i]; if (lastPoint != Vector2.zero) { Vector2 crossTop, crossLeft, crossBottom, crossRight; bool hasCrossTop = OnlineMapsUtils.LineIntersection(lastPoint, p, Vector2.zero, rightTop, out crossTop); bool hasCrossBottom = OnlineMapsUtils.LineIntersection(lastPoint, p, leftBottom, rightBottom, out crossBottom); bool hasCrossLeft = OnlineMapsUtils.LineIntersection(lastPoint, p, Vector2.zero, leftBottom, out crossLeft); bool hasCrossRight = OnlineMapsUtils.LineIntersection(lastPoint, p, rightTop, rightBottom, out crossRight); List<Vector2> intersections = new List<Vector2>(); if (hasCrossTop) intersections.Add(crossTop); if (hasCrossBottom) intersections.Add(crossBottom); if (hasCrossLeft) intersections.Add(crossLeft); if (hasCrossRight) intersections.Add(crossRight); if (intersections.Count == 1) activePoints.Add(intersections[0]); else if (intersections.Count == 2) { int minIndex = ((lastPoint - intersections[0]).magnitude < (lastPoint - intersections[1]).magnitude)? 0: 1; activePoints.Add(intersections[minIndex]); activePoints.Add(intersections[1 - minIndex]); } } if (mapRect.Contains(p)) activePoints.Add(p); else if (activePoints.Count > 0) DrawActivePoints(control, ref activePoints, ref verticles, ref normals, ref triangles, ref uv, weight); lastPoint = p; } if (activePoints.Count > 0) DrawActivePoints(control, ref activePoints, ref verticles, ref normals, ref triangles, ref uv, weight); }
protected void InitLineMesh(IEnumerable points, OnlineMapsTileSetControl control, ref List <Vector3> vertices, ref List <Vector3> normals, ref List <int> triangles, ref List <Vector2> uv, float width, bool closed = false, bool optimize = true) { api.buffer.GetCorners(out tlx, out tly, out brx, out bry); if (brx < tlx) { brx += 360; } List <Vector2> localPoints = GetLocalPoints(points, closed, optimize); List <Vector2> activePoints = new List <Vector2>(localPoints.Count); float lastPointX = 0; float lastPointY = 0; float sizeX = api.tilesetSize.x; float sizeY = api.tilesetSize.y; bestElevationYScale = control.GetBestElevationYScale(tlx, tly, brx, bry); if (vertices == null) { vertices = new List <Vector3>(Mathf.Max(Mathf.NextPowerOfTwo(localPoints.Count * 4), 32)); } else { vertices.Clear(); } if (normals == null) { normals = new List <Vector3>(vertices.Capacity); } else { normals.Clear(); } if (triangles == null) { triangles = new List <int>(Mathf.Max(Mathf.NextPowerOfTwo(localPoints.Count * 6), 32)); } else { triangles.Clear(); } if (uv == null) { uv = new List <Vector2>(triangles.Capacity); } else { uv.Clear(); } Vector2[] intersections = new Vector2[4]; for (int i = 0; i < localPoints.Count; i++) { Vector2 p = localPoints[i]; float px = p.x; float py = p.y; int countIntersections = 0; if (i > 0 && checkMapBoundaries) { float crossTopX, crossTopY, crossLeftX, crossLeftY, crossBottomX, crossBottomY, crossRightX, crossRightY; bool hasCrossTop = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, 0, sizeX, 0, out crossTopX, out crossTopY); bool hasCrossBottom = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, sizeY, sizeX, sizeY, out crossBottomX, out crossBottomY); bool hasCrossLeft = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, 0, 0, sizeY, out crossLeftX, out crossLeftY); bool hasCrossRight = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, sizeX, 0, sizeX, sizeY, out crossRightX, out crossRightY); if (hasCrossTop) { intersections[0] = new Vector2(crossTopX, crossTopY); countIntersections++; } if (hasCrossBottom) { intersections[countIntersections] = new Vector2(crossBottomX, crossBottomY); countIntersections++; } if (hasCrossLeft) { intersections[countIntersections] = new Vector2(crossLeftX, crossLeftY); countIntersections++; } if (hasCrossRight) { intersections[countIntersections] = new Vector2(crossRightX, crossRightY); countIntersections++; } if (countIntersections == 1) { activePoints.Add(intersections[0]); } else if (countIntersections == 2) { Vector2 lastPoint = new Vector2(lastPointX, lastPointY); int minIndex = (lastPoint - intersections[0]).sqrMagnitude < (lastPoint - intersections[1]).sqrMagnitude? 0: 1; activePoints.Add(intersections[minIndex]); activePoints.Add(intersections[1 - minIndex]); } } if (!checkMapBoundaries || px >= 0 && py >= 0 && px <= sizeX && py <= sizeY) { activePoints.Add(p); } else if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref triangles, ref uv, width); } lastPointX = px; lastPointY = py; } if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref vertices, ref normals, ref triangles, ref uv, width); } }
protected void InitLineMesh(IEnumerable points, OnlineMapsTileSetControl control, out List <Vector3> verticles, out List <Vector3> normals, out List <int> triangles, out List <Vector2> uv, float weight, bool closed = false) { api.GetCorners(out tlx, out tly, out brx, out bry); if (brx < tlx) { brx += 360; } List <Vector2> localPoints = GetLocalPoints(points, closed); List <Vector2> activePoints = new List <Vector2>(localPoints.Count); float lastPointX = 0; float lastPointY = 0; float sizeX = api.tilesetSize.x; float sizeY = api.tilesetSize.y; bestElevationYScale = control.GetBestElevationYScale(tlx, tly, brx, bry); verticles = new List <Vector3>(localPoints.Count * 4); normals = new List <Vector3>(localPoints.Count * 4); triangles = new List <int>(localPoints.Count * 6); uv = new List <Vector2>(localPoints.Count * 6); Vector2[] intersections = new Vector2[4]; for (int i = 0; i < localPoints.Count; i++) { Vector2 p = localPoints[i]; float px = p.x; float py = p.y; int countIntersections = 0; if (i > 0) { float crossTopX, crossTopY, crossLeftX, crossLeftY, crossBottomX, crossBottomY, crossRightX, crossRightY; bool hasCrossTop = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, 0, sizeX, 0, out crossTopX, out crossTopY); bool hasCrossBottom = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, sizeY, sizeX, sizeY, out crossBottomX, out crossBottomY); bool hasCrossLeft = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, 0, 0, 0, sizeY, out crossLeftX, out crossLeftY); bool hasCrossRight = OnlineMapsUtils.LineIntersection(lastPointX, lastPointY, px, py, sizeX, 0, sizeX, sizeY, out crossRightX, out crossRightY); if (hasCrossTop) { intersections[0] = new Vector2(crossTopX, crossTopY); countIntersections++; } if (hasCrossBottom) { intersections[countIntersections] = new Vector2(crossBottomX, crossBottomY); countIntersections++; } if (hasCrossLeft) { intersections[countIntersections] = new Vector2(crossLeftX, crossLeftY); countIntersections++; } if (hasCrossRight) { intersections[countIntersections] = new Vector2(crossRightX, crossRightY); countIntersections++; } if (countIntersections == 1) { activePoints.Add(intersections[0]); } else if (countIntersections == 2) { Vector2 lastPoint = new Vector2(lastPointX, lastPointY); int minIndex = (lastPoint - intersections[0]).magnitude < (lastPoint - intersections[1]).magnitude? 0: 1; activePoints.Add(intersections[minIndex]); activePoints.Add(intersections[1 - minIndex]); } } if (px >= 0 && py >= 0 && px <= sizeX && py <= sizeY) { activePoints.Add(p); } else if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref verticles, ref normals, ref triangles, ref uv, weight); } lastPointX = px; lastPointY = py; } if (activePoints.Count > 0) { DrawActivePoints(control, ref activePoints, ref verticles, ref normals, ref triangles, ref uv, weight); } }