123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- namespace FFalcon.XR.Runtime
- {
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using UnityEngine;
- public static class Api
- {
- private static bool mIsDeviceConfigChanged;
- private static ScreenOrientation mLastScreenOrientation;
- public static void ReloadDeviceParams()
- {
- if (!XRLoader.mIsInitialized)
- {
- return;
- }
- Debug.Log("[FFalconXR] Reload device parameters.");
- FXRUnity_SetDeviceParamsChanged();
- mIsDeviceConfigChanged = false;
- }
- public static void UpdateScreenParams()
- {
- if (!XRLoader.mIsInitialized)
- {
- Debug.LogError("Please initialize FFalcon XR loader before UpdateScreenParams.");
- return;
- }
- if (mLastScreenOrientation != Screen.orientation)
- {
- XRLoader.RecalculateRectangles(Screen.safeArea);
- mLastScreenOrientation = Screen.orientation;
- mIsDeviceConfigChanged = true;
- }
- if (mIsDeviceConfigChanged)
- {
- ReloadDeviceParams();
- }
- }
- public static void Recenter()
- {
- if (!XRLoader.mIsInitialized)
- {
- Debug.LogError("Please initialize FFalcon XR loader before Recenter.");
- return;
- }
- FXRUnity_RecenterHeadTracker();
- }
- public static void EnableSlamHeadTracker()
- {
- if (!XRLoader.mIsInitialized)
- {
- Debug.LogError("Please initialize FFalcon XR loader before EnableSlamHeadTracker.");
- return;
- }
- FXRUnity_EnableSlamHeadTracker();
- }
- public static void DisableSlamHeadTracker()
- {
- if (!XRLoader.mIsInitialized)
- {
- Debug.LogError("Please initialize FFalcon XR loader before DisableSlamHeadTracker.");
- return;
- }
- FXRUnity_DisableSlamHeadTracker();
- }
- public static float[] GetNineAxisOrientation(float[] orientation)
- {
- if (!XRLoader.mIsInitialized)
- {
- Debug.LogError("Please initialize FFalcon XR loader before GetNineAxisOrientation.");
- return orientation;
- }
- FXRUnity_NineAxisOrientation(orientation);
- return orientation;
- }
- public static int GetHeadTrackerStatus()
- {
- if (!XRLoader.mIsInitialized)
- {
- Debug.LogError("Please initialize FFalcon XR loader before GetHeadTrackerStatus.");
- return -1;
- }
- return FXRUnity_GetHeadTrackerStatus();
- }
- [DllImport(ApiConstants.FxrApi)]
- private static extern void FXRUnity_SetDeviceParamsChanged();
- [DllImport(ApiConstants.FxrApi)]
- private static extern void FXRUnity_RecenterHeadTracker();
- [DllImport(ApiConstants.FxrApi)]
- private static extern void FXRUnity_EnableSlamHeadTracker();
- [DllImport(ApiConstants.FxrApi)]
- private static extern void FXRUnity_DisableSlamHeadTracker();
- [DllImport(ApiConstants.FxrApi)]
- private static extern void FXRUnity_NineAxisOrientation(float[] orientation);
- [DllImport(ApiConstants.FxrApi)]
- public static extern float FXRUnity_NineAxisAzimuth();
- [DllImport(ApiConstants.FxrApi)]
- private static extern int FXRUnity_GetHeadTrackerStatus();
- public static long CreateFaceDetector()
- {
- IntPtr pHandle;
- if (FXRFeature_CreateFaceDetector(out pHandle) == 0)
- {
- return pHandle.ToInt64();
- }
- return 0;
- }
- public static void InitFaceDetector()
- {
- FXRFeature_InitFaceDetector();
- }
- public static void DestroyFaceDetector()
- {
- FXRFeature_DestroyFaceDetector();
- }
- public static void SetCameraFrameRate(int fps)
- {
- FXRFeature_SetFrameRate(fps);
- }
- /// <summary>
- /// ��ȡ������������������
- /// </summary>
- /// <param name="position">��Ҫ����float[3]</param>
- /// <returns></returns>
- public static float[] GetFacePosition(float[] position)
- {
- //float[] position = new float[3];
- FXRFeature_GetFacePosition(position, position.Length);
- return position;
- }
- public static float[] GetFaceInCamera(float[] position)
- {
- //float[] position = new float[3];
- FXRFeature_GetFaceInCamera(position, position.Length);
- return position;
- }
- public static float[] GetFaceLookAt()
- {
- float[] lookAt = new float[3];
- FXRFeature_GetFaceLookAt(lookAt, lookAt.Length);
- return lookAt;
- }
- public static bool CheckFaceState()
- {
- return FXRFeature_CheckFaceState();
- }
- [DllImport(ApiConstants.FxrAlgorithm)]
- private static extern int FXRFeature_CreateFaceDetector(out IntPtr handle);
- [DllImport(ApiConstants.FxrAlgorithm)]
- private static extern void FXRFeature_InitFaceDetector();
- [DllImport(ApiConstants.FxrAlgorithm)]
- private static extern void FXRFeature_DestroyFaceDetector();
- [DllImport(ApiConstants.FxrAlgorithm)]
- private static extern void FXRFeature_GetFacePosition(float[] position, int size);
- [DllImport(ApiConstants.FxrAlgorithm)]
- private static extern void FXRFeature_GetFaceInCamera(float[] position, int size);
- [DllImport(ApiConstants.FxrAlgorithm)]
- private static extern void FXRFeature_GetFaceLookAt(float[] lookAt, int size);
- [DllImport(ApiConstants.FxrAlgorithm)]
- private static extern void FXRFeature_SetFrameRate(int fps);
- [DllImport(ApiConstants.FxrAlgorithm)]
- private static extern bool FXRFeature_CheckFaceState();
- }
- }
|