/// <summary> /// Update is called once per frame. /// </summary> private void Update() { if (shouldInitTango) { tangoApplication.InitApplication(); isInitialized = true; shouldInitTango = false; } }
/// <summary> /// Internal callback when a permissions event happens. /// </summary> /// <param name="permissionsGranted">If set to <c>true</c> permissions granted.</param> private void _OnTangoApplicationPermissionsEvent(bool permissionsGranted) { if (permissionsGranted) { m_tangoApplication.InitApplication(); // Load the most recent ADF. PoseProvider.RefreshADFList(); UUIDUnityHolder latestAreaDescription = PoseProvider.GetLatestADFUUID(); if (latestAreaDescription != null) { string uuid = latestAreaDescription.GetStringDataUUID(); m_tangoApplication.InitProviders(uuid); } else { m_tangoApplication.InitProviders(null); } m_tangoApplication.ConnectToService(); } else { AndroidHelper.ShowAndroidToastMessage("Motion Tracking and Area Learning Permissions Needed", true); } }
private void _OnTangoApplicationPermissionsEvent(bool permissionsGranted) { if (permissionsGranted) { m_tangoApplication.InitApplication(); if (m_useADF) { // Query the full adf list. PoseProvider.RefreshADFList(); // loading last recorded ADF string uuid = PoseProvider.GetLatestADFUUID().GetStringDataUUID(); m_tangoApplication.InitProviders(uuid); } else { m_tangoApplication.InitProviders(string.Empty); } m_tangoApplication.ConnectToService(); } else if (!permissionsGranted) { AndroidHelper.ShowAndroidToastMessage("Motion Tracking and Area Learning Permissions Needed", true); } }
/// <summary> /// Use this for initialization. /// </summary> public void Start() { // get the reference of mesh MeshFilter mf = gameObject.GetComponent <MeshFilter>(); if (mf == null) { MeshFilter meshFilter = (MeshFilter)gameObject.AddComponent(typeof(MeshFilter)); meshFilter.mesh = m_mesh = new Mesh(); MeshRenderer renderer = gameObject.AddComponent(typeof(MeshRenderer)) as MeshRenderer; renderer.material.shader = Shader.Find("Mobile/Unlit (Supports Lightmap)"); } else { m_mesh = mf.mesh; } m_isDirty = false; _CreateMesh(); transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y * -1.0f, transform.localScale.z); m_tangoApplication = FindObjectOfType <TangoApplication>(); if (m_tangoApplication != null) { // Request Tango permissions m_tangoApplication.RequestNecessaryPermissions(); if (TangoApplication.HasGrantedPermissions()) { m_tangoApplication.InitApplication(); if (m_useADF) { // Query the full adf list. PoseProvider.RefreshADFList(); // loading last recorded ADF string uuid = PoseProvider.GetLatestADFUUID().GetStringDataUUID(); m_tangoApplication.InitProviders(uuid); } else { m_tangoApplication.InitProviders(string.Empty); } m_tangoApplication.ConnectToService(); } else { UnityEngine.Debug.Log("Tango can't be initialized because of invalid permissions"); } } else { UnityEngine.Debug.Log("No Tango Manager found in scene."); } }
/// <summary> /// This callback function is called after user appoved or declined the permission to use Motion Tracking. /// </summary> private void _OnTangoApplicationPermissionsEvent(bool permissionsGranted) { if (permissionsGranted) { m_tangoApplication.InitApplication(); m_tangoApplication.InitProviders(string.Empty); m_tangoApplication.ConnectToService(); // Ask ARScreen to query the camera intrinsics from Tango Service. m_arScreen.SetCameraIntrinsics(); // The following code is querying the camera extrinsic, for example: the transformation between // IMU and device frame. These extrinsics is used to transform the pose from the device frame // to the color camera frame. Because the extrinsic is being queried using the GetPoseAtTime() // with a desired frame pair, it can only be queried after the ConnectToService() is called. // // The device with respect to IMU frame is not directly queryable from API, so we use the IMU // frame as a temporary value to get the device frame with respect to IMU frame. double timestamp = 0.0; TangoCoordinateFramePair pair; TangoPoseData poseData = new TangoPoseData(); // Getting the transformation of device frame with respect to IMU frame. pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU; pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE; PoseProvider.GetPoseAtTime(poseData, timestamp, pair); Vector3 position = new Vector3((float)poseData.translation[0], (float)poseData.translation[1], (float)poseData.translation[2]); Quaternion quat = new Quaternion((float)poseData.orientation[0], (float)poseData.orientation[1], (float)poseData.orientation[2], (float)poseData.orientation[3]); m_imuTd = Matrix4x4.TRS(position, quat, new Vector3(1.0f, 1.0f, 1.0f)); // Getting the transformation of IMU frame with respect to color camera frame. pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU; pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_CAMERA_COLOR; PoseProvider.GetPoseAtTime(poseData, timestamp, pair); position = new Vector3((float)poseData.translation[0], (float)poseData.translation[1], (float)poseData.translation[2]); quat = new Quaternion((float)poseData.orientation[0], (float)poseData.orientation[1], (float)poseData.orientation[2], (float)poseData.orientation[3]); m_imuTc = Matrix4x4.TRS(position, quat, new Vector3(1.0f, 1.0f, 1.0f)); } else { AndroidHelper.ShowAndroidToastMessage("Motion Tracking Permissions Needed", true); } }
/// <summary> /// Internal callback when a permissions event happens. /// </summary> /// <param name="permissionsGranted">If set to <c>true</c> permissions granted.</param> public void OnTangoPermissions(bool permissionsGranted) { if (permissionsGranted) { m_tangoApplication.InitApplication(); _PopulateList(); } else { AndroidHelper.ShowAndroidToastMessage("Motion Tracking and Area Learning Permissions Needed", true); } }
/// <summary> /// Apply any needed changes to the pose. /// </summary> private void Update() { if (m_shouldInitTango) { m_tangoApplication.InitApplication(); m_tangoApplication.InitProviders(string.Empty); m_tangoApplication.ConnectToService(); m_shouldInitTango = false; double timestamp = 0.0; TangoCoordinateFramePair pair; TangoPoseData poseData = new TangoPoseData(); pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU; pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE; PoseProvider.GetPoseAtTime(poseData, timestamp, pair); Vector3 position = new Vector3((float)poseData.translation[0], (float)poseData.translation[1], (float)poseData.translation[2]); Quaternion quat = new Quaternion((float)poseData.orientation[0], (float)poseData.orientation[1], (float)poseData.orientation[2], (float)poseData.orientation[3]); m_imuTd = Matrix4x4.TRS(position, quat, new Vector3(1.0f, 1.0f, 1.0f)); pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU; pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_CAMERA_COLOR; PoseProvider.GetPoseAtTime(poseData, timestamp, pair); position = new Vector3((float)poseData.translation[0], (float)poseData.translation[1], (float)poseData.translation[2]); quat = new Quaternion((float)poseData.orientation[0], (float)poseData.orientation[1], (float)poseData.orientation[2], (float)poseData.orientation[3]); m_imuTc = Matrix4x4.TRS(position, quat, new Vector3(1.0f, 1.0f, 1.0f)); } if (m_isDirty) { Matrix4x4 ssTd = Matrix4x4.TRS(m_tangoPosition, m_tangoRotation, Vector3.one); Matrix4x4 uwTuc = m_uwTss * ssTd * Matrix4x4.Inverse(m_imuTd) * m_imuTc * m_cTuc; // Extract new local position transform.position = uwTuc.GetColumn(3); // Extract new local rotation transform.rotation = Quaternion.LookRotation(uwTuc.GetColumn(2), uwTuc.GetColumn(1)); } if (Input.GetKeyDown(KeyCode.Escape)) { if (m_tangoApplication != null) { m_tangoApplication.Shutdown(); } // This is a temporary fix for a lifecycle issue where calling // Application.Quit() here, and restarting the application immediately, // results in a hard crash. AndroidHelper.AndroidQuit(); } }
private void _OnTangoApplicationPermissionsEvent(bool permissionsGranted) { if (permissionsGranted) { m_tangoApplication.InitApplication(); m_tangoApplication.InitProviders(string.Empty); m_tangoApplication.ConnectToService(); } else { AndroidHelper.ShowAndroidToastMessage("Motion Tracking Permissions Needed", true); } }
/// <summary> /// Permissions callback. /// </summary> /// <param name="success">If set to <c>true</c> permissions are granted.</param> private void PermissionsCallback(bool success) { if (success) { m_tangoApplication.InitApplication(); // Initialize Tango Client m_tangoApplication.InitProviders(string.Empty); // Initialize listeners m_tangoApplication.ConnectToService(); // Connect to Tango Service } else { AndroidHelper.ShowAndroidToastMessage("Motion Tracking Permissions Needed", true); } }
private void _OnTangoApplicationPermissionsEvent(bool permissionsGranted) { if (permissionsGranted && !m_alreadyInitialized) { Debug.Log("SampleController._OnApplicationPermissionsEvent()"); m_tangoApplication.InitApplication(); if (m_useADF) { // Query the full adf list. PoseProvider.RefreshADFList(); // loading last recorded ADF string uuid = PoseProvider.GetLatestADFUUID().GetStringDataUUID(); m_tangoApplication.InitProviders(uuid); } else { m_tangoApplication.InitProviders(string.Empty); } m_tangoApplication.ConnectToService(); // Query extrinsics constant tranformations. TangoPoseData poseData = new TangoPoseData(); double timestamp = 0.0; TangoCoordinateFramePair pair; pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU; pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE; PoseProvider.GetPoseAtTime(poseData, timestamp, pair); Vector3 position = new Vector3((float)poseData.translation[0], (float)poseData.translation[1], (float)poseData.translation[2]); Quaternion quat = new Quaternion((float)poseData.orientation[0], (float)poseData.orientation[1], (float)poseData.orientation[2], (float)poseData.orientation[3]); m_deviceToIMUMatrix = Matrix4x4.TRS(position, quat, new Vector3(1.0f, 1.0f, 1.0f)); pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU; pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_CAMERA_COLOR; PoseProvider.GetPoseAtTime(poseData, timestamp, pair); position = new Vector3((float)poseData.translation[0], (float)poseData.translation[1], (float)poseData.translation[2]); quat = new Quaternion((float)poseData.orientation[0], (float)poseData.orientation[1], (float)poseData.orientation[2], (float)poseData.orientation[3]); m_cameraToIMUMatrix = Matrix4x4.TRS(position, quat, new Vector3(1.0f, 1.0f, 1.0f)); m_alreadyInitialized = true; } else if (!permissionsGranted) { AndroidHelper.ShowAndroidToastMessage("Motion Tracking Permissions Needed", true); } }
/// <summary> /// Internal callback when a permissions event happens. /// </summary> /// <param name="permissionsGranted">If set to <c>true</c> permissions granted.</param> private void _OnTangoApplicationPermissionsEvent(bool permissionsGranted) { if (permissionsGranted) { m_tangoApplication.InitApplication(); m_tangoApplication.InitProviders(string.Empty); m_tangoApplication.ConnectToService(); // Get camera extrinsics to form final matrix transforms _SetCameraExtrinsics(); } else { AndroidHelper.ShowAndroidToastMessage("Motion Tracking Permissions Needed", true); } }
/// <summary> /// Use this for initialization. /// </summary> public void Start() { Statics.currentTangoState = TangoPoseStates.Connecting; tangoApplication = FindObjectOfType <TangoApplication>(); if (tangoApplication == null) { tangoApplication = FindObjectOfType <TangoApplication>(); } tangoApplication.InitApplication(); tangoApplication.InitProviders(Statics.curADFId); tangoApplication.Register(this); tangoApplication.ConnectToService(); startingRotation = transform.rotation; }
/// <summary> /// This callback function is called after user appoved or declined the permission to use Motion Tracking. /// </summary> private void _OnTangoApplicationPermissionsEvent(bool permissionsGranted) { if (permissionsGranted) { m_tangoApplication.InitApplication(); m_tangoApplication.InitProviders(string.Empty); m_tangoApplication.ConnectToService(); // Ask ARScreen to query the camera intrinsics from Tango Service. _SetCameraIntrinsics(); _SetCameraExtrinsics(); } else { AndroidHelper.ShowAndroidToastMessage("Motion Tracking Permissions Needed", true); } }
/// <summary> /// Apply any needed changes to the pose. /// </summary> private void Update() { #if UNITY_ANDROID && !UNITY_EDITOR if (m_shouldInitTango) { m_tangoApplication.InitApplication(); m_tangoApplication.InitProviders(string.Empty); m_tangoApplication.ConnectToService(); m_shouldInitTango = false; } if (m_isDirty) { // Construct the start of service with respect to device matrix from the pose. Matrix4x4 ssTd = Matrix4x4.TRS(m_tangoPosition, m_tangoRotation, Vector3.one); // Converting from Tango coordinate frame to Unity coodinate frame. Matrix4x4 uwTuc = m_uwTss * ssTd * m_dTuc; // Extract new local position transform.position = uwTuc.GetColumn(3); // Extract new local rotation transform.rotation = Quaternion.LookRotation(uwTuc.GetColumn(2), uwTuc.GetColumn(1)); } if (Input.GetKeyDown(KeyCode.Escape)) { if (m_tangoApplication != null) { m_tangoApplication.Shutdown(); } // This is a temporary fix for a lifecycle issue where calling // Application.Quit() here, and restarting the application immediately, // results in a hard crash. AndroidHelper.AndroidQuit(); } #else Vector3 tempPosition = transform.position; Quaternion tempRotation = transform.rotation; PoseProvider.GetMouseEmulation(ref tempPosition, ref tempRotation); transform.rotation = tempRotation; transform.position = tempPosition; #endif }
private void Start() { m_tangoApplication = FindObjectOfType <TangoApplication>(); if (m_tangoApplication != null) { // Request Tango permissions m_tangoApplication.RequestNecessaryPermissions(); if (TangoApplication.HasGrantedPermissions()) { m_tangoApplication.InitApplication(); if (m_useADF) { // Query the full adf list. PoseProvider.RefreshADFList(); // loading last recorded ADF string uuid = PoseProvider.GetLatestADFUUID().GetStringDataUUID(); m_tangoApplication.InitProviders(uuid); } else { m_tangoApplication.InitProviders(string.Empty); } m_tangoApplication.ConnectToService(); } else { Debug.Log("Tango can't be initialized because of invalid permissions"); } } else { Debug.Log("No Tango Manager found in scene."); } m_tangoServiceVersionName = TangoApplication.GetTangoServiceVersion(); }
/// <summary> /// Apply any needed changes to the pose. /// </summary> private void Update() { #if UNITY_ANDROID && !UNITY_EDITOR if (m_shouldInitTango) { m_tangoApplication.InitApplication(); if (m_useADF) { // Query the full adf list. PoseProvider.RefreshADFList(); // loading last recorded ADF string uuid = PoseProvider.GetLatestADFUUID().GetStringDataUUID(); m_tangoApplication.InitProviders(uuid); } else { m_tangoApplication.InitProviders(string.Empty); } // Query extrinsics constant tranformations. TangoPoseData poseData = new TangoPoseData(); double timestamp = 0.0; TangoCoordinateFramePair pair; pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU; pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_DEVICE; PoseProvider.GetPoseAtTime(poseData, timestamp, pair); Vector3 position = new Vector3((float)poseData.translation[0], (float)poseData.translation[1], (float)poseData.translation[2]); Quaternion quat = new Quaternion((float)poseData.orientation[0], (float)poseData.orientation[1], (float)poseData.orientation[2], (float)poseData.orientation[3]); m_deviceToIMUMatrix = Matrix4x4.TRS(position, quat, new Vector3(1.0f, 1.0f, 1.0f)); pair.baseFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_IMU; pair.targetFrame = TangoEnums.TangoCoordinateFrameType.TANGO_COORDINATE_FRAME_CAMERA_COLOR; PoseProvider.GetPoseAtTime(poseData, timestamp, pair); position = new Vector3((float)poseData.translation[0], (float)poseData.translation[1], (float)poseData.translation[2]); quat = new Quaternion((float)poseData.orientation[0], (float)poseData.orientation[1], (float)poseData.orientation[2], (float)poseData.orientation[3]); m_cameraToIMUMatrix = Matrix4x4.TRS(position, quat, new Vector3(1.0f, 1.0f, 1.0f)); m_alreadyInitialized = true; m_shouldInitTango = false; m_tangoApplication.ConnectToService(); } if (m_isDirty) { // This rotation needs to be put into Unity coordinate space. Quaternion rotationFix = Quaternion.Euler(90.0f, 0.0f, 0.0f); if (!m_isRelocalized) { Quaternion axisFix = Quaternion.Euler(-m_tangoRotation[0].eulerAngles.x, -m_tangoRotation[0].eulerAngles.z, m_tangoRotation[0].eulerAngles.y); transform.rotation = m_startingRotation * (rotationFix * axisFix); transform.position = (m_startingRotation * (m_tangoPosition[0] * m_movementScale)) + m_startingOffset; } else { Quaternion axisFix = Quaternion.Euler(-m_tangoRotation[1].eulerAngles.x, -m_tangoRotation[1].eulerAngles.z, m_tangoRotation[1].eulerAngles.y); transform.rotation = m_startingRotation * (rotationFix * axisFix); transform.position = (m_startingRotation * (m_tangoPosition[1] * m_movementScale)) + m_startingOffset; } m_isDirty = false; } if (Input.GetKeyDown(KeyCode.Escape)) { if (m_tangoApplication != null) { m_tangoApplication.Shutdown(); } // This is a temporary fix for a lifecycle issue where calling // Application.Quit() here, and restarting the application immediately, // results in a hard crash. AndroidHelper.AndroidQuit(); } #else Vector3 tempPosition = transform.position; Quaternion tempRotation = transform.rotation; PoseProvider.GetMouseEmulation(ref tempPosition, ref tempRotation); transform.rotation = tempRotation; transform.position = tempPosition; #endif }