Api.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. namespace FFalcon.XR.Runtime
  2. {
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. using UnityEngine;
  8. public static class Api
  9. {
  10. private static bool mIsDeviceConfigChanged;
  11. private static ScreenOrientation mLastScreenOrientation;
  12. public static void ReloadDeviceParams()
  13. {
  14. if (!XRLoader.mIsInitialized)
  15. {
  16. return;
  17. }
  18. Debug.Log("[FFalconXR] Reload device parameters.");
  19. FXRUnity_SetDeviceParamsChanged();
  20. mIsDeviceConfigChanged = false;
  21. }
  22. public static void UpdateScreenParams()
  23. {
  24. if (!XRLoader.mIsInitialized)
  25. {
  26. Debug.LogError("Please initialize FFalcon XR loader before UpdateScreenParams.");
  27. return;
  28. }
  29. if (mLastScreenOrientation != Screen.orientation)
  30. {
  31. XRLoader.RecalculateRectangles(Screen.safeArea);
  32. mLastScreenOrientation = Screen.orientation;
  33. mIsDeviceConfigChanged = true;
  34. }
  35. if (mIsDeviceConfigChanged)
  36. {
  37. ReloadDeviceParams();
  38. }
  39. }
  40. public static void Recenter()
  41. {
  42. if (!XRLoader.mIsInitialized)
  43. {
  44. Debug.LogError("Please initialize FFalcon XR loader before Recenter.");
  45. return;
  46. }
  47. FXRUnity_RecenterHeadTracker();
  48. }
  49. public static void EnableSlamHeadTracker()
  50. {
  51. if (!XRLoader.mIsInitialized)
  52. {
  53. Debug.LogError("Please initialize FFalcon XR loader before EnableSlamHeadTracker.");
  54. return;
  55. }
  56. FXRUnity_EnableSlamHeadTracker();
  57. }
  58. public static void DisableSlamHeadTracker()
  59. {
  60. if (!XRLoader.mIsInitialized)
  61. {
  62. Debug.LogError("Please initialize FFalcon XR loader before DisableSlamHeadTracker.");
  63. return;
  64. }
  65. FXRUnity_DisableSlamHeadTracker();
  66. }
  67. public static float[] GetNineAxisOrientation(float[] orientation)
  68. {
  69. if (!XRLoader.mIsInitialized)
  70. {
  71. Debug.LogError("Please initialize FFalcon XR loader before GetNineAxisOrientation.");
  72. return orientation;
  73. }
  74. FXRUnity_NineAxisOrientation(orientation);
  75. return orientation;
  76. }
  77. public static int GetHeadTrackerStatus()
  78. {
  79. if (!XRLoader.mIsInitialized)
  80. {
  81. Debug.LogError("Please initialize FFalcon XR loader before GetHeadTrackerStatus.");
  82. return -1;
  83. }
  84. return FXRUnity_GetHeadTrackerStatus();
  85. }
  86. [DllImport(ApiConstants.FxrApi)]
  87. private static extern void FXRUnity_SetDeviceParamsChanged();
  88. [DllImport(ApiConstants.FxrApi)]
  89. private static extern void FXRUnity_RecenterHeadTracker();
  90. [DllImport(ApiConstants.FxrApi)]
  91. private static extern void FXRUnity_EnableSlamHeadTracker();
  92. [DllImport(ApiConstants.FxrApi)]
  93. private static extern void FXRUnity_DisableSlamHeadTracker();
  94. [DllImport(ApiConstants.FxrApi)]
  95. private static extern void FXRUnity_NineAxisOrientation(float[] orientation);
  96. [DllImport(ApiConstants.FxrApi)]
  97. public static extern float FXRUnity_NineAxisAzimuth();
  98. [DllImport(ApiConstants.FxrApi)]
  99. private static extern int FXRUnity_GetHeadTrackerStatus();
  100. public static long CreateFaceDetector()
  101. {
  102. IntPtr pHandle;
  103. if (FXRFeature_CreateFaceDetector(out pHandle) == 0)
  104. {
  105. return pHandle.ToInt64();
  106. }
  107. return 0;
  108. }
  109. public static void InitFaceDetector()
  110. {
  111. FXRFeature_InitFaceDetector();
  112. }
  113. public static void DestroyFaceDetector()
  114. {
  115. FXRFeature_DestroyFaceDetector();
  116. }
  117. public static void SetCameraFrameRate(int fps)
  118. {
  119. FXRFeature_SetFrameRate(fps);
  120. }
  121. /// <summary>
  122. /// ��ȡ������������������
  123. /// </summary>
  124. /// <param name="position">��Ҫ����float[3]</param>
  125. /// <returns></returns>
  126. public static float[] GetFacePosition(float[] position)
  127. {
  128. //float[] position = new float[3];
  129. FXRFeature_GetFacePosition(position, position.Length);
  130. return position;
  131. }
  132. public static float[] GetFaceInCamera(float[] position)
  133. {
  134. //float[] position = new float[3];
  135. FXRFeature_GetFaceInCamera(position, position.Length);
  136. return position;
  137. }
  138. public static float[] GetFaceLookAt()
  139. {
  140. float[] lookAt = new float[3];
  141. FXRFeature_GetFaceLookAt(lookAt, lookAt.Length);
  142. return lookAt;
  143. }
  144. public static bool CheckFaceState()
  145. {
  146. return FXRFeature_CheckFaceState();
  147. }
  148. [DllImport(ApiConstants.FxrAlgorithm)]
  149. private static extern int FXRFeature_CreateFaceDetector(out IntPtr handle);
  150. [DllImport(ApiConstants.FxrAlgorithm)]
  151. private static extern void FXRFeature_InitFaceDetector();
  152. [DllImport(ApiConstants.FxrAlgorithm)]
  153. private static extern void FXRFeature_DestroyFaceDetector();
  154. [DllImport(ApiConstants.FxrAlgorithm)]
  155. private static extern void FXRFeature_GetFacePosition(float[] position, int size);
  156. [DllImport(ApiConstants.FxrAlgorithm)]
  157. private static extern void FXRFeature_GetFaceInCamera(float[] position, int size);
  158. [DllImport(ApiConstants.FxrAlgorithm)]
  159. private static extern void FXRFeature_GetFaceLookAt(float[] lookAt, int size);
  160. [DllImport(ApiConstants.FxrAlgorithm)]
  161. private static extern void FXRFeature_SetFrameRate(int fps);
  162. [DllImport(ApiConstants.FxrAlgorithm)]
  163. private static extern bool FXRFeature_CheckFaceState();
  164. }
  165. }