/// <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); }
/// <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. lastCreatedMarker = newMarkObject; newMarkObject = Instantiate(m_markPrefabs[m_currentMarkType], planeCenter, Quaternion.LookRotation(forward, up)) as GameObject; ARMarker markerScript = newMarkObject.GetComponent <ARMarker>(); int newMarker_id = markerScript.GetID(); 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(newMarker_id, newMarkObject); m_selectedMarker = null; // Create independent marker if (m_currentMethodType == 2) { yield break; } // Created first marker => can not create connection if (lastCreatedMarker != null) { ARMarker lastTmp = lastCreatedMarker.GetComponent <ARMarker>(); ARMarker newTmp = newMarkObject.GetComponent <ARMarker>(); lastTmp.AddLine(newTmp.GetID(), newTmp.transform.position); } }