EnsureSlamTrackingMode.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. using System.Collections;
  10. using UnityEngine;
  11. namespace NRKernal.NRExamples
  12. {
  13. /// <summary> An ensure slam tracking mode. </summary>
  14. public class EnsureSlamTrackingMode : MonoBehaviour
  15. {
  16. /// <summary> Type of the tracking. </summary>
  17. [SerializeField]
  18. private NRHMDPoseTracker.TrackingType m_TrackingType = NRHMDPoseTracker.TrackingType.Tracking6Dof;
  19. /// <summary> Starts this object. </summary>
  20. void Start()
  21. {
  22. StartCoroutine(EnsureTrackingType(m_TrackingType));
  23. }
  24. private IEnumerator EnsureTrackingType(NRHMDPoseTracker.TrackingType type)
  25. {
  26. WaitForEndOfFrame waitForEndOfFrame = new WaitForEndOfFrame();
  27. if (m_TrackingType == NRHMDPoseTracker.TrackingType.Tracking0Dof && NRSessionManager.Instance.NRHMDPoseTracker.TrackingMode != m_TrackingType)
  28. {
  29. while (!NRSessionManager.Instance.NRHMDPoseTracker.ChangeTo0Dof(null))
  30. {
  31. yield return waitForEndOfFrame;
  32. }
  33. }
  34. else if (m_TrackingType == NRHMDPoseTracker.TrackingType.Tracking0DofStable && NRSessionManager.Instance.NRHMDPoseTracker.TrackingMode != m_TrackingType)
  35. {
  36. while (!NRSessionManager.Instance.NRHMDPoseTracker.ChangeTo0DofStable(null))
  37. {
  38. yield return waitForEndOfFrame;
  39. }
  40. }
  41. else if (m_TrackingType == NRHMDPoseTracker.TrackingType.Tracking3Dof && NRSessionManager.Instance.NRHMDPoseTracker.TrackingMode != m_TrackingType)
  42. {
  43. while (!NRSessionManager.Instance.NRHMDPoseTracker.ChangeTo3Dof(null))
  44. {
  45. yield return waitForEndOfFrame;
  46. }
  47. }
  48. else if (m_TrackingType == NRHMDPoseTracker.TrackingType.Tracking6Dof && NRSessionManager.Instance.NRHMDPoseTracker.TrackingMode != m_TrackingType)
  49. {
  50. while (!NRSessionManager.Instance.NRHMDPoseTracker.ChangeTo6Dof(null))
  51. {
  52. yield return waitForEndOfFrame;
  53. }
  54. }
  55. }
  56. }
  57. }