<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — RWT generated mesh not hovering correctly map]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2082&amp;type=atom" />
	<updated>2023-01-26T15:45:58Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=2082</id>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8861#p8861" />
			<content type="html"><![CDATA[<p>Great Alex, Thanks a lot!</p>]]></content>
			<author>
				<name><![CDATA[Loryer]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=561</uri>
			</author>
			<updated>2023-01-26T15:45:58Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8861#p8861</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8856#p8856" />
			<content type="html"><![CDATA[<p>You have broken proportions.<br />I updated the script in post #2 to handle the situation when the terrain is not square.<br />Here is a video on how to match them in this case:<br /><a href="https://www.dropbox.com/s/y5fz2saf78eqskt/Online%20Maps%20Match%20RWT%202.mp4?dl=0">https://www.dropbox.com/s/y5fz2saf78eqs … 2.mp4?dl=0</a></p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-01-26T12:01:24Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8856#p8856</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8852#p8852" />
			<content type="html"><![CDATA[<p>Ok, i have loaded video on my cloud.<br />If you need upload other material you can use it.</p><p><a href="https://cloud.cetena.it/s/JQ9WCdaQLBYr0Vt">https://cloud.cetena.it/s/JQ9WCdaQLBYr0Vt</a></p>]]></content>
			<author>
				<name><![CDATA[Loryer]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=561</uri>
			</author>
			<updated>2023-01-26T11:09:58Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8852#p8852</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8848#p8848" />
			<content type="html"><![CDATA[<p>I dont know. Please attach a video of how you do it. I will check it.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-01-25T17:03:48Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8848#p8848</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8846#p8846" />
			<content type="html"><![CDATA[<p>Rusult_Overlay03</p>]]></content>
			<author>
				<name><![CDATA[Loryer]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=561</uri>
			</author>
			<updated>2023-01-25T11:27:27Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8846#p8846</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8845#p8845" />
			<content type="html"><![CDATA[<p>Rusult_Overlay02</p>]]></content>
			<author>
				<name><![CDATA[Loryer]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=561</uri>
			</author>
			<updated>2023-01-25T11:26:16Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8845#p8845</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8844#p8844" />
			<content type="html"><![CDATA[<p>Rusult_Overlay01</p>]]></content>
			<author>
				<name><![CDATA[Loryer]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=561</uri>
			</author>
			<updated>2023-01-25T11:24:48Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8844#p8844</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8843#p8843" />
			<content type="html"><![CDATA[<p>Thanks for your help man!</p><p>I created a new project and installed the assets from scratch.<br />I generated a terrain and created a map with default settings.<br />I added your script to the map and went play.<br />Attached is the result obtained (result_overlay01, result_overlay02, result_overlay03).<br />As you can see the map looks stretched and rotated. From your video everything seemed to be correct, what went wrong?</p><p>An other question, in order to cover the size of the example terrain whose data I previously sent you with the OnlineMaps map, I need to increase the pixel dimensions of the map to 16K because otherwise the resolution of the map is too low and I cannot read the written.<br />Is it correct to increase that parameter to obtain this result?</p><p>Thanks so much for your patience</p>]]></content>
			<author>
				<name><![CDATA[Loryer]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=561</uri>
			</author>
			<updated>2023-01-25T10:09:39Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8843#p8843</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8842#p8842" />
			<content type="html"><![CDATA[<p>How I did it:<br />I used a modified version of the script from post #2 where I added the map to the scene in the same place as the terrain so they overlap. <br />I changed the terrain material to make it transparent.<br />The script calculates the center position quite well, and I just need to tweak the zoom a bit.</p><p>In most cases, replacing the terrain material is a bad idea because you won&#039;t be able to undo it. <br />It is better to change the transparency of the map.<br />I added this feature and updated the script in post #2.</p><p>How you need to do:<br />- Add a script to the map.<br />- Tileset / Materials &amp; Shaders / Tileset Shader - Tileset.<br />- Start the scene.<br />- Move the map up (y-axis) to draw the map first.<br />- Set top view and switch to Ortho projection.<br />- Adjust the zoom and save the map state.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-01-24T17:02:44Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8842#p8842</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8841#p8841" />
			<content type="html"><![CDATA[<p>Nice! Thanks for the video!<br />What did you do to make them match? Did you just tune the zoom slider after matching the center?</p><p>Do you think there is some kind of automation that i can use to do this?<br />I ask this because i need to make the same adjustment on like 30 different locations :S</p><p>To tune the zoom slider by moving it manually seems a pretty good compromise but i still need to match the center before doing that. Do you have some suggestions? Or is it still ok to use the script you sent me the other day?</p>]]></content>
			<author>
				<name><![CDATA[Loryer]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=561</uri>
			</author>
			<updated>2023-01-24T13:53:25Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8841#p8841</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8839#p8839" />
			<content type="html"><![CDATA[<p>I managed to make it match.<br />Here&#039;s a video:<br /><a href="https://www.dropbox.com/s/288783pb6ekwu6o/Online%20Maps%20Match%20RWT.mp4?dl=0">https://www.dropbox.com/s/288783pb6ekwu … T.mp4?dl=0</a></p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-01-23T18:37:35Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8839#p8839</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8838#p8838" />
			<content type="html"><![CDATA[<p>I&#039;m sending an image with the variables set on the 2 assets, as i stated before there is the zoom component for online maps which confuses me quite a lot and seems by tuning it the easiest way to make the 2 maps match.</p><p>Let me know <img src="https://forum.infinity-code.com/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></content>
			<author>
				<name><![CDATA[Loryer]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=561</uri>
			</author>
			<updated>2023-01-23T14:23:55Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8838#p8838</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8836#p8836" />
			<content type="html"><![CDATA[<p>Please attach the coordinates of your area boundaries in RWT. I will check it.</p>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-01-20T13:30:24Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8836#p8836</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8835#p8835" />
			<content type="html"><![CDATA[<p>Thanks for the answer and for the script.</p><p>What i wanted to make clear is that right now we are matching the map and the terrain by tuning the zoom slider on the map component. What i noticed is the fact the 2 representation aren&#039;t actually matching and the difference become greater as we move away from the center.<br />I started considering the possibility of the 2 modules using different projection methods (?), is this the case?</p><p>I attach a screenshot hoping to make clear what i&#039;m referring to.<br />The first 2 images show the differences, the third is the hovering from an high view point.</p>]]></content>
			<author>
				<name><![CDATA[Loryer]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=561</uri>
			</author>
			<updated>2023-01-20T10:05:05Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8835#p8835</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: RWT generated mesh not hovering correctly map]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=8830#p8830" />
			<content type="html"><![CDATA[<p>Hello.</p><p>For RWT, you can get the coordinate under the cursor with RealWorldTerrainMonoBase.GetCoordinatesUnderCursor.<br /><a href="http://infinity-code.com/doxygen/real-world-terrain/classInfinityCode_1_1RealWorldTerrain_1_1RealWorldTerrainMonoBase.html#ab9de374f907257376ff49bc9b337f452">http://infinity-code.com/doxygen/real-w … c9b337f452</a></p><p>For Online Maps, you can get the coordinate under the cursor using OnlineMapsControlBase.GetCoords.<br /><a href="https://infinity-code.com/doxygen/online-maps/classOnlineMapsControlBase.html#afb49b4ee032bba752f9b3bab8b006546">https://infinity-code.com/doxygen/onlin … ab8b006546</a></p><p>Unfortunately you don&#039;t have a way to automatically make map and terrain match.<br />You can implement some kind of algorithm (something like below), but it&#039;s still not ideal and will have a calculation error.<br /></p><div class="codebox"><pre><code>using System;
using System.Collections;
using InfinityCode.RealWorldTerrain;
using UnityEngine;

public class MatchTerrainSize : MonoBehaviour
{
    public RealWorldTerrainContainer container;

    [Range(0, 1)]
    public float mapAlpha = 1;

    private float _mapAlpha = 1;

    public static void GetCenterPointAndZoom(OnlineMaps map, IEnumerable positions, out OnlineMapsVector2d center, out float zoom, Vector2 inset = default(Vector2))
    {
        center = new OnlineMapsVector2d();
        zoom = OnlineMaps.MINZOOM;
        if (positions == null || map == null) return;

        double minX = double.MaxValue;
        double minY = double.MaxValue;
        double maxX = double.MinValue;
        double maxY = double.MinValue;

        int type = -1; // 0 - Vector2, 1 - OnlineMapsVector2d, 2 - marker2D, 3 - marker3d, 4 - float, 5 - double
        object prev = null;
        int pindex = -1;
        int vindex = 0;
        bool useTwoValues = false;

        foreach (object v in positions)
        {
            pindex++;

            if (type == -1)
            {
                if (v is Vector2) type = 0;
                else if (v is OnlineMapsVector2d) type = 1;
                else if (v is OnlineMapsMarker) type = 2;
                else if (v is OnlineMapsMarker3D) type = 3;
                else if (v is float) type = 4;
                else if (v is double) type = 5;
                else return;

                if (type &gt;= 4) useTwoValues = true;
            }

            if (useTwoValues &amp;&amp; pindex % 2 != 1)
            {
                prev = v;
                continue;
            }

            double lng = 0, lat = 0;

            if (type == 0)
            {
                Vector2 p = (Vector2)v;
                lng = p.x;
                lat = p.y;
            }
            else if (type == 1)
            {
                OnlineMapsVector2d p = (OnlineMapsVector2d)v;
                lng = p.x;
                lat = p.y;
            }
            else if (type == 2 || type == 3)
            {
                OnlineMapsMarkerBase p = v as OnlineMapsMarkerBase;
                p.GetPosition(out lng, out lat);
            }
            else if (type == 4)
            {
                lng = (float)prev;
                lat = (float)v;
            }
            else if (type == 5)
            {
                lng = (double)prev;
                lat = (double)v;
            }

            if (vindex &gt; 0)
            {
                double rx = lng - minX;
                if (rx &gt; 180) lng -= 360;
                else if (rx &lt; -180) lng += 360;
            }

            if (lng &lt; minX) minX = lng;
            if (lng &gt; maxX) maxX = lng;

            if (lat &lt; minY) minY = lat;
            if (lat &gt; maxY) maxY = lat;

            vindex++;
        }

        double sx = maxX - minX;
        double sy = maxY - minY;

        center = new OnlineMapsVector2d(sx / 2 + minX, sy / 2 + minY);

        if (center.x &lt; -180) center.x += 360;
        else if (center.x &gt; 180) center.x -= 360;

        if (vindex == 1)
        {
            zoom = OnlineMaps.MAXZOOM;
            return;
        }

        OnlineMapsProjection projection = map.projection;

        double alx, aty, arx, aby;
        projection.CoordinatesToTile(minX, maxY, OnlineMaps.MAXZOOM, out alx, out aty);
        projection.CoordinatesToTile(maxX, minY, OnlineMaps.MAXZOOM, out arx, out aby);

        double mapRangeX = (map.width - inset.x * 2) / OnlineMapsUtils.tileSize;
        double mapRangeY = (map.height - inset.y * 2) / OnlineMapsUtils.tileSize;

        double areaRangeX = arx - alx;
        double areaRangeY = aby - aty;

        double rangeX = areaRangeX / mapRangeX;
        double rangeY = areaRangeY / mapRangeY;

        double zoomOffsetX = Math.Log(rangeX, 2);
        double zoomOffsetY = Math.Log(rangeY, 2);

        zoom = OnlineMaps.MAXZOOM - (float)Math.Max(zoomOffsetX, zoomOffsetY) - 0.5f;
    }

    private void Start()
    {
        if (container == null) return;

        OnlineMaps map = OnlineMaps.instance;
        OnlineMapsVector2d center;
        float zoom;
        GetCenterPointAndZoom(map, new double[]
        {
            container.leftLongitude,
            container.topLatitude,
            container.rightLongitude,
            container.bottomLatitude
        }, out center, out zoom);
        
        map.SetPositionAndZoom(center.x, center.y, zoom);

        OnlineMapsTileSetControl control = map.control as OnlineMapsTileSetControl;
        float size = Mathf.Max(container.size.x, container.size.z);
        control.sizeInScene = new Vector2(size, size);

        map.transform.rotation = Quaternion.Euler(0, 180, 0);
        map.transform.position = container.transform.position + new Vector3((container.size.x - size) / 2, 0, size + (container.size.z - size) / 2);

        control.OnDrawTile += OnDrawTile;
    }

    private void OnDrawTile(OnlineMapsTile tile, Material material)
    {
        Color color = material.color;
        color.a = mapAlpha;
        material.color = color;
    }

    private void Update()
    {
        if (_mapAlpha != mapAlpha)
        {
            OnlineMaps.instance.Redraw();
            _mapAlpha = mapAlpha;
        }
    }
}</code></pre></div>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2023-01-18T19:36:02Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=8830#p8830</id>
		</entry>
</feed>
