123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- using System;
- using System.Runtime.InteropServices;
- using AOT;
- using Rokid.UXR.Utility;
- //using Google.XR.Cardboard;
- namespace Rokid.UXR.Native
- {
- public partial class NativeInterface
- {
- public partial class NativeAPI
- {
- /// <summary>
- /// Glasses IMU update
- /// Acc Gyt Gnt timeStamp
- /// </summary>
- public static event Action<float[], float[], float[], long> OnGlassIMUSensorUpdate;
- /// <summary>
- /// Glasses IMU rotation callback
- /// Input Value GameRotation Rotation timeStamp
- /// </summary>
- public static event Action<float[], float[], long> OnGlassIMURotationUpdate;
- /// <summary>
- /// Register glasses IMU rotation
- /// </summary>
- public static void RegisterRotationEvent()
- {
- if (!Utils.IsAndroidPlatfrom())
- {
- return;
- }
- setOnRotationUpdate(OnRotationUpdateCallByC);//注册
- }
- /// <summary>
- /// Unregister glasses IMU rotation
- /// </summary>
- public static void UnregisterRotationEvent()
- {
- if (!Utils.IsAndroidPlatfrom())
- {
- return;
- }
- clearOnRotationUpdate();
- }
- /// <summary>
- /// Open phone IMU tracking
- /// </summary>
- public static void OpenPhoneTracker()
- {
- if (Utils.IsAndroidPlatfrom())
- Api.openPhoneTracker();
- }
- /// <summary>
- /// Close phone IMU tracking
- /// </summary>
- public static void ClosePhoneTracker()
- {
- if (Utils.IsAndroidPlatfrom())
- Api.closePhoneTracker();
- }
- /// <summary>
- /// Get phone IMU pose
- /// </summary>
- /// <param name="oritation"></param>
- public static void GetPhonePose(float[] oritation)
- {
- if (Utils.IsAndroidPlatfrom())
- Api.getPhonePose(oritation);
- }
- /// <summary>
- /// Reset the y-axis of the phone's IMU
- /// </summary>
- public static void RecenterPhonePose()
- {
- if (Utils.IsAndroidPlatfrom())
- Api.recenterPhonePose();
- }
- /// <summary>
- /// Reset the three axes of the phone's IMU
- /// </summary>
- public static void RecenterPhonePoseYPR()
- {
- if (Utils.IsAndroidPlatfrom())
- Api.recenterPhonePoseYPR();
- }
- /// <summary>
- /// Register glasses imu sensor events
- /// </summary>
- public static void RegisterGlassSensorEvent()
- {
- if (!Utils.IsAndroidPlatfrom())
- {
- return;
- }
- setOnSensorUpdate(OnSensorUpdateCallByC);//注册
- }
- /// <summary>
- /// Unregister glasses imu sensor events
- /// </summary>
- public static void UnregisterGlassSensorEvent()
- {
- if (!Utils.IsAndroidPlatfrom())
- {
- return;
- }
- clearOnSensorUpdate();//注销
- }
- #region NativeInterface
- [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
- static extern void setOnSensorUpdate(OnSensorUpdate cb);
- [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
- static extern void clearOnSensorUpdate();
- delegate void OnSensorUpdate(IntPtr ptrAcc, IntPtr ptrGyt, IntPtr ptrGnt, long timestamp);
- static float[] resultAcc = new float[3];
- static float[] resultGyt = new float[3];
- static float[] resultGnt = new float[3];
- [MonoPInvokeCallback(typeof(OnSensorUpdate))]
- static void OnSensorUpdateCallByC(IntPtr ptrAcc, IntPtr ptrGyr, IntPtr ptrGnt, long timestamp)
- {
- RKLog.Debug("OnSensorUpdateCallByC " + timestamp);
- Marshal.Copy(ptrAcc, resultAcc, 0, 3);
- Marshal.Copy(ptrGyr, resultGyt, 0, 3);
- Marshal.Copy(ptrGnt, resultGnt, 0, 3);
- OnGlassIMUSensorUpdate?.Invoke(resultAcc, resultGyt, resultGnt, timestamp);
- }
- [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
- static extern void clearOnRotationUpdate();
- [DllImport(ApiConstants.UXR_GFX_PLUGIN)]
- static extern void setOnRotationUpdate(OnRotationUpdate cb);
- delegate void OnRotationUpdate(IntPtr ptrGameRotation, IntPtr ptrRotation, long timestamp);
- static float[] resultGameRotation = new float[4];
- static float[] resultRotation = new float[5];
- [MonoPInvokeCallback(typeof(OnRotationUpdate))]
- static void OnRotationUpdateCallByC(IntPtr ptrGameRotation, IntPtr ptrRotation, long timestamp)
- {
- RKLog.Debug("OnRotationUpdateCallByC: " + timestamp);
- Marshal.Copy(ptrGameRotation, resultGameRotation, 0, 4);
- Marshal.Copy(ptrRotation, resultRotation, 0, 5);
- OnGlassIMURotationUpdate?.Invoke(resultGameRotation, resultRotation, timestamp);
- }
- }
- #endregion
- }
- }
|