NativeTracking.cs 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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. using System;
  12. using System.Runtime.InteropServices;
  13. /// <summary> Native Tracking API. </summary>
  14. public partial class NativeTracking
  15. {
  16. /// <summary> The native interface. </summary>
  17. private NativeInterface m_NativeInterface;
  18. /// <summary> Handle of the tracking. </summary>
  19. private UInt64 m_TrackingHandle;
  20. /// <summary> Constructor. </summary>
  21. /// <param name="nativeInterface"> The native interface.</param>
  22. public NativeTracking(NativeInterface nativeInterface)
  23. {
  24. m_NativeInterface = nativeInterface;
  25. }
  26. /// <summary> Creates a new bool. </summary>
  27. /// <returns> True if it succeeds, false if it fails. </returns>
  28. public bool Create()
  29. {
  30. NativeResult result = NativeApi.NRTrackingCreate(ref m_TrackingHandle);
  31. NativeErrorListener.Check(result, this, "Create");
  32. m_NativeInterface.TrackingHandle = m_TrackingHandle;
  33. return result == NativeResult.Success;
  34. }
  35. /// <summary> Inits tracking mode. </summary>
  36. /// <param name="mode"> The mode.</param>
  37. /// <returns> True if it succeeds, false if it fails. </returns>
  38. public bool InitTrackingMode(TrackingMode mode)
  39. {
  40. if (m_TrackingHandle == 0)
  41. {
  42. return false;
  43. }
  44. NativeResult result = NativeApi.NRTrackingInitSetTrackingMode(m_TrackingHandle, mode);
  45. NativeErrorListener.Check(result, this, "InitTrackingMode");
  46. return result == NativeResult.Success;
  47. }
  48. /// <summary> Starts this object. </summary>
  49. /// <returns> True if it succeeds, false if it fails. </returns>
  50. public bool Start()
  51. {
  52. if (m_TrackingHandle == 0)
  53. {
  54. return false;
  55. }
  56. NativeResult result = NativeApi.NRTrackingStart(m_TrackingHandle);
  57. NativeErrorListener.Check(result, this, "Start");
  58. return result == NativeResult.Success;
  59. }
  60. /// <summary> Switch tracking mode. </summary>
  61. /// <param name="mode"> The mode.</param>
  62. /// <returns> True if it succeeds, false if it fails. </returns>
  63. public bool SwitchTrackingMode(TrackingMode mode)
  64. {
  65. NativeResult result = NativeApi.NRTrackingSetTrackingMode(m_TrackingHandle, mode);
  66. NativeErrorListener.Check(result, this, "SwitchTrackingMode");
  67. return result == NativeResult.Success;
  68. }
  69. /// <summary> Pauses this object. </summary>
  70. /// <returns> True if it succeeds, false if it fails. </returns>
  71. public bool Pause()
  72. {
  73. if (m_TrackingHandle == 0)
  74. {
  75. return false;
  76. }
  77. NativeResult result = NativeApi.NRTrackingPause(m_TrackingHandle);
  78. NativeErrorListener.Check(result, this, "Pause");
  79. return result == NativeResult.Success;
  80. }
  81. /// <summary> Resumes this object. </summary>
  82. /// <returns> True if it succeeds, false if it fails. </returns>
  83. public bool Resume()
  84. {
  85. if (m_TrackingHandle == 0)
  86. {
  87. return false;
  88. }
  89. NativeResult result = NativeApi.NRTrackingResume(m_TrackingHandle);
  90. NativeErrorListener.Check(result, this, "Resume");
  91. return result == NativeResult.Success;
  92. }
  93. /// <summary> only worked at 3dof mode. </summary>
  94. public void Recenter()
  95. {
  96. if (m_TrackingHandle == 0)
  97. {
  98. return;
  99. }
  100. var result = NativeApi.NRTrackingRecenter(m_TrackingHandle);
  101. NativeErrorListener.Check(result, this, "Recenter");
  102. }
  103. /// <summary> Destroys this object. </summary>
  104. /// <returns> True if it succeeds, false if it fails. </returns>
  105. public bool Destroy()
  106. {
  107. if (m_TrackingHandle == 0)
  108. {
  109. return false;
  110. }
  111. NativeResult result = NativeApi.NRTrackingDestroy(m_TrackingHandle);
  112. NativeErrorListener.Check(result, this, "Destroy");
  113. m_TrackingHandle = 0;
  114. m_NativeInterface.TrackingHandle = m_TrackingHandle;
  115. return result == NativeResult.Success;
  116. }
  117. private partial struct NativeApi
  118. {
  119. /// <summary> Nr tracking create. </summary>
  120. /// <param name="out_tracking_handle"> [in,out] Handle of the out tracking.</param>
  121. /// <returns> A NativeResult. </returns>
  122. [DllImport(NativeConstants.NRNativeLibrary)]
  123. public static extern NativeResult NRTrackingCreate(ref UInt64 out_tracking_handle);
  124. /// <summary> Nr tracking initialize set tracking mode. </summary>
  125. /// <param name="tracking_handle"> Handle of the tracking.</param>
  126. /// <param name="tracking_mode"> The tracking mode.</param>
  127. /// <returns> A NativeResult. </returns>
  128. [DllImport(NativeConstants.NRNativeLibrary)]
  129. public static extern NativeResult NRTrackingInitSetTrackingMode(UInt64 tracking_handle, TrackingMode tracking_mode);
  130. /// <summary> Nr tracking start. </summary>
  131. /// <param name="tracking_handle"> Handle of the tracking.</param>
  132. /// <returns> A NativeResult. </returns>
  133. [DllImport(NativeConstants.NRNativeLibrary)]
  134. public static extern NativeResult NRTrackingStart(UInt64 tracking_handle);
  135. /// <summary> Nr tracking set tracking mode. </summary>
  136. /// <param name="tracking_handle"> Handle of the tracking.</param>
  137. /// <param name="tracking_mode"> The tracking mode.</param>
  138. /// <returns> A NativeResult. </returns>
  139. [DllImport(NativeConstants.NRNativeLibrary)]
  140. public static extern NativeResult NRTrackingSetTrackingMode(UInt64 tracking_handle, TrackingMode tracking_mode);
  141. /// <summary> Nr tracking destroy. </summary>
  142. /// <param name="tracking_handle"> Handle of the tracking.</param>
  143. /// <returns> A NativeResult. </returns>
  144. [DllImport(NativeConstants.NRNativeLibrary)]
  145. public static extern NativeResult NRTrackingDestroy(UInt64 tracking_handle);
  146. /// <summary> Nr tracking pause. </summary>
  147. /// <param name="tracking_handle"> Handle of the tracking.</param>
  148. /// <returns> A NativeResult. </returns>
  149. [DllImport(NativeConstants.NRNativeLibrary)]
  150. public static extern NativeResult NRTrackingPause(UInt64 tracking_handle);
  151. /// <summary> Nr tracking resume. </summary>
  152. /// <param name="tracking_handle"> Handle of the tracking.</param>
  153. /// <returns> A NativeResult. </returns>
  154. [DllImport(NativeConstants.NRNativeLibrary)]
  155. public static extern NativeResult NRTrackingResume(UInt64 tracking_handle);
  156. /// <summary> Nr tracking recenter. </summary>
  157. /// <param name="tracking_handle"> Handle of the tracking.</param>
  158. /// <returns> A NativeResult. </returns>
  159. [DllImport(NativeConstants.NRNativeLibrary)]
  160. public static extern NativeResult NRTrackingRecenter(UInt64 tracking_handle);
  161. };
  162. }
  163. }