<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — Some problem extending the horizon]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=1162</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=1162&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Some problem extending the horizon.]]></description>
		<lastBuildDate>Thu, 08 Aug 2019 19:02:01 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5425#p5425</link>
			<description><![CDATA[<p>Interesting effect.</p><p>Unfortunately, it is very difficult to say what is wrong without debugging.<br />It looks like you are calculating the difference too early.<br />Try this way:<br /></p><div class="codebox"><pre><code>private bool waitUpdated = false;

OnlineMaps.instance.OnChangePosition += OnMapPan;

void OnMapPan()
{
    if (!waitUpdated) 
    {
        OnlineMaps.instance.OnMapUpdated += OnMapUpdated;
        waitUpdated = true;
    }
}

void OnMapUpdated()
{
    OnlineMaps.instance.OnMapUpdated -= OnMapUpdated;
    waitUpdated = false;

    // Prev OnMapPan content
}</code></pre></div><br /><p>If the problem persists, send me your project.<br />I will try to find the cause of the problem.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 08 Aug 2019 19:02:01 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5425#p5425</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5422#p5422</link>
			<description><![CDATA[<p>Hello, I&#039;m using your 1st tip (calculate the offset for the first point, and apply this offset for the remaining points) when the map is moved, but I have a problem: on top view it seem ok, but tilting the map it&#039;s evident that the elevation of the points is not correctly calculated.</p><p>This is a video to show you what I mean (from second 10)<br /><a href="https://vr.alicefit.com/ice_video_20190808-192152.webm">https://vr.alicefit.com/ice_video_20190808-192152.webm</a></p><p>I&#039;ve seen that also just panning the map I get &quot;OnElevationUpdated&quot; at the end of the movement (that&#039;s why when I release the mouse the track get correctly calculated).<br />So I have idea that this 1st tip cannot be used... I&#039;m doing it wrong?</p><p>This is my code (p.s. I&#039;m still using Vectrosity but this is not the issue, because if moving the map I call &quot;UpdateLine&quot;, just like with &quot;OnChangeZoom&quot; and with &quot;OnElevationUpdated&quot;, it work.</p><p>private void Start()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMaps.instance.OnChangeZoom += UpdateLine;<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMaps.instance.OnChangePosition += OnMapPan;<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMapsElevationManagerBase.instance.OnElevationUpdated += UpdateLine;<br />&nbsp; &nbsp; }</p><p>....</p><p>void OnMapPan()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ///Get the distance difference only for the 1st point<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector3 oldPos = _convertedWordlPositionsToList[0];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector2 firstCoord = _coords[0];<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector3 newPos = GetWorldPositionFromCoordinates(firstCoord);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector3 difference = newPos - oldPos;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ///Apply the difference to all points<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int ii = 0; ii &lt; _convertedWordlPositionsToList.Count; ii++)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; _convertedWordlPositionsToList[ii] += difference;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ///Update line<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myLine.points3 = _convertedWordlPositionsToList;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; myLine.Draw3D();<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; }</p><br /><p>void UpdateLine()<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; _convertedWordlPositionsToList = GetWorldPositionsFromCoordinates(_coords);<br />&nbsp; &nbsp; &nbsp; &nbsp; myLine.points3 = _convertedWordlPositionsToList;<br />&nbsp; &nbsp; &nbsp; &nbsp; myLine.Draw3D();<br />&nbsp; &nbsp; }</p>]]></description>
			<author><![CDATA[null@example.com (danielesuppo)]]></author>
			<pubDate>Thu, 08 Aug 2019 17:56:55 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5422#p5422</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5386#p5386</link>
			<description><![CDATA[<p>If you use these methods every time the map is updated, you will most likely have performance problems.<br />Here you need to use some optimization trick, for example:<br />You do a full update of the track only when updating elevations and changing the zoom, and when moving the map, you simply calculate the offset for the first point, and apply this offset for the remaining points.</p><p>It can also help:<br />- Track optimization (reducing the number of points).<br />- Caching values that are used in calculations.<br />- The use of overloaded methods, with a large number of parameters.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Wed, 31 Jul 2019 22:24:13 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5386#p5386</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5382#p5382</link>
			<description><![CDATA[<p>Thank-you!!<br />Do all these methods (GetWorldPosition, GetElevation, etc) require a lot more of CPU than just to use GetWorldPositionWithElevation?</p><p>(Since I call GetWorldPositionsFromHorizon for each vertex in my track line when the map is panned or zoomed I&#039;m worrying about performance issue)</p>]]></description>
			<author><![CDATA[null@example.com (danielesuppo)]]></author>
			<pubDate>Wed, 31 Jul 2019 15:12:39 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5382#p5382</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5379#p5379</link>
			<description><![CDATA[<p>Because elevation != position.y.<br />How to calculate position.y:<br /></p><div class="codebox"><pre><code>float elevationScale = OnlineMapsElevationManagerBase.GetBestElevationYScale(tlx, tly, brx, bry);

float elevationOffset = 0;
if (OnlineMapsElevationManagerBase.isActive &amp;&amp; OnlineMapsElevationManagerBase.instance.bottomMode == OnlineMapsElevationBottomMode.minValue)
{
    elevationOffset = OnlineMapsElevationManagerBase.instance.GetMinElevation(1);
}

position.y = (elevation - elevationOffset) * elevationScale;</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 30 Jul 2019 18:00:35 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5379#p5379</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5374#p5374</link>
			<description><![CDATA[<p>Hello,<br />I&#039;m using your script to get the elevation from the horizon but I have some issue... the points are much more over the map and the horizon, them fly in the sky.</p><p>I use this function to get XZ position, and next Y position from an array of longLat:</p><p>private Vector3[] GetWorldPositionsFromHorizon(Vector2[] _coords)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; Vector3[] positions = new Vector3[_coords.Length];</p><p>&nbsp; &nbsp; &nbsp; &nbsp; for (int ii = 0; ii &lt; _coords.Length; ii++)<br />&nbsp; &nbsp; &nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ///Get X-Z position<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector3 flatPosition = OnlineMapsTileSetControl.instance.GetWorldPosition<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (_coords[ii]);</p><p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ///Get Y position (elevation)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; float elevation = GetElevationFromHorizon.instance.GetElevation(_coords[ii]);<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; positions[ii] = new Vector3(flatPosition.x, elevation, flatPosition.z);<br />&nbsp; &nbsp; &nbsp; &nbsp; }<br />&nbsp; &nbsp; &nbsp; &nbsp; return positions;<br />&nbsp; &nbsp; }</p><p>And your script just a little modified because I already have the longitude latitude of my point:</p><p> public float GetElevation(Vector2 longLat)<br />&nbsp; &nbsp; {<br />&nbsp; &nbsp; &nbsp; &nbsp; double lng = longLat.x;<br />&nbsp; &nbsp; &nbsp; &nbsp; double lat = longLat.y;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; float elevation = 0;<br />&nbsp; &nbsp; &nbsp; &nbsp; if (GetElevationFromTile(lng, lat, ref elevation)) return elevation;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; if (Horizon2_BingMaps.overviewElevation == null) return 0;</p><p>&nbsp; &nbsp; &nbsp; &nbsp; double mx = lng, my = lat;<br />&nbsp; &nbsp; &nbsp; &nbsp; OnlineMapsUtils.LatLongToMercat(ref mx, ref my);<br />&nbsp; &nbsp; &nbsp; &nbsp; elevation = Horizon2_BingMaps.overviewElevation.GetElevation(mx, my);<br />&nbsp; &nbsp; &nbsp; &nbsp; return elevation;<br />&nbsp; &nbsp; }</p><br /><p>As you can see in the attached picture in top view (orthographic) the shape created with my points is ok, so X and Z are right.<br />The elevation (Y) is wrong</p>]]></description>
			<author><![CDATA[null@example.com (danielesuppo)]]></author>
			<pubDate>Tue, 30 Jul 2019 12:22:15 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5374#p5374</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5231#p5231</link>
			<description><![CDATA[<p>Yes, it is, because this script already controls elevations of the map.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 25 Jun 2019 18:53:52 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5231#p5231</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5228#p5228</link>
			<description><![CDATA[<p>Thank-you!<br />So if I well understand I can use &quot;GetElevation&quot; from this class, in place of &quot;GetWorldPositionWithElevation&quot;, for every object I want to get elevation, for both objects onto the Map and objects onto the Horizon, isn&#039;t it?</p>]]></description>
			<author><![CDATA[null@example.com (danielesuppo)]]></author>
			<pubDate>Tue, 25 Jun 2019 12:04:02 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5228#p5228</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5200#p5200</link>
			<description><![CDATA[<p>1. This is the specificity of the script.<br />This is not to optimize, but to simplify the script.<br />As it is, you cannot say - I want to have a front tile.</p><p>2. Something like this:<br /></p><div class="codebox"><pre><code>using UnityEngine;

public class GetElevationFromHorizon : MonoBehaviour
{
    public Horizon2_BingMaps horizon;
    private OnlineMaps map;
    private OnlineMapsTileSetControl control;

    private void Start()
    {
        map = OnlineMaps.instance;
        control = OnlineMapsTileSetControl.instance;
    }

    private void Update()
    {
        Vector2 size = control.sizeInScene;
        float el = GetElevation(new Vector3(size.x / -2, 0, size.y / 2));
        Debug.Log(el);
    }

    private float GetElevation(Vector3 pos)
    {
        double lng, lat;
        control.GetCoordsByWorldPosition(out lng, out lat, pos);

        float elevation = 0;
        if (GetElevationFromTile(lng, lat, ref elevation)) return elevation;

        if (Horizon2_BingMaps.overviewElevation == null) return 0;

        double mx = lng, my = lat;
        OnlineMapsUtils.LatLongToMercat(ref mx, ref my);
        elevation = Horizon2_BingMaps.overviewElevation.GetElevation(mx, my);
        return elevation;
    }

    private bool GetElevationFromTile(double lng, double lat, ref float elevation)
    {
        double tx, ty;
        int zoom = map.zoom - horizon.zoomOffset;
        map.projection.CoordinatesToTile(lng, lat, zoom, out tx, out ty);
        OnlineMapsTile tile = OnlineMapsTile.GetTile(zoom, (int) tx, (int) ty);
        if (tile == null) return false;
        Horizon2_BingMaps.CData data = tile[&quot;cdata&quot;] as Horizon2_BingMaps.CData;
        if (data == null) return false;
        if (!data.hasData) return false;
        elevation = data.GetElevation(tx, ty);
        return true;
    }
}</code></pre></div><p>P.S. Make Horizon2_BingMaps.overviewElevation as internal.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 18 Jun 2019 00:11:43 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5200#p5200</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5198#p5198</link>
			<description><![CDATA[<p>1 - I&#039;ve partially solved this issue increasing count to 5x5</p>]]></description>
			<author><![CDATA[null@example.com (danielesuppo)]]></author>
			<pubDate>Mon, 17 Jun 2019 18:28:07 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5198#p5198</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5197#p5197</link>
			<description><![CDATA[<p>Thanks a lot for your effort, it work!<br />I&#039;d have just 2 more question: </p><p>1 - is there a way to tell the script at which distance from the camera the horizon should appear?<br />I try to explain better: in some situations the script create more horizon tiles on the back of the camera, and not in front.<br />As a result panning the Camera the orizon disappear, but as you move forward a little the new horizon tile appear (see pict in attachment).<br />I think that&#039;s some kind of optimization, so I&#039;m wondering if it is possible to tell (&quot;hey, I always want an horizon tile in front of the Camera... or something like that)</p><p>2 - Is it possible to get the elevation on the horizon tiles ? I have a very long path, and the piece of the path that is outside of the map does not get elevation</p><p>Many thanks!</p>]]></description>
			<author><![CDATA[null@example.com (danielesuppo)]]></author>
			<pubDate>Mon, 17 Jun 2019 14:40:59 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5197#p5197</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5152#p5152</link>
			<description><![CDATA[<p>nice <br />thank youuuuuuuu</p>]]></description>
			<author><![CDATA[null@example.com (Amen)]]></author>
			<pubDate>Fri, 14 Jun 2019 14:34:28 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5152#p5152</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5149#p5149</link>
			<description><![CDATA[<p>Hello.</p><p>Something like that.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Fri, 14 Jun 2019 09:40:03 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5149#p5149</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5148#p5148</link>
			<description><![CDATA[<p>Hi, There is&nbsp; a script using ArcGIS for horizon elevation ? Thank you</p>]]></description>
			<author><![CDATA[null@example.com (Amen)]]></author>
			<pubDate>Fri, 14 Jun 2019 08:29:51 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5148#p5148</guid>
		</item>
		<item>
			<title><![CDATA[Re: Some problem extending the horizon]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=5114#p5114</link>
			<description><![CDATA[<p>It was difficult, but it seems like I made it work.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Sun, 09 Jun 2019 11:47:18 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=5114#p5114</guid>
		</item>
	</channel>
</rss>
