NRTrackingSubsystem.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. namespace NRKernal
  10. {
  11. public class NRTrackingSubsystemDescriptor : IntegratedSubsystemDescriptor<NRTrackingSubsystem>
  12. {
  13. public const string Name = "Subsystem.Tracking";
  14. public override string id => Name;
  15. }
  16. public class NRTrackingSubsystem : IntegratedSubsystem<NRTrackingSubsystemDescriptor>
  17. {
  18. private ITrackingDataProvider m_Provider;
  19. public NRTrackingSubsystem(NRTrackingSubsystemDescriptor descriptor) : base(descriptor)
  20. {
  21. #if UNITY_EDITOR
  22. m_Provider = new NREmulatorTrackingDataProvider();
  23. #else
  24. m_Provider = new NRTrackingDataProvider();
  25. #endif
  26. }
  27. public override void Start()
  28. {
  29. if (running)
  30. {
  31. return;
  32. }
  33. base.Start();
  34. m_Provider.Start();
  35. }
  36. public override void Pause()
  37. {
  38. if (!running)
  39. {
  40. return;
  41. }
  42. base.Pause();
  43. m_Provider.Pause();
  44. }
  45. public override void Resume()
  46. {
  47. if (running)
  48. {
  49. return;
  50. }
  51. base.Resume();
  52. m_Provider.Resume();
  53. }
  54. public override void Stop()
  55. {
  56. if (!running)
  57. {
  58. return;
  59. }
  60. base.Stop();
  61. m_Provider.Stop();
  62. }
  63. public bool GetFramePresentHeadPose(ref UnityEngine.Pose pose, ref LostTrackingReason lostReason, ref ulong timestamp)
  64. {
  65. return m_Provider.GetFramePresentHeadPose(ref pose, ref lostReason, ref timestamp);
  66. }
  67. public bool GetFramePresentTimeByCount(int count, ref ulong timestamp)
  68. {
  69. return m_Provider.GetFramePresentTimeByCount(count, ref timestamp);
  70. }
  71. public bool GetHeadPose(ref UnityEngine.Pose pose, ulong timestamp)
  72. {
  73. return m_Provider.GetHeadPose(ref pose, timestamp);
  74. }
  75. public ulong GetHMDTimeNanos()
  76. {
  77. return m_Provider.GetHMDTimeNanos();
  78. }
  79. public bool InitTrackingMode(TrackingMode mode)
  80. {
  81. return m_Provider.InitTrackingMode(mode);
  82. }
  83. public bool SwitchTrackingMode(TrackingMode mode)
  84. {
  85. return m_Provider.SwitchTrackingMode(mode);
  86. }
  87. public void Recenter()
  88. {
  89. m_Provider.Recenter();
  90. }
  91. }
  92. }