상속: MonoBehaviour
예제 #1
1
파일: AROrigin.cs 프로젝트: Eryns/Inception
	public void AddMarker(ARMarker marker, bool atHeadOfList = false)
	{
		if (!atHeadOfList) {
			markersEligibleForBaseMarker.Add(marker);
		} else {
			markersEligibleForBaseMarker.Insert(0, marker);
		}
	}
예제 #2
0
    private static void DrawNFTMarker(ARMarker m, Matrix4x4 mat, bool selected)
    {
        float pattWidth  = m.NFTWidth;
        float pattHeight = m.NFTHeight;

        //Debug.Log("DrawNFTMarker got pattWidth=" + pattWidth + ", pattHeight=" + pattHeight + ".");
        if (pattWidth > 0.0f && pattHeight > 0.0f)
        {
            float   biggestSide = Math.Max(pattWidth, pattHeight);
            Vector3 origin      = mat.GetColumn(3);
            Vector3 right       = mat.GetColumn(0);
            Vector3 up          = mat.GetColumn(1);
            Vector3 centre      = origin + right * 0.5f * pattWidth + up * 0.5f * pattHeight;

            //float d = selected ? 1.0f : 0.0f;

            DrawRectangle(centre, up, right, pattWidth, pattHeight, selected ? MarkerBorderSelected : MarkerBorderUnselected);
            DrawRectangle(centre, up, right, pattWidth + biggestSide * 0.05f, pattHeight + biggestSide * 0.05f, selected ? MarkerEdgeSelected : MarkerEdgeUnselected);

            //Gizmos.DrawGUITexture(new Rect(centre.x, centre.y, 20, 20), m.MarkerImage);

            float wordUnitSize = pattHeight * 0.02f;
            DrawWord(m.Tag, wordUnitSize, centre - up * (pattHeight * 0.6f + (wordUnitSize * 4)) - right * pattWidth * 0.525f, up, right * 0.5f);
        }
    }
예제 #3
0
    /// <summary>
    /// Correct all saved marks when loop closure happens.
    ///
    /// When Tango Service is in learning mode, the drift will accumulate overtime, but when the system sees a
    /// pre-exsiting area, it will do a operation to correct all previously saved poses
    /// (the pose you can query with GetPoseAtTime). This operation is called loop closure. When loop closure happens,
    /// we will need to re-query all previously saved marker position in order to achieve the best result.
    /// This function is doing the querying job based on timestamp.
    /// </summary>
    private void _UpdateMarkersForLoopClosures()
    {
        // Adjust mark's position each time we have a loop closure detected.
        foreach (GameObject obj in m_markerList)
        {
            ARMarker tempMarker = obj.GetComponent <ARMarker>();
            if (tempMarker.m_timestamp != -1.0f)
            {
                TangoCoordinateFramePair pair;
                TangoPoseData            relocalizedPose = new TangoPoseData();

                pair.baseFrame   = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION;
                pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
                PoseProvider.GetPoseAtTime(relocalizedPose, tempMarker.m_timestamp, pair);
                Vector3 pDevice = new Vector3((float)relocalizedPose.translation[0],
                                              (float)relocalizedPose.translation[1],
                                              (float)relocalizedPose.translation[2]);
                Quaternion qDevice = new Quaternion((float)relocalizedPose.orientation[0],
                                                    (float)relocalizedPose.orientation[1],
                                                    (float)relocalizedPose.orientation[2],
                                                    (float)relocalizedPose.orientation[3]);

                Matrix4x4 uwTDevice = m_poseController.m_uwTss
                                      * Matrix4x4.TRS(pDevice, qDevice, Vector3.one)
                                      * m_poseController.m_dTuc;

                Matrix4x4 uwTMarker = uwTDevice * tempMarker.m_deviceTMarker;

                obj.transform.position = uwTMarker.GetColumn(3);
                obj.transform.rotation = Quaternion.LookRotation(uwTMarker.GetColumn(2), uwTMarker.GetColumn(1));
            }
        }
    }
예제 #4
0
    /// <summary>
    /// Correct all saved marks when loop closure happens.
    ///
    /// When Tango Service is in learning mode, the drift will accumulate overtime, but when the system sees a
    /// preexisting area, it will do a operation to correct all previously saved poses
    /// (the pose you can query with GetPoseAtTime). This operation is called loop closure. When loop closure happens,
    /// we will need to re-query all previously saved marker position in order to achieve the best result.
    /// This function is doing the querying job based on timestamp.
    /// </summary>
    private void _UpdateMarkersForLoopClosures()
    {
        // Adjust mark's position each time we have a loop closure detected.
        foreach (GameObject obj in m_markerList)
        {
            ARMarker tempMarker = obj.GetComponent <ARMarker>();
            if (tempMarker.m_timestamp != -1.0f)
            {
                TangoCoordinateFramePair pair;
                TangoPoseData            relocalizedPose = new TangoPoseData();

                pair.baseFrame   = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_AREA_DESCRIPTION;
                pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE;
                PoseProvider.GetPoseAtTime(relocalizedPose, tempMarker.m_timestamp, pair);

                Matrix4x4 uwTDevice = TangoSupport.UNITY_WORLD_T_START_SERVICE
                                      * relocalizedPose.ToMatrix4x4()
                                      * m_poseController.m_dTuc;

                Matrix4x4 uwTMarker = uwTDevice * tempMarker.m_deviceTMarker;

                obj.transform.position = uwTMarker.GetColumn(3);
                obj.transform.rotation = Quaternion.LookRotation(uwTMarker.GetColumn(2), uwTMarker.GetColumn(1));
            }
        }
    }
예제 #5
0
 void OnMarkerTracked(ARMarker marker)
 {
     if (marker.Tag.Equals("Marker1"))
     {
         //Do something each frame
     }
 }
예제 #6
0
	/// <summary>
	/// Raises the marker found event.
	/// </summary>
	/// <param name="marker"></param>
	void OnMarkerFound(ARMarker marker)
	{
		string markerName = marker.name;
		int pageNumber = int.Parse(marker.name.TrimStart("p".ToCharArray()).TrimEnd("marker".ToCharArray()));
		StateManager.manager.pageNumber = pageNumber;
		UnityEngine.SceneManagement.SceneManager.LoadScene("PageSceneEmpty");
	}
예제 #7
0
 void OnMarkerFound(ARMarker marker)
 {
     foreach (Transform child in transform)
     {
         child.gameObject.SetActive(false);
     }
 }
예제 #8
0
 void OnMarkerLost(ARMarker marker)
 {
     foreach (Transform child in transform)
     {
         child.gameObject.SetActive(true);
     }
 }
    /// <summary>
    /// Unity OnGUI function.
    ///
    /// Mainly for removing markers.
    /// </summary>
    public void OnGUI()
    {
        if (m_selectedMarker != null)
        {
            Renderer selectedRenderer = m_selectedMarker.GetComponent <Renderer>();

            // GUI's Y is flipped from the mouse's Y
            Rect  screenRect = _WorldBoundsToScreen(Camera.main, selectedRenderer.bounds);
            float yMin       = Screen.height - screenRect.yMin;
            float yMax       = Screen.height - screenRect.yMax;
            screenRect.yMin = Mathf.Min(yMin, yMax);
            screenRect.yMax = Mathf.Max(yMin, yMax);

            if (GUI.Button(screenRect, "<size=30>Hide</size>"))
            {
                m_markerList.Remove(m_selectedMarker.gameObject);
                m_selectedMarker.SendMessage("Hide");
                m_selectedMarker = null;
                m_selectedRect   = new Rect();
            }
            else
            {
                m_selectedRect = screenRect;
            }
        }
        else
        {
            m_selectedRect = new Rect();
        }
    }
예제 #10
0
    // Updates arVisible, arPosition, arRotation based on linked marker state.
    private void UpdateTracking()
    {
        // Note the current time
        timeLastUpdate = Time.realtimeSinceStartup;

        // First, ensure we have a base marker. If none, then no markers are currently in view.
        ARMarker marker = GetMarker();

        if (marker == null)
        {
            markerInsight = false;
            if (arVisible)
            {
                // Marker was visible but now is hidden.
                timeTrackingLost = timeLastUpdate;
                arVisible        = false;
            }
        }
        else
        {
            markerInsight = true;

            if (marker.Visible)
            {
                Matrix4x4 pose;
                if (Optical && opticalSetupOK)
                {
                    pose = (opticalViewMatrix * marker.TransformationMatrix).inverse;
                }
                else
                {
                    pose = marker.TransformationMatrix.inverse;
                }

                arPosition = ARUtilityFunctions.PositionFromMatrix(pose);
                // Camera orientation: In ARToolKit, zero rotation of the camera corresponds to looking vertically down on a marker
                // lying flat on the ground. In Unity however, if we still treat markers as being flat on the ground, we clash with Unity's
                // camera "rotation", because an unrotated Unity camera is looking horizontally.
                // So we choose to treat an unrotated marker as standing vertically, and apply a transform to the scene to
                // to get it to lie flat on the ground.
                arRotation = ARUtilityFunctions.QuaternionFromMatrix(pose);

                if (!arVisible)
                {
                    // Marker was hidden but now is visible.
                    arVisible = true;
                }
            }
            else
            {
                if (arVisible)
                {
                    // Marker was visible but now is hidden.
                    timeTrackingLost = timeLastUpdate;
                    arVisible        = false;
                }
            }
        }
    }
    /// <summary>
    /// Wait for the next depth update, then find the plane at the touch position.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    /// <param name="touchPosition">Touch position to find a plane at.</param>
    private IEnumerator _WaitForDepthAndFindPlane(Vector2 touchPosition)
    {
        m_findPlaneWaitingForDepth = true;
        
        // Turn on the camera and wait for a single depth update.
        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.MAXIMUM);
        while (m_findPlaneWaitingForDepth)
        {
            yield return null;
        }

        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.DISABLED);
        
        // Find the plane.
        Camera cam = Camera.main;
        Vector3 planeCenter;
        Plane plane;
        if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane))
        {
            yield break;
        }
        
        // Ensure the location is always facing the camera.  This is like a LookRotation, but for the Y axis.
        Vector3 up = plane.normal;
        Vector3 forward;
        if (Vector3.Angle(plane.normal, cam.transform.forward) < 175)
        {
            Vector3 right = Vector3.Cross(up, cam.transform.forward).normalized;
            forward = Vector3.Cross(right, up).normalized;
        }
        else
        {
            // Normal is nearly parallel to camera look direction, the cross product would have too much
            // floating point error in it.
            forward = Vector3.Cross(up, cam.transform.right);
        }

        // Instantiate marker object.
        newMarkObject = Instantiate(m_markPrefabs[m_currentMarkType],
                                    planeCenter,
                                    Quaternion.LookRotation(forward, up)) as GameObject;

        ARMarker markerScript = newMarkObject.GetComponent<ARMarker>();

        markerScript.m_type = m_currentMarkType;
        markerScript.m_timestamp = (float)m_poseController.m_poseTimestamp;
        
        Matrix4x4 uwTDevice = Matrix4x4.TRS(m_poseController.m_tangoPosition,
                                            m_poseController.m_tangoRotation,
                                            Vector3.one);
        Matrix4x4 uwTMarker = Matrix4x4.TRS(newMarkObject.transform.position,
                                            newMarkObject.transform.rotation,
                                            Vector3.one);
        markerScript.m_deviceTMarker = Matrix4x4.Inverse(uwTDevice) * uwTMarker;
        
        m_markerList.Add(newMarkObject);

        m_selectedMarker = null;
    }
예제 #12
0
    /// <summary>
    /// Wait for the next depth update, then find the plane at the touch position.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    /// <param name="touchPosition">Touch position to find a plane at.</param>
    private IEnumerator _WaitForDepthAndFindPlane(Vector2 touchPosition)
    {
        m_findPlaneWaitingForDepth = true;
        Debug.Log("touch at " + touchPosition);

        // Turn on the camera and wait for a single depth update.
        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.MAXIMUM);
        while (m_findPlaneWaitingForDepth)
        {
            yield return(null);
        }
        Debug.Log("Got depth");

        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.DISABLED);

        // Find the plane.
        Camera  cam = Camera.main;
        Vector3 planeCenter;
        Plane   plane;

        if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane))
        {
            Debug.Log("Cannot find plane");
            yield break;
        }

        // Ensure the location is always facing the camera.  This is like a LookRotation, but for the Y axis.
        Vector3 up = plane.normal;
        Vector3 forward;

        if (Vector3.Angle(plane.normal, cam.transform.forward) < 175)
        {
            Vector3 right = Vector3.Cross(up, cam.transform.forward).normalized;
            forward = Vector3.Cross(right, up).normalized;
        }
        else
        {
            // Normal is nearly parallel to camera look direction, the cross product would have too much
            // floating point error in it.
            forward = Vector3.Cross(up, cam.transform.right);
        }

        m_adding = true;
        if (m_placedObject != null)
        {
            Destroy(m_placedObject);
        }
        m_placedObject = (GameObject)Instantiate(m_prefabMarker, planeCenter, Quaternion.LookRotation(forward, up));
        m_placedObject.gameObject.SetActive(true);
        IGetSculptController[] comps = m_placedObject.GetComponentsInChildren <IGetSculptController>();
        if (comps != null && comps.Length > 0)
        {
            foreach (IGetSculptController c in comps)
            {
                c.RegisterSculptController(this);
            }
        }
        m_selectedMarker = null;
    }
예제 #13
0
        public void OnMarkerTracked(ARMarker marker)
        {
            MagnifierLensTexture.Pose     = GetComponent <ARTrackedObject> ().transform.position;
            MagnifierLensTexture.Rotation = marker.transform.rotation;

            //MagnifierLensTexture.Pose = marker.transform.position;
            //Debug.Log ("marker tracked: " + marker.Tag);
        }
예제 #14
0
 public bool RemoveMarker(ARMarker marker)
 {
     if (baseMarker == marker)
     {
         baseMarker = null;
     }
     return(markersEligibleForBaseMarker.Remove(marker));
 }
예제 #15
0
 public void OnMarkerLost(ARMarker marker)
 {
     Debug.Log("OnMarkerLost : " + marker.name);
     if (showContent != null)
     {
         StopCoroutine(showContent);
     }
     HideContent();
 }
예제 #16
0
        public void RemoveTrackedObject(ARTrackedObject trackedObject)
        {
            ARMarker marker = trackedObject.GetMarker();

            objectsForMarkers[marker].Remove(trackedObject);
            if (objectsForMarkers[marker].Count == 0)
            {
                objectsForMarkers.Remove(marker);
            }
        }
    /// <summary>
    /// Select craete marker via touch
    /// </summary>
    /// <param name="hitInfo"></param>
    private void _SelectCreatedMarker(RaycastHit hitInfo)
    {
        // Found a marker, select it (so long as it isn't disappearing)!
        GameObject tapped = hitInfo.collider.gameObject;

        if (!tapped.GetComponent <Animation>().isPlaying)
        {
            m_selectedMarker = tapped.GetComponent <ARMarker>();
        }
    }
예제 #18
0
 public void AddMarker(ARMarker marker, bool atHeadOfList = false)
 {
     if (!atHeadOfList)
     {
         markersEligibleForBaseMarker.Add(marker);
     }
     else
     {
         markersEligibleForBaseMarker.Insert(0, marker);
     }
 }
예제 #19
0
 void OnMarkerLost(ARMarker marker)
 {
     /*
      * if (marker.Tag.Equals("Marker1"))
      * {
      *  //Do something each frame
      * }
      */
     Debug.Log("Marker lost!");
     uiController.GetComponent <UserInterfaceButtons>().onTargetLost();
 }
예제 #20
0
    void OnMarkerFound(ARMarker mark)
    {
        if (mark.Tag == "left")
        {
            ShootingLeft = true;
        }

        if (mark.Tag == "right")
        {
            ShootingRight = true;
        }
    }
예제 #21
0
 public void OnMarkerFound(ARMarker marker)
 {
     Debug.Log("OnMarkerFound : " + marker.name);
     if (CheckMarkerFromString(Memberinfo.Instance.ID))
     {
         showContent = StartCoroutine(ShowContent());
     }
     else
     {
         SetContent();
     }
 }
    /// <summary>
    /// Add line to 3D space according ids of markers.
    /// </summary>
    /// <param name="id1">Id of start marker.</param>
    /// <param name="id2">Id of target marker.</param>
    public void AddLineWithIds(int id1, int id2)
    {
        GameObject go1;
        GameObject go2;

        m_markerList.TryGetValue(id1, out go1);
        m_markerList.TryGetValue(id2, out go2);

        ARMarker marker1 = go1.GetComponent <ARMarker>();
        ARMarker marker2 = go2.GetComponent <ARMarker>();

        marker1.AddLine(marker2.GetID(), marker2.transform.position);
    }
예제 #23
0
    void OnMarkerFound(ARMarker marker)
    {
        /*
         * if (marker.Tag.Equals("Marker1"))
         * {
         *  //Do something
         * }
         */

        Debug.Log("Marker found!");

        uiController.GetComponent <UserInterfaceButtons>().onTargetFound();
    }
예제 #24
0
	// Return the marker associated with this component.
	// Uses cached value if available, otherwise performs a find operation.
	public virtual ARMarker GetMarker()
	{
		if (_marker == null) {
			// Locate the marker identified by the tag
			ARMarker[] ms = FindObjectsOfType<ARMarker>();
			foreach (ARMarker m in ms) {
				if (m.Tag == _markerTag) {
					_marker = m;
					break;
				}
			}
		}
		return _marker;
	}
예제 #25
0
    void OnMarkerMadeVisible(ARMarker marker)
    {
        // Update every .. 2 seconds
        int secondNow = (int)timeNowSeconds;

        if (secondNow == lastUpdateSecond)
        {
            return;
        }
        lastUpdateSecond = secondNow;
        DownloadJSON();
        // Update UI
        UpdateTexts();
    }
예제 #26
0
    public static void ApplyMarkerData(ARMarker markerComponent)
    {
        // temporarily disable any existing instance
        markerComponent.enabled = false;

        // use our custom field to avoid the file being loaded from
        // StreamingAssets by ARToolKit
        markerComponent.MarkerType                  = MarkerType.Multimarker;
        markerComponent.MultiConfigFile             = PATTERN_FILE_NAME;
        markerComponent.MultiConfigNonStreamingFile = PATTERN_FILE_PATH;

        // enable the marker so that ARToolKit knows params have changed
        markerComponent.enabled = true;
    }
예제 #27
0
 public void OnMarkerFound(ARMarker arMarker)
 {
     if (arMarker.GetMarkerTag == "marker01" || arMarker.GetMarkerTag == "marker02")
     {
         Debug.Log("Salle Antiquité");
         SceneManager.LoadScene(sceneAntiquite);
         gameObject.SetActive(false);
     }
     else if (arMarker.GetMarkerTag == "marker03")
     {
         Debug.Log("Salle Moyen Age");
         //SceneManager.LoadScene(sceneMoyenAge);
     }
 }
예제 #28
0
    void OnMarkerLost(ARMarker mark)
    {
        Debug.Log(mark.tag + "Now not visible");
        if (mark.Tag == "left")
        {
            Debug.Log("Turning off");
            ShootingLeft = false;
        }

        if (mark.Tag == "right")
        {
            ShootingRight = true;
        }
    }
예제 #29
0
    /// <summary>
    /// Wait for the next depth update, then find the plane at the touch position.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    /// <param name="touchPosition">Touch position to find a plane at.</param>
    private IEnumerator _WaitForDepthAndFindPlane(Vector2 touchPosition)
    {
        m_findPlaneWaitingForDepth = true;

        // Turn on the camera and wait for a single depth update.
        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.MAXIMUM);
        while (m_findPlaneWaitingForDepth)
        {
            yield return(null);
        }

        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.DISABLED);

        // Find the plane.
        Camera  cam = Camera.main;
        Vector3 planeCenter;
        Plane   plane;

        if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane))
        {
            yield break;
        }

        // Ensure the location is always facing the camera.  This is like a LookRotation, but for the Y axis.
        Vector3 up = plane.normal;
        Vector3 forward;

        if (Vector3.Angle(plane.normal, cam.transform.forward) < 175)
        {
            Vector3 right = Vector3.Cross(up, cam.transform.forward).normalized;
            forward = Vector3.Cross(right, up).normalized;
        }
        else
        {
            // Normal is nearly parallel to camera look direction, the cross product would have too much
            // floating point error in it.
            forward = Vector3.Cross(up, cam.transform.right);
        }

        #region Cfd
        _markerPositions.Add(planeCenter);
        if (_markerPositions.Count >= 4)
        {
            CalculateTransform();
        }
        #endregion
        Instantiate(m_prefabMarker, planeCenter, Quaternion.LookRotation(forward, up));
        m_selectedMarker = null;
    }
예제 #30
0
    private void GetMarkers()
    {
        for (int i = 0; i < armarker.Length; i++)
        {
            if (armarker[i].Tag == "hiro")
            {
                ballMarkerScript = armarker[i];
            }

            if (armarker[i].Tag == "kanji")
            {
                pinMarkerScript = armarker[i];
            }
        }
    }
예제 #31
0
        public void AddTrackedObject(ARTrackedObject trackedObject)
        {
            ARMarker marker = trackedObject.GetMarker();

            if (objectsForMarkers.ContainsKey(marker))
            {
                objectsForMarkers[marker].Add(trackedObject);
            }
            else
            {
                objectsForMarkers.Add(marker, new HashSet <ARTrackedObject> {
                    trackedObject
                });
            }
        }
    /// <summary>
    /// Create connection between two independent markers
    /// </summary>
    public void JoinMarkers()
    {
        if (m_selectedMarker != null && m_connectMarkers[0] == null)
        {
            m_connectMarkers[0] = m_selectedMarker;
            m_connectMarkers[0].GetComponent <ARMarker>().SelectGameObject();
            m_selectedMarker = null;
        }

        if (m_selectedMarker != null && m_connectMarkers[1] == null)
        {
            m_connectMarkers[1] = m_selectedMarker;
            m_connectMarkers[1].GetComponent <ARMarker>().SelectGameObject();
            m_selectedMarker = null;
        }

        if (m_connectMarkers[0] != null && m_connectMarkers[1] != null)
        {
            GameObject tmpLine = null;
            if (m_connectMarkers[0].lines.TryGetValue(m_connectMarkers[1].GetID(), out tmpLine))
            {
                m_connectMarkers[0].lines.Remove(m_connectMarkers[1].GetID());
            }

            if (tmpLine == null)
            {
                if (m_connectMarkers[1].lines.TryGetValue(m_connectMarkers[0].GetID(), out tmpLine))
                {
                    m_connectMarkers[1].lines.Remove(m_connectMarkers[0].GetID());
                }
            }

            if (tmpLine != null)
            {
                Destroy(tmpLine);
                AndroidHelper.ShowAndroidToastMessage("Connection is deleted.");
            }
            else
            {
                m_connectMarkers[0].AddLine(m_connectMarkers[1].GetID(), m_connectMarkers[1].transform.position);
                AndroidHelper.ShowAndroidToastMessage("Connection is created.");
            }

            _ResetSelectedMarkers();

            m_selectedMarker = null;
        }
    }
예제 #33
0
 // Return the marker associated with this component.
 // Uses cached value if available, otherwise performs a find operation.
 public virtual ARMarker GetMarker()
 {
     if (_marker == null)
     {
         // Locate the marker identified by the tag
         ARMarker[] ms = FindObjectsOfType <ARMarker>();
         foreach (ARMarker m in ms)
         {
             if (m.Tag == _markerTag)
             {
                 _marker = m;
                 break;
             }
         }
     }
     return(_marker);
 }
예제 #34
0
	public void OnMarkerLost(ARMarker marker){
		//Debug.Log("MARKER LOST! WHEEEE!");
		MRIObject.Visible = false;
	}
예제 #35
0
 /// <summary>
 /// Unity OnGUI function.
 /// 
 /// Mainly for removing markers.
 /// </summary>
 public void OnGUI()
 {
     if (m_selectedMarker != null)
     {
         Renderer selectedRenderer = m_selectedMarker.GetComponent<Renderer>();
         
         // GUI's Y is flipped from the mouse's Y
         Rect screenRect = _WorldBoundsToScreen(Camera.main, selectedRenderer.bounds);
         float yMin = Screen.height - screenRect.yMin;
         float yMax = Screen.height - screenRect.yMax;
         screenRect.yMin = Mathf.Min(yMin, yMax);
         screenRect.yMax = Mathf.Max(yMin, yMax);
         
         if (GUI.Button(screenRect, "<size=30>Hide</size>"))
         {
             m_markerList.Remove(m_selectedMarker.gameObject);
             m_selectedMarker.SendMessage("Hide");
             m_selectedMarker = null;
             m_selectedRect = new Rect();
         }
         else
         {
             m_selectedRect = screenRect;
         }
     }
     else
     {
         m_selectedRect = new Rect();
     }
 }
예제 #36
0
    /// <summary>
    /// Wait for the next depth update, then find the plane at the touch position.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    /// <param name="touchPosition">Touch position to find a plane at.</param>
    private IEnumerator _WaitForDepthAndFindPlane(Vector2 touchPosition)
    {
        m_findPlaneWaitingForDepth = true;
        
        // Turn on the camera and wait for a single depth update.
        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.MAXIMUM);
        while (m_findPlaneWaitingForDepth)
        {
            yield return null;
        }

        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.DISABLED);
        
        // Find the plane.
        Camera cam = Camera.main;
        Vector3 planeCenter;
        Plane plane;
        if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane))
        {
            yield break;
        }
        
        // Ensure the location is always facing the camera.  This is like a LookRotation, but for the Y axis.
        Vector3 up = plane.normal;
        Vector3 forward;
        if (Vector3.Angle(plane.normal, cam.transform.forward) < 175)
        {
            Vector3 right = Vector3.Cross(up, cam.transform.forward).normalized;
            forward = Vector3.Cross(right, up).normalized;
        }
        else
        {
            // Normal is nearly parallel to camera look direction, the cross product would have too much
            // floating point error in it.
            forward = Vector3.Cross(up, cam.transform.right);
        }

        // Instantiate marker object.
        newMarkObject = Instantiate(m_markPrefabs[m_currentMarkType],
                                    planeCenter,
                                    Quaternion.LookRotation(forward, up)) as GameObject;

        ARMarker markerScript = newMarkObject.GetComponent<ARMarker>();

        markerScript.m_type = m_currentMarkType;
        markerScript.m_timestamp = (float)m_poseController.m_poseTimestamp;
        
        Matrix4x4 uwTDevice = Matrix4x4.TRS(m_poseController.m_tangoPosition,
                                            m_poseController.m_tangoRotation,
                                            Vector3.one);
        Matrix4x4 uwTMarker = Matrix4x4.TRS(planeCenter,
                                            Quaternion.identity,
                                            Vector3.one);
        markerScript.m_deviceTMarker = Matrix4x4.Inverse(uwTDevice) * uwTMarker;
        
        m_markerList.Add(newMarkObject);

        m_selectedMarker = null;
    }
예제 #37
0
    /// <summary>
    /// Wait for the next depth update, then find the plane at the touch position.
    /// </summary>
    /// <returns>Coroutine IEnumerator.</returns>
    /// <param name="touchPosition">Touch position to find a plane at.</param>
    private IEnumerator _WaitForDepthAndFindPlane(Vector2 touchPosition)
    {
        m_findPlaneWaitingForDepth = true;

        // Turn on the camera and wait for a single depth update.
        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.MAXIMUM);
        while (m_findPlaneWaitingForDepth)
        {
            yield return null;
        }
        m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.DISABLED);

        // Find the plane.
        Camera cam = Camera.main;
        Vector3 planeCenter;
        Plane plane;
        if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane))
        {
            yield break;
        }

        // Ensure the location is always facing the camera.  This is like a LookRotation, but for the Y axis.
        Vector3 up = plane.normal;
        Vector3 forward;
        if (Vector3.Angle(plane.normal, cam.transform.forward) < 175)
        {
            Vector3 right = Vector3.Cross(up, cam.transform.forward).normalized;
            forward = Vector3.Cross(right, up).normalized;
        }
        else
        {
            // Normal is nearly parallel to camera look direction, the cross product would have too much
            // floating point error in it.
            forward = Vector3.Cross(up, cam.transform.right);
        }
        Instantiate(m_prefabMarker, planeCenter, Quaternion.LookRotation(forward, up));
        m_selectedMarker = null;
    }
예제 #38
0
파일: AROrigin.cs 프로젝트: Eryns/Inception
	public bool RemoveMarker(ARMarker marker)
	{
		if (baseMarker == marker) baseMarker = null;
		return markersEligibleForBaseMarker.Remove(marker);
	}
예제 #39
0
	/// <summary>
	/// Display simple GUI.
	/// </summary>
	public void OnGUI()
	{

		if (GameObject.FindObjectOfType<ARMarker> () == null) {

			Texture2D placeTableTexture = (Texture2D)Resources.Load ("PlaceTable");
			Rect playRect = new Rect((Screen.width - 1206)/2 , 20, 1206, 109);
			GUI.Button (playRect, placeTableTexture);

		}

		if (GameObject.FindObjectOfType<ARMarker> () != null && beerPongComponent != null && !beerPongComponent.isActive) {
			Rect distortionButtonRec = new Rect (Screen.width - UI_BUTTON_SIZE_X - UI_BUTTON_GAP_X,
			                                     Screen.height - UI_BUTTON_SIZE_Y - UI_BUTTON_GAP_X,
			                                     UI_BUTTON_SIZE_X,
			                                     UI_BUTTON_SIZE_Y);
			if (GUI.Button (distortionButtonRec,
			                UI_FONT_SIZE + "Continue" + "</size>")) {
				
				GameObject.DestroyImmediate (m_canvas.gameObject);
				
				if (beerPongComponent != null) {
					
					beerPongComponent.ActivateGame ();
				}
				Debug.Log ("Activated game elements");
				//Logic for Continue button goes here
			}
		}
		
		if (m_showDebug && m_tangoApplication.HasRequestedPermissions())
		{
			Color oldColor = GUI.color;
			GUI.color = Color.white;
			
			GUI.color = Color.black;
			GUI.Label(new Rect(UI_LABEL_START_X,
			                   UI_LABEL_START_Y,
			                   UI_LABEL_SIZE_X,
			                   UI_LABEL_SIZE_Y),
			          UI_FONT_SIZE + String.Format(UX_TANGO_SERVICE_VERSION, m_tangoServiceVersion) + "</size>");
			
			GUI.Label(new Rect(UI_LABEL_START_X,
			                   UI_FPS_LABEL_START_Y,
			                   UI_LABEL_SIZE_X,
			                   UI_LABEL_SIZE_Y),
			          UI_FONT_SIZE + m_fpsText + "</size>");
			
			// MOTION TRACKING
			GUI.Label(new Rect(UI_LABEL_START_X,
			                   UI_POSE_LABEL_START_Y - UI_LABEL_OFFSET,
			                   UI_LABEL_SIZE_X,
			                   UI_LABEL_SIZE_Y),
			          UI_FONT_SIZE + String.Format(UX_TARGET_TO_BASE_FRAME, "Device", "Start") + "</size>");
			
			Vector3 pos = m_tangoPose.transform.position;
			Quaternion quat = m_tangoPose.transform.rotation;
			string positionString = pos.x.ToString(UI_FLOAT_FORMAT) + ", " +
				pos.y.ToString(UI_FLOAT_FORMAT) + ", " +
					pos.z.ToString(UI_FLOAT_FORMAT);
			string rotationString = quat.x.ToString(UI_FLOAT_FORMAT) + ", " +
				quat.y.ToString(UI_FLOAT_FORMAT) + ", " +
					quat.z.ToString(UI_FLOAT_FORMAT) + ", " +
					quat.w.ToString(UI_FLOAT_FORMAT);
			string statusString = String.Format(UX_STATUS,
			                                    _GetLoggingStringFromPoseStatus(m_tangoPose.m_poseStatus),
			                                    _GetLoggingStringFromFrameCount(m_tangoPose.m_poseCount),
			                                    positionString, rotationString);
			GUI.Label(new Rect(UI_LABEL_START_X,
			                   UI_POSE_LABEL_START_Y,
			                   UI_LABEL_SIZE_X,
			                   UI_LABEL_SIZE_Y),
			          UI_FONT_SIZE + statusString + "</size>");
			GUI.color = oldColor;
		}
		
		if (m_selectedMarker != null)
		{
			Renderer selectedRenderer = m_selectedMarker.GetComponent<Renderer>();
			
			// GUI's Y is flipped from the mouse's Y
			Rect screenRect = WorldBoundsToScreen(Camera.main, selectedRenderer.bounds);
			float yMin = Screen.height - screenRect.yMin;
			float yMax = Screen.height - screenRect.yMax;
			screenRect.yMin = Mathf.Min(yMin, yMax);
			screenRect.yMax = Mathf.Max(yMin, yMax);
			
			if (GUI.Button(screenRect, "<size=30>Hide</size>"))
			{
				m_selectedMarker.SendMessage("Hide");
				m_selectedMarker = null;
				m_selectedRect = new Rect();
			}
			else
			{
				m_selectedRect = screenRect;
			}
		}
		else
		{
			m_selectedRect = new Rect();
		}
		
		if (GameObject.FindObjectOfType<ARMarker>() != null && beerPongComponent != null && !beerPongComponent.isActive)
		{
			

			Texture2D placeTableTexture = (Texture2D)Resources.Load ("DragTable");
			Rect playRect = new Rect((Screen.width - 790)/2 , 20, 790, 109);
			GUI.Button (playRect, placeTableTexture);



			m_hideAllRect = new Rect(UI_BUTTON_GAP_X,
			                         Screen.height - UI_BUTTON_SIZE_Y - UI_BUTTON_GAP_X,
			                         UI_BUTTON_SIZE_X,
			                         UI_BUTTON_SIZE_Y);
			if (GUI.Button(m_hideAllRect, "<size=30>Place Again</size>"))
			{
				foreach (ARMarker marker in GameObject.FindObjectsOfType<ARMarker>())
				{
					marker.SendMessage("Hide");
				}
			}
		}
		else
		{
			m_hideAllRect = new Rect(0, 0, 0, 0);
		}
	}
예제 #40
0
    /// <summary>
    /// Display simple GUI.
    /// </summary>
    public void OnGUI()
    {
        Rect distortionButtonRec = new Rect(UI_BUTTON_GAP_X,
                                            Screen.height - UI_BUTTON_SIZE_Y - UI_BUTTON_GAP_X,
                                            UI_BUTTON_SIZE_X,
                                            UI_BUTTON_SIZE_Y);
        string isOn = m_arCameraPostProcess.enabled ? "Off" : "On";
        if (GUI.Button(distortionButtonRec,
                       UI_FONT_SIZE + "Turn Distortion " + isOn + "</size>"))
        {
            m_arCameraPostProcess.enabled = !m_arCameraPostProcess.enabled;
        }

        if (m_showDebug && m_tangoApplication.HasRequestedPermissions())
        {
            Color oldColor = GUI.color;
            GUI.color = Color.white;

            GUI.color = Color.black;
            GUI.Label(new Rect(UI_LABEL_START_X,
                               UI_LABEL_START_Y,
                               UI_LABEL_SIZE_X,
                               UI_LABEL_SIZE_Y),
                      UI_FONT_SIZE + String.Format(UX_TANGO_SERVICE_VERSION, m_tangoServiceVersion) + "</size>");

            GUI.Label(new Rect(UI_LABEL_START_X,
                               UI_FPS_LABEL_START_Y,
                               UI_LABEL_SIZE_X,
                               UI_LABEL_SIZE_Y),
                      UI_FONT_SIZE + m_fpsText + "</size>");

            // MOTION TRACKING
            GUI.Label(new Rect(UI_LABEL_START_X,
                               UI_POSE_LABEL_START_Y - UI_LABEL_OFFSET,
                               UI_LABEL_SIZE_X,
                               UI_LABEL_SIZE_Y),
                      UI_FONT_SIZE + String.Format(UX_TARGET_TO_BASE_FRAME, "Device", "Start") + "</size>");

            Vector3 pos = m_tangoPose.transform.position;
            Quaternion quat = m_tangoPose.transform.rotation;
            string positionString = pos.x.ToString(UI_FLOAT_FORMAT) + ", " +
                pos.y.ToString(UI_FLOAT_FORMAT) + ", " +
                    pos.z.ToString(UI_FLOAT_FORMAT);
            string rotationString = quat.x.ToString(UI_FLOAT_FORMAT) + ", " +
                quat.y.ToString(UI_FLOAT_FORMAT) + ", " +
                    quat.z.ToString(UI_FLOAT_FORMAT) + ", " +
                    quat.w.ToString(UI_FLOAT_FORMAT);
            string statusString = String.Format(UX_STATUS,
                                                _GetLoggingStringFromPoseStatus(m_tangoPose.m_poseStatus),
                                                _GetLoggingStringFromFrameCount(m_tangoPose.m_poseCount),
                                                positionString, rotationString);
            GUI.Label(new Rect(UI_LABEL_START_X,
                               UI_POSE_LABEL_START_Y,
                               UI_LABEL_SIZE_X,
                               UI_LABEL_SIZE_Y),
                      UI_FONT_SIZE + statusString + "</size>");
            GUI.color = oldColor;
        }

        if (m_selectedMarker != null)
        {
            Renderer selectedRenderer = m_selectedMarker.GetComponent<Renderer>();

            // GUI's Y is flipped from the mouse's Y
            Rect screenRect = WorldBoundsToScreen(Camera.main, selectedRenderer.bounds);
            float yMin = Screen.height - screenRect.yMin;
            float yMax = Screen.height - screenRect.yMax;
            screenRect.yMin = Mathf.Min(yMin, yMax);
            screenRect.yMax = Mathf.Max(yMin, yMax);

            if (GUI.Button(screenRect, "<size=30>Hide</size>"))
            {
                m_selectedMarker.SendMessage("Hide");
                m_selectedMarker = null;
                m_selectedRect = new Rect();
            }
            else
            {
                m_selectedRect = screenRect;
            }
        }
        else
        {
            m_selectedRect = new Rect();
        }

        if (GameObject.FindObjectOfType<ARMarker>() != null)
        {
            m_hideAllRect = new Rect(Screen.width - UI_BUTTON_SIZE_X - UI_BUTTON_GAP_X,
                                     Screen.height - UI_BUTTON_SIZE_Y - UI_BUTTON_GAP_X,
                                     UI_BUTTON_SIZE_X,
                                     UI_BUTTON_SIZE_Y);
            if (GUI.Button(m_hideAllRect, "<size=30>Hide All</size>"))
            {
                foreach (ARMarker marker in GameObject.FindObjectsOfType<ARMarker>())
                {
                    marker.SendMessage("Hide");
                }
            }
        }
        else
        {
            m_hideAllRect = new Rect(0, 0, 0, 0);
        }
    }
    /// <summary>
    /// Unity Update function.
    /// 
    /// Mainly handle the touch event and place mark in place.
    /// </summary>
    public void Update()
    {
        if (m_saveThread != null && m_saveThread.ThreadState != ThreadState.Running)
        {
            // After saving an Area Description or mark data, we reload the scene to restart the game.
            _UpdateMarkersForLoopClosures();

            // Compose a XML data list.
            List<MarkerData> xmlDataList = new List<MarkerData>();
            foreach (GameObject obj in m_markerList)
            {
                // Add marks data to the list, we intentionally didn't add the timestamp, because the timestamp will not be
                // useful when the next time Tango Service is connected. The timestamp is only used for loop closure pose
                // correction in current Tango connection.
                MarkerData temp = new MarkerData();
                temp.m_type = obj.GetComponent<ARMarker>().m_type;
                temp.m_position = obj.transform.position;
                temp.m_orientation = obj.transform.rotation;
                xmlDataList.Add(temp);
            }

            _WriteToXml(m_curAreaDescription.m_uuid + ".xml", xmlDataList);
            Application.LoadLevel(Application.loadedLevel);
        }

        if (!m_initialized)
        {
            return;
        }

        if (EventSystem.current.IsPointerOverGameObject(0) || GUIUtility.hotControl != 0)
        {
            return;
        }

        if (Input.touchCount == 1)
        {
            Touch t = Input.GetTouch(0);
            Vector2 guiPosition = new Vector2(t.position.x, Screen.height - t.position.y);
            Camera cam = Camera.main;
            RaycastHit hitInfo;

            if (t.phase != TouchPhase.Began)
            {
                return;
            }

            if (m_selectedRect.Contains(guiPosition))
            {
                // do nothing, the button will handle it
            }
            else if (Physics.Raycast(cam.ScreenPointToRay(t.position), out hitInfo))
            {
                // Found a marker, select it (so long as it isn't disappearing)!
                GameObject tapped = hitInfo.collider.gameObject;
                if (!tapped.GetComponent<Animation>().isPlaying)
                {
                    m_selectedMarker = tapped.GetComponent<ARMarker>();
                }
            }
            else
            {
                // Place a new point at that location, clear selection
                m_selectedMarker = null;
                StartCoroutine(_WaitForDepthAndFindPlane(t.position));
                
                // Because we may wait a small amount of time, this is a good place to play a small
                // animation so the user knows that their input was received.
                RectTransform touchEffectRectTransform = Instantiate(m_prefabTouchEffect) as RectTransform;
                touchEffectRectTransform.transform.SetParent(m_canvas.transform, false);
                Vector2 normalizedPosition = t.position;
                normalizedPosition.x /= Screen.width;
                normalizedPosition.y /= Screen.height;
                touchEffectRectTransform.anchorMin = touchEffectRectTransform.anchorMax = normalizedPosition;
            }
        }

        if (Input.GetKey(KeyCode.Escape))
        {
            Application.LoadLevel(Application.loadedLevel);
        }
    }
예제 #42
0
 public void OnMarkerLost(ARMarker marker)
 {
     visibleMarkers.Remove (marker);
 }
예제 #43
0
	private static void DrawNFTMarker(ARMarker m, Matrix4x4 mat, bool selected) 
    {
        float pattWidth = m.NFTWidth;
		float pattHeight = m.NFTHeight;
		//Debug.Log("DrawNFTMarker got pattWidth=" + pattWidth + ", pattHeight=" + pattHeight + ".");
		if (pattWidth > 0.0f && pattHeight > 0.0f) {

			float biggestSide = Math.Max(pattWidth, pattHeight);
			Vector3 origin = mat.GetColumn(3);
			Vector3 right = mat.GetColumn(0);
			Vector3 up = mat.GetColumn(1);
			Vector3 centre = origin + right*0.5f*pattWidth + up*0.5f*pattHeight;

        	//float d = selected ? 1.0f : 0.0f;
     
			DrawRectangle(centre, up, right, pattWidth, pattHeight, selected ? MarkerBorderSelected : MarkerBorderUnselected);
			DrawRectangle(centre, up, right, pattWidth + biggestSide*0.05f, pattHeight + biggestSide*0.05f, selected ? MarkerEdgeSelected : MarkerEdgeUnselected);

        	//Gizmos.DrawGUITexture(new Rect(centre.x, centre.y, 20, 20), m.MarkerImage);
		
			float wordUnitSize = pattHeight * 0.02f;
			DrawWord(m.Tag, wordUnitSize, centre - up*(pattHeight*0.6f + (wordUnitSize*4)) - right*pattWidth*0.525f, up, right*0.5f);
		}
	}
예제 #44
0
    private static void DrawSingleMarker(ARMarker m, Matrix4x4 mat, bool selected) 
    {
        float pattWidth = m.PatternWidth;
		Vector3 origin = mat.GetColumn(3);
		Vector3 right = mat.GetColumn(0);
		Vector3 up = mat.GetColumn(1);

        //float d = selected ? 1.0f : 0.0f;
     
		DrawRectangle(origin, up, right, pattWidth * 0.5f, pattWidth * 0.5f, selected ? MarkerBorderSelected : MarkerBorderUnselected); // Inside border.
		DrawRectangle(origin, up, right, pattWidth, pattWidth, selected ? MarkerBorderSelected : MarkerBorderUnselected); // Edge.
		DrawRectangle(origin, up, right, pattWidth * 1.05f, pattWidth * 1.05f, selected ? MarkerEdgeSelected : MarkerEdgeUnselected); // Highlighting.

        //Gizmos.DrawGUITexture(new Rect(origin.x, origin.y, 20, 20), m.MarkerImage);
		
		float wordUnitSize = pattWidth * 0.02f;
		DrawWord(m.Tag, wordUnitSize, origin - up * (pattWidth * 0.6f + (wordUnitSize * 4)) - right * (pattWidth * 0.525f), up, right * 0.5f);
    }
예제 #45
0
	private static void DrawMultiMarker(ARMarker m, Matrix4x4 mat, bool selected) 
    {
		for (int i = 0; i < m.Patterns.Length; i++) {

			Matrix4x4 mat1 = mat * m.Patterns[i].matrix;

            float pattWidth = m.Patterns[i].width;

            //float d = selected ? 1.0f : 0.0f;

			Vector3 origin = mat1.GetColumn(3);
			Vector3 right = mat1.GetColumn(0);
			Vector3 up = mat1.GetColumn(1);

			DrawRectangle(origin, up, right, pattWidth * 0.5f, pattWidth * 0.5f, selected ? MarkerBorderSelected : MarkerBorderUnselected); // Inside border.
			DrawRectangle(origin, up, right, pattWidth, pattWidth, selected ? MarkerBorderSelected : MarkerBorderUnselected); // Edge.
			DrawRectangle(origin, up, right, pattWidth * 1.05f, pattWidth * 1.05f, selected ? MarkerEdgeSelected : MarkerEdgeUnselected); // Highlighting.

			float wordUnitSize = pattWidth * 0.02f;
			DrawWord(m.Tag + "(" + i + ")", wordUnitSize, origin - up * (pattWidth * 0.6f + (wordUnitSize * 4)) - right * (pattWidth * 0.525f), up, right * 0.5f);
		}
               
        //Gizmos.DrawGUITexture(new Rect(origin.x, origin.y, 20, 20), m.MarkerImage);
    }
    /// <summary>
    /// Unity Update function.
    /// 
    /// Mainly handle the touch event and place mark in place.
    /// </summary>
    public void Update()
    {
        if (m_saveThread != null && m_saveThread.ThreadState != ThreadState.Running)
        {
            // After saving an Area Description or mark data, we reload the scene to restart the game.
            Application.LoadLevel(Application.loadedLevel);
        }

        if (!m_initialized)
        {
            return;
        }
        if (EventSystem.current.IsPointerOverGameObject(0) || GUIUtility.hotControl != 0)
        {
            return;
        }

        if (Input.touchCount == 1)
        {
            Touch t = Input.GetTouch(0);
            Vector2 guiPosition = new Vector2(t.position.x, Screen.height - t.position.y);
            Camera cam = Camera.main;
            RaycastHit hitInfo;

            if (m_selectedRect.Contains(guiPosition))
            {
                // do nothing, the button will handle it.
            }
            else if (Physics.Raycast(cam.ScreenPointToRay(t.position), out hitInfo))
            {
                if (t.phase == TouchPhase.Began)
                {
                    GameObject tapped = hitInfo.collider.gameObject;
                    if (tapped.tag != "Ground")
                    {
                        if (!tapped.GetComponent<Animation>().isPlaying)
                        {
                            m_selectedMarker = tapped.GetComponent<ARMarker>();
                        }
                    }
                    else
                    {
                        // Instantiate marker object.
                        newMarkObject = Instantiate(m_markPrefabs[m_currentMarkType],
                                                    hitInfo.point,
                                                    Quaternion.identity) as GameObject;
                        ARMarker markerScript = newMarkObject.GetComponent<ARMarker>();

                        markerScript.m_type = m_currentMarkType;
                        markerScript.m_timestamp = m_deltaPoseController.m_poseTimestamp;

                        Matrix4x4 uwTDevice = Matrix4x4.TRS(m_deltaPoseController.m_tangoPosition,
                                                            m_deltaPoseController.m_tangoRotation,
                                                            Vector3.one);
                        Matrix4x4 uwTMarker = Matrix4x4.TRS(hitInfo.point,
                                                            Quaternion.identity,
                                                            Vector3.one);
                        markerScript.m_deviceTMarker = Matrix4x4.Inverse(uwTDevice) * uwTMarker;

                        m_markerList.Add(newMarkObject);
                    }
                }
                else if (t.phase == TouchPhase.Moved)
                {
                    // Move instantiate object
                    if (newMarkObject != null)
                    {
                        newMarkObject.transform.position = hitInfo.point;
                    }
                }
                else if (t.phase == TouchPhase.Ended)
                {
                    newMarkObject = null;
                }
            }
        }

        if (Input.GetKey(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
예제 #47
0
	/// <summary>
	/// Raises the marker lost event.
	/// </summary>
	/// <param name="marker">Marker.</param>
	void OnMarkerLost(ARMarker marker)
	{
	}
예제 #48
0
	/// <summary>
	/// Wait for the next depth update, then find the plane at the touch position.
	/// </summary>
	/// <returns>Coroutine IEnumerator.</returns>
	/// <param name="touchPosition">Touch position to find a plane at.</param>
	private IEnumerator _WaitForDepthAndFindPlane(Vector2 touchPosition)
	{
		m_findPlaneWaitingForDepth = true;
		
		// Turn on the camera and wait for a single depth update.
		m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.MAXIMUM);
		while (m_findPlaneWaitingForDepth)
		{
			yield return null;
		}
		
		m_tangoApplication.SetDepthCameraRate(TangoEnums.TangoDepthCameraRate.DISABLED);
		
		// Find the plane.
		Camera cam = Camera.main;
		Vector3 planeCenter;
		Plane plane;
		if (!m_pointCloud.FindPlane(cam, touchPosition, out planeCenter, out plane))
		{
			yield break;
		}
		
		Vector3 camForward = Camera.main.transform.forward;
		camForward.y = 0;
		camForward.Normalize ();
		
		m_instantiatedGame = (GameObject) Instantiate(m_prefabMarker, planeCenter, Quaternion.LookRotation(camForward, Vector3.up));
		m_placingTable = false;
		m_selectedMarker = null;
	}
예제 #49
0
 public void OnMarkerFound(ARMarker marker)
 {
     visibleMarkers.Add (marker);
 }
예제 #50
0
	/// <summary>
	/// Update location marker state.
	/// </summary>
	private void _UpdateLocationMarker()
	{
		if ((beerPongComponent != null && beerPongComponent.isActive) || m_placingTable)
			return;

		if (Input.touchCount != 0) {
			
			m_didTouchNow = !m_isTouching;
			m_isTouching = true;
			
			
			// Single tap -- place new location or select existing location.
			Touch t = Input.GetTouch (0);
			Vector2 guiPosition = new Vector2 (t.position.x, Screen.height - t.position.y);
			Camera cam = Camera.main;
			RaycastHit hitInfo;
			var ray = cam.ScreenPointToRay (t.position);


			//Dragging
			if (GameObject.FindObjectOfType<ARMarker> () != null) {
				
				Debug.Log ("Marker not null");
				
				if (Physics.Raycast (ray, out hitInfo)) {
					
					
					Debug.Log ("Got multiple touches and hit marker");
					GameObject tapped = hitInfo.collider.gameObject;
					if (tapped.transform.parent == m_instantiatedGame.transform) {
						//theObject = hitInfo.transform;
//						
//						if (m_didTouchNow)
//							m_offset = hitInfo.point - m_instantiatedGame.transform.position;
//						
//						float t1 = -(m_instantiatedGame.transform.position.y + m_offset.y) / ray.direction.y;
//						Vector3 newPosition = -ray.direction * t1;
//						
//						
//						//m_instantiatedGame.transform.position = new Vector3 (ray.origin.x + offSet.x, m_instantiatedGame.transform.position.y, ray.origin.z + offSet.z);     // Only move the object on a 2D plane.
//						m_instantiatedGame.transform.position = newPosition - m_offset;




						if (m_didTouchNow)
							m_offset = hitInfo.point - m_instantiatedGame.transform.position;
						

						float t1 = (m_instantiatedGame.transform.position.y - hitInfo.point.y + m_offset.y) / ray.direction.y;
						m_instantiatedGame.transform.position = ray.direction * t1 + hitInfo.point - m_offset;


						Debug.Log ("Moving Marker");
					}
					
				}
				return;
			} 

			//Adding Table
			if (Input.touchCount == 1) {
				

				if (t.phase != TouchPhase.Began) {
					return;
				}
				
				if (m_selectedRect.Contains (guiPosition) || m_hideAllRect.Contains (guiPosition)) {
					// do nothing, the button will handle it
				} else if (Physics.Raycast (cam.ScreenPointToRay (t.position), out hitInfo)) {
					// Found a marker, select it (so long as it isn't disappearing)!
					GameObject tapped = hitInfo.collider.gameObject;
					if (!tapped.GetComponent<Animation> ().isPlaying) {
						m_selectedMarker = tapped.GetComponent<ARMarker> ();
					}
				} else {
					Debug.Log ("Table Creation");
					// Place a new point at that location, clear selection
					m_placingTable = true;
					m_selectedMarker = null;
					StartCoroutine (_WaitForDepthAndFindPlane (t.position));
					
					// Because we may wait a small amount of time, this is a good place to play a small
					// animation so the user knows that their input was received.
					RectTransform touchEffectRectTransform = (RectTransform)Instantiate (m_prefabTouchEffect);
					touchEffectRectTransform.transform.SetParent (m_canvas.transform, false);
					Vector2 normalizedPosition = t.position;
					normalizedPosition.x /= Screen.width;
					normalizedPosition.y /= Screen.height;
					touchEffectRectTransform.anchorMin = touchEffectRectTransform.anchorMax = normalizedPosition;
				}
			}
		} //Closing the touchCount !=0 If
		else {
			m_isTouching = false;
			m_didTouchNow = false;
		}
		
		
		if (Input.touchCount == 2)
		{
			// Two taps -- toggle debug text
			Touch t0 = Input.GetTouch(0);
			Touch t1 = Input.GetTouch(1);
			
			if (t0.phase != TouchPhase.Began && t1.phase != TouchPhase.Began)
			{
				return;
			}
			
			m_showDebug = !m_showDebug;
			return;
		}
		
		if (Input.touchCount != 1)
		{
			return;
		}
	}
예제 #51
0
	public void OnMarkerFound(ARMarker marker){
		//Debug.Log("MARKER FOUND! WHEEEE!");
		MRIObject.Visible = true;
	}
예제 #52
0
	public void OnMarkerLost(ARMarker marker) {
		visibleMarkers.Remove (marker);
		//GameObject obj = GameObject.Find (marker.name + "/Container/Furniture");
		//CheckDisappearingObject(obj);
	}
예제 #53
0
	public void OnMarkerTracked(ARMarker marker)
	{
		MRIObject.Pose = marker.transform.position;
		//Debug.Log ("marker tracked: " + marker.Tag);
	}
예제 #54
0
    /// <summary>
    /// Update location marker state.
    /// </summary>
    private void _UpdateLocationMarker()
    {
        if (Input.touchCount == 1)
        {
            // Single tap -- place new location or select existing location.
            Touch t = Input.GetTouch(0);
            Vector2 guiPosition = new Vector2(t.position.x, Screen.height - t.position.y);
            Camera cam = Camera.main;
            RaycastHit hitInfo;

            if (t.phase != TouchPhase.Began)
            {
                return;
            }

            if (m_selectedRect.Contains(guiPosition) || m_hideAllRect.Contains(guiPosition))
            {
                // do nothing, the button will handle it
            }
            else if (Physics.Raycast(cam.ScreenPointToRay(t.position), out hitInfo))
            {
                // Found a marker, select it (so long as it isn't disappearing)!
                GameObject tapped = hitInfo.collider.gameObject;
                if (!tapped.GetComponent<Animation>().isPlaying)
                {
                    m_selectedMarker = tapped.GetComponent<ARMarker>();
                }
            }
            else
            {
                // Place a new point at that location, clear selection
                m_selectedMarker = null;
                StartCoroutine(_WaitForDepthAndFindPlane(t.position));

                // Because we may wait a small amount of time, this is a good place to play a small
                // animation so the user knows that their input was received.
                RectTransform touchEffectRectTransform = (RectTransform)Instantiate(m_prefabTouchEffect);
                touchEffectRectTransform.transform.SetParent(m_canvas.transform, false);
                Vector2 normalizedPosition = t.position;
                normalizedPosition.x /= Screen.width;
                normalizedPosition.y /= Screen.height;
                touchEffectRectTransform.anchorMin = touchEffectRectTransform.anchorMax = normalizedPosition;
            }
        }
        if (Input.touchCount == 2)
        {
            // Two taps -- toggle debug text
            Touch t0 = Input.GetTouch(0);
            Touch t1 = Input.GetTouch(1);

            if (t0.phase != TouchPhase.Began && t1.phase != TouchPhase.Began)
            {
                return;
            }

            m_showDebug = !m_showDebug;
            return;
        }

        if (Input.touchCount != 1)
        {
            return;
        }
    }
예제 #55
0
    /// <summary>
    /// Unity Update function.
    /// 
    /// Mainly handle the touch event and place mark in place.
    /// </summary>
    public void Update()
    {
        if (m_saveThread != null && m_saveThread.ThreadState != ThreadState.Running)
        {
            // After saving an Area Description or mark data, we reload the scene to restart the game.
            _UpdateMarkersForLoopClosures();
            _SaveMarkerToDisk();
            Application.LoadLevel(Application.loadedLevel);
        }

        if (!m_initialized)
        {
            return;
        }

        if (EventSystem.current.IsPointerOverGameObject(0) || GUIUtility.hotControl != 0)
        {
            return;
        }

        if (Input.touchCount == 1)
        {
            Touch t = Input.GetTouch(0);
            Vector2 guiPosition = new Vector2(t.position.x, Screen.height - t.position.y);
            Camera cam = Camera.main;
            RaycastHit hitInfo;

            if (t.phase != TouchPhase.Began)
            {
                return;
            }

            if (m_selectedRect.Contains(guiPosition))
            {
                // do nothing, the button will handle it
            }
            else if (Physics.Raycast(cam.ScreenPointToRay(t.position), out hitInfo))
            {
                // Found a marker, select it (so long as it isn't disappearing)!
                GameObject tapped = hitInfo.collider.gameObject;
                if (!tapped.GetComponent<Animation>().isPlaying)
                {
                    m_selectedMarker = tapped.GetComponent<ARMarker>();
                }
            }
            else
            {
                // Place a new point at that location, clear selection
                m_selectedMarker = null;
                StartCoroutine(_WaitForDepthAndFindPlane(t.position));
                
                // Because we may wait a small amount of time, this is a good place to play a small
                // animation so the user knows that their input was received.
                RectTransform touchEffectRectTransform = Instantiate(m_prefabTouchEffect) as RectTransform;
                touchEffectRectTransform.transform.SetParent(m_canvas.transform, false);
                Vector2 normalizedPosition = t.position;
                normalizedPosition.x /= Screen.width;
                normalizedPosition.y /= Screen.height;
                touchEffectRectTransform.anchorMin = touchEffectRectTransform.anchorMax = normalizedPosition;
            }
        }

        if (Input.GetKey(KeyCode.Escape))
        {
            Application.LoadLevel(Application.loadedLevel);
        }
    }
예제 #56
0
파일: AROrigin.cs 프로젝트: Eryns/Inception
	// Get the marker, if any, currently acting as the base.
	public ARMarker GetBaseMarker()
	{
		if (baseMarker != null) {
			if (baseMarker.Visible) return baseMarker;
			else baseMarker = null;
		}
		
		foreach (ARMarker m in markersEligibleForBaseMarker) {
			if (m.Visible) {
				baseMarker = m;
				//ARController.Log("Marker " + m.UID + " became base marker.");
				break;
			}
		}
		
		return baseMarker;
	}
예제 #57
0
파일: AROrigin.cs 프로젝트: Eryns/Inception
	public void RemoveAllMarkers()
	{
		baseMarker = null;
		markersEligibleForBaseMarker.Clear();
	}