<?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 — Gesture zoom with custom inputs?]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=413</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=413&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Gesture zoom with custom inputs?.]]></description>
		<lastBuildDate>Mon, 20 Feb 2017 14:31:26 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1860#p1860</link>
			<description><![CDATA[<p>Hey guys, thanks for the input (hah). Sorry I totally forgot about this thread lol... I ended up just implementing a zoom where the user could pull the trigger on the vive and move the controller vertically to zoom in and out. It seemed pretty intuitive and ended up working pretty well, so we stuck with that at the time.</p><p>I ended up with a couple issues that have sort of janky fixes, though. One of them was that OnlineMapsControlBase.instance.ZoomOnPoint wasn&#039;t putting me in the right place, so I had to call OnlineMaps.instance.SetPosition afterwards weirdly. The other was with elevation turned on you could end up going under the ground just by zooming in, so I had to add a script to the camera rig to make it so you&#039;re always x distance above the terrain.</p>]]></description>
			<author><![CDATA[null@example.com (ShaneTheKing)]]></author>
			<pubDate>Mon, 20 Feb 2017 14:31:26 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1860#p1860</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1843#p1843</link>
			<description><![CDATA[<p>I understood.<br />The problem occurs at the intersection of longitude 180 / -180.<br />Solution (line 71):<br /></p><div class="codebox"><pre><code>int cx = x + itx;
if (cx &gt;= maxX) cx -= maxX;</code></pre></div><br /><br /><p>You need to change the scale of markers.<br />Something like:<br /><a href="http://forum.infinity-code.com/viewtopic.php?pid=1692#p1692">http://forum.infinity-code.com/viewtopi … 1692#p1692</a><br />For 3D markers you need to use OnlineMapsControlBase3D.markers3D.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 16 Feb 2017 14:38:24 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1843#p1843</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1842#p1842</link>
			<description><![CDATA[<p>This is the result of the Console.<br />It seems to happen only on zoom levels that are more zoomed out, around when I get clusters.</p><p>[EDIT: It happens in the entirety of zoomlevel 6. So from 6.0 to 6.9. It does not happen on any other zoomlevel for some reason.]</p>]]></description>
			<author><![CDATA[null@example.com (alexandra)]]></author>
			<pubDate>Thu, 16 Feb 2017 14:19:58 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1842#p1842</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1841#p1841</link>
			<description><![CDATA[<p>I will add that and report back to you <img src="https://forum.infinity-code.com/img/smilies/smile.png" width="15" height="15" alt="smile" /><br />Using this smooth zoom the markers are also scaled. Is there a way to stop the markers from scaling along with the decimal values of the zoom?</p>]]></description>
			<author><![CDATA[null@example.com (alexandra)]]></author>
			<pubDate>Thu, 16 Feb 2017 14:09:39 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1841#p1841</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1840#p1840</link>
			<description><![CDATA[<p>Your script looks fine.<br />This problem can be only if «tileKey != tile.key».<br />But I do not know the situation, when this is possible.</p><p>Try it this way (line 82):<br /></p><div class="codebox"><pre><code>tile = new TileItem(cx, cy, zoom, tileContainer);
try
{
    tiles.Add(tile.key, tile);
}
catch (Exception)
{
    Debug.Log(&quot;Oops. Something happened.&quot;);
    Debug.Log(tileKey);
    Debug.Log(tile.key);
    Debug.Log(tiles.ContainsKey(tileKey));
    throw;
}</code></pre></div><p>I am very interested what will happen.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 16 Feb 2017 13:28:33 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1840#p1840</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1839#p1839</link>
			<description><![CDATA[<div class="codebox"><pre><code>using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Minimap : MonoBehaviour
{
    public int zoom = 10;
    public RectTransform tileContainer;

    private static OnlineMaps map;
    private Dictionary&lt;ulong, TileItem&gt; tiles;
    private List&lt;ulong&gt; keysForRemove;

    private void OnTileDownloaded(OnlineMapsTile tile)
    {
        if (tiles.ContainsKey(tile.key))
        {
            TileItem item = tiles[tile.key];
            if (string.IsNullOrEmpty(tile.www.error))
            {
                Texture2D texture = new Texture2D(128, 128);
                tile.www.LoadImageIntoTexture(texture);
                texture.wrapMode = TextureWrapMode.Clamp;
                item.SetTexture(texture);
                UpdateMinimap();
            }
        }
    }

    private void Start()
    {
        map = OnlineMaps.instance;
        zoom = map.zoom - 5;
        map.OnChangePosition += UpdateMinimap;
        map.OnChangeZoom += delegate { zoom = map.zoom - 5; UpdateMinimap(); };
        OnlineMapsTile.OnTileDownloaded += OnTileDownloaded;

        tiles = new Dictionary&lt;ulong, TileItem&gt;();

        UpdateMinimap();
    }
    private void UpdateMinimap()
    {
        //gameObject.transform.rotation = new Quaternion(0, 0, 0, 0);
        int maxX = 1 &lt;&lt; zoom;

        double lng, lat;
        double lng2, lat2;
        map.GetPosition(out lng, out lat);
        map.GetBottomRightPosition(out lng2, out lat2);
        lng = (lng2 + lng *2) /3;
        lat = (lat2 + lat *2) /3;


        double tx, ty;
        map.projection.CoordinatesToTile(lng, lat, zoom, out tx, out ty);

        int itx = (int) tx - 1;
        int ity = (int) ty - 1;

        if (itx &lt; 0) itx -= maxX;
        if (ity &lt; 0) ity = 0;

        foreach (KeyValuePair&lt;ulong, TileItem&gt; pair in tiles)
        {
            pair.Value.used = false;
        }

        for (int x = 0; x &lt; 3; x++)
        {
            int cx = x + itx;

            for (int y = 0; y &lt; 3; y++)
            {
                int cy = y + ity;
                ulong tileKey = OnlineMapsTile.GetTileKey(zoom, cx, cy);
                TileItem tile;
                if (tiles.ContainsKey(tileKey)) tile = tiles[tileKey];
                else
                {
                    tile = new TileItem(cx, cy, zoom, tileContainer);
                    tiles.Add(tile.key, tile);
                }

                tile.used = true;
                tile.UpdatePosition(tx, ty);
            }
        }

        UnloadUnusedTiles();
    }

    private void UnloadUnusedTiles()
    {
        if (keysForRemove == null) keysForRemove = new List&lt;ulong&gt;(9);
        else keysForRemove.Clear();

        foreach (KeyValuePair&lt;ulong, TileItem&gt; pair in tiles)
        {
            if (!pair.Value.used)
            {
                keysForRemove.Add(pair.Value.key);
                pair.Value.Dispose();
            }
        }

        if (keysForRemove.Count &gt; 0)
        {
            foreach (ulong key in keysForRemove)
            {
                tiles.Remove(key);
            }
        }
    }

    internal class TileItem
    {
        public OnlineMapsTile tile;
        public ulong key;
        public GameObject instance;
        public bool used;

        private int tx;
        private int ty;
        private RectTransform rectTransform;
        private RawImage rawImage;

        public TileItem(int tx, int ty, int zoom, RectTransform container)
        {
            this.tx = tx;
            this.ty = ty;
            tile = new OnlineMapsTile(tx, ty, zoom, map, false);
            key = tile.key;
            map.StartDownloadTile(tile);
            instance = new GameObject(zoom + &quot;x&quot; + tx + &quot;+&quot; + ty);
            rawImage = instance.AddComponent&lt;RawImage&gt;();
            rectTransform = instance.transform as RectTransform;
            rectTransform.SetParent(container);
            rectTransform.anchorMin = new Vector2(0, 1);
            rectTransform.anchorMax = new Vector2(0, 1);
            rectTransform.pivot = new Vector2(0, 1);
            rectTransform.sizeDelta = new Vector2(OnlineMapsUtils.tileSize, OnlineMapsUtils.tileSize);
        }

        public void Dispose()
        {
            tile.Dispose();
            Destroy(instance);

            tile = null;
            instance = null;
            rectTransform = null;
        }

        internal void UpdatePosition(double cx, double cy)
        {
            double px = (tx - cx) * (OnlineMapsUtils.tileSize);
            double py = (cy - ty) * (OnlineMapsUtils.tileSize);
            rectTransform.localPosition = new Vector3((float)px, (float)py, 0);
        }

        public void SetTexture(Texture2D texture)
        {
            rawImage.texture = texture;
        }
    }
}</code></pre></div><p>I added a bit to start so the minimap also zooms out when the player zooms out.</p>]]></description>
			<author><![CDATA[null@example.com (alexandra)]]></author>
			<pubDate>Thu, 16 Feb 2017 12:34:46 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1839#p1839</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1838#p1838</link>
			<description><![CDATA[<p>Hello.</p><p>I have nothing on this stack trace.<br />You have modified the script, right?!</p><p>This error occurs when you try to add an element to the dictionary whose key is already in the dictionary.<br />The original script contains checks for the key in the dictionary.<br />Please send modified Minimap.cs.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 16 Feb 2017 11:42:31 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1838#p1838</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1834#p1834</link>
			<description><![CDATA[<p>While using the smooth zoom sometimes I get this error:</p><p>ArgumentException: An element with the same key already exists in the dictionary.<br />System.Collections.Generic.Dictionary`2[System.UInt64,Minimap+TileItem].Add (UInt64 key, .TileItem value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Collections.Generic/Dictionary.cs:404)<br />Minimap.UpdateMinimap () (at Assets/Minimap/Minimap.cs:83)<br />Minimap.&lt;Start&gt;m__0 () (at Assets/Minimap/Minimap.cs:36)<br />OnlineMaps.DispatchEvent (.OnlineMapsEvents[] evs) (at Assets/Infinity Code/Online maps/Scripts/OnlineMaps.cs:951)<br />OnlineMaps.set_zoom (Int32 value) (at Assets/Infinity Code/Online maps/Scripts/OnlineMaps.cs:584)<br />FloatZoom.UpdateZoom () (at Assets/FloatZoom.cs:43)<br />FloatZoom.set_zoom (Single value) (at Assets/FloatZoom.cs:22)<br />FloatZoom.Update () (at Assets/FloatZoom.cs:65)</p><p>(cs:64 refers to <br />if (currentZoom != _zoom) zoom = currentZoom;<br />)</p>]]></description>
			<author><![CDATA[null@example.com (alexandra)]]></author>
			<pubDate>Thu, 16 Feb 2017 10:40:57 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1834#p1834</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1831#p1831</link>
			<description><![CDATA[<p>The problem was in scale.<br />Actually, you can simply specify Width / Height (pixels) = 64.</p><p>I improved the script, and now it will work correctly.</p><div class="codebox"><pre><code>using UnityEngine;

public class FloatZoom:MonoBehaviour
{
    public float currentZoom; // To change the zoom using the Inspector.

    private float _zoom;
    private OnlineMaps map;
    private Vector3 originalPosition;
    private Vector3 originalScale;
    private Vector3 smoothZoomOffset;
    private Transform mapTransform;

    public float zoom
    {
        get { return _zoom; }
        set
        {
            _zoom = Mathf.Clamp(value, 3, OnlineMaps.MAXZOOM);
            UpdateZoom();
        }
    }

    private void Start()
    {
        map = OnlineMaps.instance;
        currentZoom = _zoom = map.zoom;
        mapTransform = map.transform;
        originalPosition = mapTransform.localPosition;
        originalScale = mapTransform.localScale;

        // This part can be simplified, but I just copied it from Tileset Control.
        Vector3 smoothZoomHitPoint = originalPosition + mapTransform.rotation * new Vector3(map.tilesetSize.x / -2 * originalScale.x, 0, map.tilesetSize.y / 2 * originalScale.z);
        smoothZoomOffset = Quaternion.Inverse(mapTransform.rotation) * (originalPosition - smoothZoomHitPoint);
        smoothZoomOffset.Scale(new Vector3(-1f / map.tilesetWidth, 0, -1f / map.tilesetHeight));
    }

    private void Update()
    {
        if (currentZoom != _zoom) zoom = currentZoom;
    }

    private void UpdateZoom()
    {
        currentZoom = _zoom;
        map.zoom = (int) _zoom;
        float offset = _zoom - (int) _zoom + 1;
        Vector3 newScale = originalScale * offset;

        mapTransform.localScale = newScale;
        Vector3 s = newScale - originalScale;
        s.Scale(new Vector3(1f / originalScale.x, 1 / originalScale.y, 1 / originalScale.z));
        Vector3 p = mapTransform.rotation * new Vector3(map.tilesetWidth * s.x * smoothZoomOffset.x, 0, map.tilesetHeight * s.z * smoothZoomOffset.z);
        mapTransform.localPosition = originalPosition - p;
    }
}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Wed, 15 Feb 2017 17:52:26 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1831#p1831</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1828#p1828</link>
			<description><![CDATA[<p>Sorry for the thread hijack, feel free to take it back whenever Shane <img src="https://forum.infinity-code.com/img/smilies/wink.png" width="15" height="15" alt="wink" /><br />I&#039;ve attached our map settings. When the smooth zoom float is changed the whole map gets displaced to a different location. This only happens on the first change. After that it scales as it should (in that new location). Could it have anything to do with the scale or size of our map?</p><p>[EDIT: It had to do with our scale. We set it back to 1 instead of 0.25 and it worked correctly. We couldn&#039;t find a way to make it work with the 0.25 scale so we&#039;re just rewriting other scripts now <img src="https://forum.infinity-code.com/img/smilies/tongue.png" width="15" height="15" alt="tongue" />]</p>]]></description>
			<author><![CDATA[null@example.com (alexandra)]]></author>
			<pubDate>Wed, 15 Feb 2017 13:47:42 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1828#p1828</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1822#p1822</link>
			<description><![CDATA[<p>This is nice, thank you <img src="https://forum.infinity-code.com/img/smilies/smile.png" width="15" height="15" alt="smile" /><br />It seems however that the entire map gets displaced when the zoom is first changed. I am now just incrementing and decrementing this zoom instead of the original map zoom.</p>]]></description>
			<author><![CDATA[null@example.com (alexandra)]]></author>
			<pubDate>Tue, 14 Feb 2017 12:35:40 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1822#p1822</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1821#p1821</link>
			<description><![CDATA[<p>Hello.</p><p>You can quite easily make your own a smooth zoom.<br />How to make a smooth zoom in general:<br /></p><div class="codebox"><pre><code>using UnityEngine;

public class FloatZoom:MonoBehaviour
{
    public float currentZoom; // To change the zoom using the Inspector.

    private float _zoom;
    private OnlineMaps map;
    private Vector3 originalPosition;
    private Vector3 originalScale;
    private Vector3 smoothZoomOffset;
    private Transform mapTransform;

    public float zoom
    {
        get { return _zoom; }
        set
        {
            _zoom = Mathf.Clamp(value, 3, OnlineMaps.MAXZOOM);
            UpdateZoom();
        }
    }

    private void Start()
    {
        map = OnlineMaps.instance;
        currentZoom = _zoom = map.zoom;
        mapTransform = map.transform;
        originalPosition = mapTransform.position;
        originalScale = mapTransform.localScale;

        // This part can be simplified, but I just copied it from Tileset Control.
        Vector3 smoothZoomHitPoint = mapTransform.position + mapTransform.rotation * new Vector3(map.tilesetSize.x / -2, 0, map.tilesetSize.y / 2);
        smoothZoomOffset = Quaternion.Inverse(mapTransform.rotation) * (originalPosition - smoothZoomHitPoint);
        smoothZoomOffset.Scale(new Vector3(-1f / map.tilesetWidth, 0, -1f / map.tilesetHeight));
    }

    private void Update()
    {
        if (currentZoom != _zoom) zoom = currentZoom;
    }

    private void UpdateZoom()
    {
        currentZoom = _zoom;
        map.zoom = (int) _zoom;
        float offset = _zoom - (int) _zoom + 1;
        mapTransform.localScale = originalScale * offset;
        Vector3 p = mapTransform.rotation * new Vector3(map.tilesetWidth * (mapTransform.localScale.x - 1) * smoothZoomOffset.x, 0, map.tilesetHeight * (mapTransform.localScale.z - 1) * smoothZoomOffset.z);
        mapTransform.localPosition = originalPosition - p;
    }
}</code></pre></div><p>I hope this helps you.</p><p>P.S. In Online Maps v2.6 is planned to add a float zoom for all controls.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Tue, 14 Feb 2017 11:52:46 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1821#p1821</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1819#p1819</link>
			<description><![CDATA[<p>Hi Shane,</p><p>Do you want smooth zoom or is regular changing of the zoom levels also OK?<br />We just used the touchpad (on Vive controllers), where if you press on the bottom side of the pad you zoom out, while pressing on the top side of the pad zooms you out. It&#039;s a regular map.zoom-- and map.zoom++ though so it&#039;s not that neat looking.</p><p>Are you going to do a pinching motion with the controllers? I&#039;m interested in seeing how you would make that work <img src="https://forum.infinity-code.com/img/smilies/smile.png" width="15" height="15" alt="smile" /><br />Right now we&#039;re looking into more of a scrolling mechanism that we could use with the touchpad and hopefully make it a bit smoother. Kind of like scrolling on maps.google.com<br />Unfortunately this seems a bit more challenging on a 3D map.</p>]]></description>
			<author><![CDATA[null@example.com (alexandra)]]></author>
			<pubDate>Tue, 14 Feb 2017 10:16:40 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1819#p1819</guid>
		</item>
		<item>
			<title><![CDATA[Re: Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1801#p1801</link>
			<description><![CDATA[<p>Hello.</p><p>No, in your case (VR) you need to implement it yourself.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 09 Feb 2017 21:35:19 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1801#p1801</guid>
		</item>
		<item>
			<title><![CDATA[Gesture zoom with custom inputs?]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=1798#p1798</link>
			<description><![CDATA[<p>Greetings,</p><p>I&#039;d like to be able to zoom in using VR controllers sort of like pinch to zoom but pulling the triggers on the controllers to zoom, but as far as I can tell, current gesture zoom is only for mobile devices and overriding input locations only works with one input.</p><p>Is there any way to do this without writing my own zoom method?</p><p>Thank you</p>]]></description>
			<author><![CDATA[null@example.com (ShaneTheKing)]]></author>
			<pubDate>Thu, 09 Feb 2017 19:07:57 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=1798#p1798</guid>
		</item>
	</channel>
</rss>
