<?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 — Adapt map control for VR]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=989</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=989&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Adapt map control for VR.]]></description>
		<lastBuildDate>Thu, 13 Dec 2018 21:48:02 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Adapt map control for VR]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=4405#p4405</link>
			<description><![CDATA[<p>This method is called to find out if the button is pressed.<br />So of course, this is the planned behavior.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 13 Dec 2018 21:48:02 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=4405#p4405</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adapt map control for VR]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=4404#p4404</link>
			<description><![CDATA[<p>Actually, it&#039;s &quot;OnGetTouchCount()&quot; which is called every frame, no matter if i press my button or not. Is that the intended behavior ?</p>]]></description>
			<author><![CDATA[null@example.com (Thibault)]]></author>
			<pubDate>Thu, 13 Dec 2018 21:41:46 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=4404#p4404</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adapt map control for VR]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=4403#p4403</link>
			<description><![CDATA[<p>Each of these methods can be called several times per frame.</p><p>I looked at your code in post number 3, and I think you always have a click.<br />Check your Update method. I think there is a bug.<br />Fix this and all events (including click and drag) will work correctly.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Thu, 13 Dec 2018 21:19:56 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=4403#p4403</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adapt map control for VR]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=4400#p4400</link>
			<description><![CDATA[<p>Ok, part 1) is definitly solved !</p><p>The correct code is : <br /></p><div class="codebox"><pre><code>private Vector2 OnGetInputPosition()
    {
        return texCam.ViewportToScreenPoint(cursorPos);
    }</code></pre></div><p>Stupid mistake really, as i was giving a position between (0,0) and (1,1) instead of (0,0) to (screen.width,screen.height). And so, it was always spawning bottom left of the screen.</p><p> 2)And also, why is OnGetTouchCount() always called twice when i press my button ?</p><p>3)Is there a way to emulate a cursor drag in a similar way that OnGetTouchCount is emulating a click? (To move the map)</p>]]></description>
			<author><![CDATA[null@example.com (Thibault)]]></author>
			<pubDate>Thu, 13 Dec 2018 19:30:30 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=4400#p4400</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adapt map control for VR]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=4398#p4398</link>
			<description><![CDATA[<p>Ok so i solved the the first part of 1) by replacing :</p><div class="codebox"><pre><code>Debug.Log(&quot;Fake mouse clic at texture coord : &quot;+cursorPos.ToString(&quot;f8&quot;)+&quot; which is &quot;+ OnlineMapsTileSetControl.instance.GetCoords(cursorPos).ToString(&quot;f8&quot;));</code></pre></div><p>With :<br /></p><div class="codebox"><pre><code>double lng, lat;
OnlineMapsTileSetControl.instance.GetCoords(out lng, out lat, cursorPos);
Debug.Log(&quot;Fake mouse clic at texture coord : &quot;+cursorPos.ToString(&quot;f8&quot;)+&quot; which is &quot;+ lng + &quot;   &quot; + lat);</code></pre></div><p>So the remaining questions are : </p><p>1)Since the value given by &quot;Debug.Log(&quot;OnMapClick at &quot; + lng + &quot;&nbsp; &nbsp;&quot; + lat)&quot; is always different, why are my markers at the same position ? </p><p>EDIT : -&gt; In fact, even if the lat/lng seems different, google maps is pointing at the same place where my markers are, so i guess that the lat / lng are not different enough to spawn my cubes at different place. </p><p>So i need to find out why &quot;OnlineMapsTileSetControl.instance.GetCoords(out lng, out lat, cursorPos);&quot; is giving similar position even when cursorPos (which is my texture coordinates) is a lot different.</p><br /><br /><br /><p>2)And also, why is OnGetTouchCount() always called twice when i press my button ?</p><p>3)Is there a way to emulate a cursor drag in a similar way that OnGetTouchCount is emulating a click? (To move the map)</p>]]></description>
			<author><![CDATA[null@example.com (Thibault)]]></author>
			<pubDate>Thu, 13 Dec 2018 17:31:26 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=4398#p4398</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adapt map control for VR]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=4397#p4397</link>
			<description><![CDATA[<p>Thanks for the example, I did some tests based on this code.<br />I&#039;m facing several issues though.</p><p><a href="https://gph.is/2SMO0lo">https://gph.is/2SMO0lo</a></p><p>In this GIF i&#039;m trying to place a cube prefab as a marker on click. As you cans see they all appears at the same position, bottom left of the fake screen.</p><p>This is the console output :</p><p><span class="postimg"><img src="https://i.imgur.com/5uK0QJh.jpg" alt="https://i.imgur.com/5uK0QJh.jpg" /></span></p><br /><p>based on this code :<br /></p><div class="codebox"><pre><code>using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

public class Test_VR_controller_UI_interaction : MonoBehaviour {


    public Text outputText;
    public Camera texCam;
    public GameObject prefab;

    LineRenderer LR;

    private Vector2 cursorPos = new Vector2();
    private bool isPointingTabletScreen = false;

    // Use this for initialization
    void Start () {
        
        LR = gameObject.AddComponent&lt;LineRenderer&gt;();
        LR.startWidth = 0.01f;
        LR.endWidth = 0.01f;
        LR.positionCount = 2;
        LR.material = new Material(Shader.Find(&quot;Particles/Alpha Blended Premultiply&quot;));
        LR.startColor = Color.yellow;
        LR.endColor = Color.yellow;

        // Intercepts getting the cursor coordinates.
        OnlineMapsControlBase.instance.OnGetInputPosition += OnGetInputPosition;

        // Intercepts getting the number of touches.
        OnlineMapsControlBase.instance.OnGetTouchCount += OnGetTouchCount;

        OnlineMapsControlBase.instance.OnMapClick += OnMapClick;// Subscribe to the click event.
    }
    
    // Update is called once per frame
    void Update () {
        bool bDown = OVRInput.GetDown(OVRInput.Button.PrimaryIndexTrigger, OVRInput.Controller.RTouch); // for right hand

        LR.SetPosition(0, transform.position);

        RaycastHit hit;
        // Does the ray intersect any objects
        if (Physics.Raycast(transform.position, transform.TransformDirection(Vector3.forward), out hit, Mathf.Infinity))
        {
            LR.SetPosition(1, hit.point);
            LR.endColor = Color.red;

            //outputText.text = hit.transform.gameObject.name;
            outputText.text = hit.transform.gameObject.name + &quot;  &quot; + hit.textureCoord.ToString();
            //outputText.text = OnlineMapsTileSetControl.instance.GetCoords(hit.textureCoord).ToString(&quot;f8&quot;);

            if (bDown)
            {
                if (hit.transform.gameObject.name == &quot;tablet_screen&quot;)
                {
                    cursorPos = hit.textureCoord;
                    isPointingTabletScreen = true;
                    return;
                }
            }
        }
        else
        {
            LR.SetPosition(1, transform.position + transform.TransformDirection(Vector3.forward) * 1000);
        }

        isPointingTabletScreen = false;
    }

    private Vector2 OnGetInputPosition()
    {
        return cursorPos;
    }

    private int OnGetTouchCount()
    {
        if (isPointingTabletScreen)
        {
            Debug.Log(&quot;Fake mouse clic at texture coord : &quot;+cursorPos.ToString(&quot;f8&quot;)+&quot; which is &quot;+ OnlineMapsTileSetControl.instance.GetCoords(cursorPos).ToString(&quot;f8&quot;));
            return 1;
        }
        else
            return 0;
    }
    
    private void OnMapClick()
    {
        double lng, lat;
        OnlineMapsControlBase.instance.GetCoords(out lng, out lat);
        Debug.Log(&quot;OnMapClick at &quot; + lng + &quot;   &quot; + lat);

        OnlineMapsMarker3D marker = OnlineMapsControlBase3D.instance.AddMarker3D(lng, lat, prefab);
    }
}</code></pre></div><p> 1) I don&#039;t understand&nbsp; why the longitude/latitude is different when i debug.log it in &quot;OnGetTouchCount()&quot; and in &quot;OnMapClick()&quot;.<br />Shouldn&#039;t it be the same value ?</p><p>Since the value given by &quot;Debug.Log(&quot;OnMapClick at &quot; + lng + &quot;&nbsp; &nbsp;&quot; + lat)&quot; is always different, why are my markers at the same position ?</p><p>2)And also, why is OnGetTouchCount() always called twice when i press my button ?</p><p>3)Is there a way to emulate a cursor drag in a similar way that OnGetTouchCount is emulating a click? (To move the map)</p>]]></description>
			<author><![CDATA[null@example.com (Thibault)]]></author>
			<pubDate>Thu, 13 Dec 2018 16:36:37 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=4397#p4397</guid>
		</item>
		<item>
			<title><![CDATA[Re: Adapt map control for VR]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=4389#p4389</link>
			<description><![CDATA[<p>Hello.</p><p>First of all, look at this example:<br /><a href="http://infinity-code.com/atlas/online-maps/pages/InterceptInputExample.html">http://infinity-code.com/atlas/online-m … ample.html</a><br />This allows you to emulate the cursor position and mouse click.</p><p>Unfortunately, I do not know whether it will work for UI buttons or not.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Wed, 12 Dec 2018 23:27:56 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=4389#p4389</guid>
		</item>
		<item>
			<title><![CDATA[Adapt map control for VR]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=4387#p4387</link>
			<description><![CDATA[<p>Hi</p><p>I have the chance to work with an oculus rift this week, and i&#039;m trying some experiments.</p><p>I&#039;m trying to virtualize my application. I mean that i did set up the main camera to render to a texture instead of rendering on the screen, an put this texture to a &quot;fake screen&quot;. Now i want to be able to interact with the map.</p><p><a href="https://gph.is/2C7N8SR">https://gph.is/2C7N8SR</a></p><p>As you can see in this Gif, i&#039;m trying to control the map using the oculus&nbsp; touch. <br />Right now i&#039;m performing a raycast, and retrieving the texture coordinate of the hit point.</p><p>So i think that i should trigger a mouse click, using the texture coordinate to &quot;emulate&quot; a screen position. This would give me the ability to use the map control, add marker at certain coordinates, etc ...</p><p>1) Is that a good approach ? How would you proceed to call a mouse clic at a certain position ?</p><p>2) Or are there any functions to control the map that i could call to do this job ? </p><p>3) Would this also give me the abilitie to press my UI buttons ? (my ui is on a canvas which is set to overlay the &quot;map&quot; camera.) I know i could set those ui elements to world space, position them onto the fake screen, add a box collider to every button and trigger them with my controller but if i could just simulate a screen click that should work without having to change anything in my UI right?</p>]]></description>
			<author><![CDATA[null@example.com (Thibault)]]></author>
			<pubDate>Wed, 12 Dec 2018 20:10:09 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=4387#p4387</guid>
		</item>
	</channel>
</rss>
