<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Drawing "3D" line between 3D markers]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=917&amp;type=atom" />
	<updated>2018-10-19T21:11:58Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=917</id>
		<entry>
			<title type="html"><![CDATA[Re: Drawing "3D" line between 3D markers]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4060#p4060" />
			<content type="html"><![CDATA[<p>I manage to modify your example to fit my needs, and it&#039;s working <img src="https://forum.infinity-code.com/img/smilies/smile.png" width="15" height="15" alt="smile" /></p><p>Thanks a lot, as i wasn&#039;t so close after all. Having the lineRenderer directly on my marker wasn&#039;t such a good idea and it&#039;s much more simple with your solution. </p><p>Thank you Alex, you have helped me a lot over the past 2 days. Hopefully i will progress &amp; get more familiar with this asset to stop bothering you every day <img src="https://forum.infinity-code.com/img/smilies/big_smile.png" width="15" height="15" alt="big_smile" /></p>]]></content>
			<author>
				<name><![CDATA[Thibault]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=821</uri>
			</author>
			<updated>2018-10-19T21:11:58Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4060#p4060</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Drawing "3D" line between 3D markers]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4059#p4059" />
			<content type="html"><![CDATA[<p>Thanks for your response.</p><p>I tried on my own for a couple hours and i almost achieve it.</p><p>* i&#039;ve got a lineRenderer component attached to my 3D marker<br />* each time i change the position of the marker, i add the new position to my lineRenderer.</p><p>But i&#039;m struggling with a curious offset. My lineRenderer is drawn at a certain distance of where it should be. </p><p>I made a Gif to show this strange behaviour : </p><p><a href="https://gph.is/2R1GjXp">https://gph.is/2R1GjXp</a></p><p>Quality is not great, but you should see that the line are renderer like 50 meters from my marker.<br />On the bright side the LineRenderer positions follow the map movement now <img src="https://forum.infinity-code.com/img/smilies/tongue.png" width="15" height="15" alt="tongue" /></p><p>Initiating the LineRenderer : </p><p>LineRenderer LR = marker.instance.AddComponent&lt;LineRenderer&gt;();<br />LR.useWorldSpace = false;<br />LR.positionCount = 0;</p><p>Adding a position (each time i move my marker):</p><p>LineRenderer LR = droneMarker.instance.GetComponent&lt;LineRenderer&gt;();<br />LR.positionCount++;<br />LR.SetPosition(LR.positionCount - 1, droneMarker.transform.position);</p><p>What am i doing wrong ? <br />Is it a problem like: the transform is Vector3 with float, but the marker position was set with double, so i get an offset because of the precision lost ?</p><p>I will look at your example now. Am i supposed to attach it to the Map GameObject ?</p>]]></content>
			<author>
				<name><![CDATA[Thibault]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=821</uri>
			</author>
			<updated>2018-10-19T19:59:38Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4059#p4059</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Drawing "3D" line between 3D markers]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4058#p4058" />
			<content type="html"><![CDATA[<p>Hello.</p><p>Yes, I think for your case it is better to use LineRenderer.<br />Should LineRenderer be inside the marker or not, it depends on many things.<br />But in most cases it is better to have it outside the marker.<br />I made a small example.<br />At least it&#039;s something where you can begin.</p><div class="codebox"><pre><code>using UnityEngine;

public class DrawLineRendererLine : MonoBehaviour
{
    public GameObject prefab;
    private LineRenderer lineRenderer;
    private OnlineMapsMarker3D marker1;
    private OnlineMapsMarker3D marker2;
    private OnlineMapsTileSetControl control;
    private OnlineMaps map;

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

        marker1 = control.AddMarker3D(Vector2.zero, prefab);
        marker2 = control.AddMarker3D(Vector2.one, prefab);

        GameObject go = new GameObject(&quot;Line&quot;);
        lineRenderer = go.AddComponent&lt;LineRenderer&gt;();
        lineRenderer.widthCurve = AnimationCurve.Constant(0, 1, 10);
        lineRenderer.positionCount = 2;

        UpdateLineRenderer();

        control.OnMeshUpdated += OnMeshUpdated;
    }

    private Vector3 GetWorldPositionWithAltitude(OnlineMapsMarker3D marker)
    {
        double lng, lat;
        marker.GetPosition(out lng, out lat);

        double tlx, tly, brx, bry;
        map.GetCorners(out tlx, out tly, out brx, out bry);

        Vector3 p;

        if (marker.altitude.HasValue)
        {
            p = OnlineMapsTileSetControl.instance.GetWorldPosition(lng, lat);
            float yScale = control.GetBestElevationYScale(tlx, tly, brx, bry);
            p.y = marker.altitude.Value * yScale;
            if (control.elevationBottomMode == OnlineMapsTileSetControl.ElevationBottomMode.minValue) p.y -= control.elevationMinValue * yScale;
            p.y *= control.elevationScale;
        }
        else p = OnlineMapsTileSetControl.instance.GetWorldPositionWithElevation(lng, lat, tlx, tly, brx, bry);

        return p;
    }

    private void OnMeshUpdated()
    {
        UpdateLineRenderer();
    }

    private void UpdateLineRenderer()
    {
        lineRenderer.SetPositions(new[]
        {
            GetWorldPositionWithAltitude(marker1),
            GetWorldPositionWithAltitude(marker2),
        });
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2018-10-19T19:10:44Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4058#p4058</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Drawing "3D" line between 3D markers]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=4057#p4057" />
			<content type="html"><![CDATA[<p>Hi</p><p>I want to draw lines between a succession of OnlineMapsMarker3D which are the previous position of a plane.</p><p>OnlineMapsDrawingLine doesn&#039;t seems to be the right tool since i want 3D lines (altitude is important). </p><p>What is the best option ? Should i use LineRenderer ?</p><p>In that case, how to proceed to benefit of the map transformation ? I mean should my lineRenderer be a component of an OnlineMapsMarker3D? Will this be enough ?</p><p>I&#039;m curious to know the best options to achieve this goal. I didn&#039;t find answers in the atlas of examples. I&#039;m still a beginner with this awesome asset, any help will be appreciated ;D</p><p>Thanks<br />Thibault</p>]]></content>
			<author>
				<name><![CDATA[Thibault]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=821</uri>
			</author>
			<updated>2018-10-19T15:59:39Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=4057#p4057</id>
		</entry>
</feed>
