NativeController.cs 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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. using UnityEngine;
  14. /// <summary> A controller for handling natives. </summary>
  15. internal partial class NativeController
  16. {
  17. /// <summary> Handle of the controller. </summary>
  18. private UInt64 m_ControllerHandle = 0;
  19. /// <summary> The state handles. </summary>
  20. private UInt64[] m_StateHandles = new UInt64[NRInput.MAX_CONTROLLER_STATE_COUNT] { 0, 0 };
  21. /// <summary> Initializes this object. </summary>
  22. /// <returns> True if it succeeds, false if it fails. </returns>
  23. public bool Init()
  24. {
  25. NRDebugger.Debug("[NativeController] Init");
  26. NativeResult result = NativeApi.NRControllerCreate(ref m_ControllerHandle);
  27. if (result == NativeResult.Success)
  28. {
  29. //manually start controller
  30. NativeApi.NRControllerStart(m_ControllerHandle);
  31. int count = GetControllerCount();
  32. NRDebugger.Debug("[NativeController] Get controller count:" + count);
  33. for (int i = 0; i < count; i++)
  34. {
  35. result = NativeApi.NRControllerStateCreate(m_ControllerHandle, i, ref m_StateHandles[i]);
  36. if (result != NativeResult.Success)
  37. {
  38. NRDebugger.Error("[NativeController] Create Failed!" + result.ToString());
  39. return false;
  40. }
  41. }
  42. NRDebugger.Debug("[NativeController] Created Successed");
  43. return true;
  44. }
  45. NRDebugger.Error("[NativeController] Create Failed!");
  46. m_ControllerHandle = 0;
  47. return false;
  48. }
  49. //public void TestApi(int index)
  50. //{
  51. //string msg = "GetControllerCount:" + GetControllerCount() + "\n"
  52. //+"GetAvailableFeatures:" + GetAvailableFeatures(index) + "\n"
  53. //+ "GetControllerType:" + GetControllerType(index) + "\n"
  54. //+ "GetConnectionState:" + GetConnectionState(index) + "\n"
  55. //+ "GetBatteryLevel:" + GetBatteryLevel(index) + "\n"
  56. //+ "IsCharging:" + IsCharging(index) + "\n"
  57. //+ "GetPose:" + GetPose(index).ToString("F3") + "\n"
  58. //+ "GetGyro:" + GetGyro(index).ToString("F3") + "\n"
  59. //+ "GetAccel:" + GetAccel(index).ToString("F3") + "\n"
  60. //+ "GetMag:" + GetMag(index).ToString("F3") + "\n"
  61. //+ "GetButtonState:" + GetButtonState(index) + "\n"
  62. //+ "GetButtonUp:" + GetButtonUp(index) + "\n"
  63. //+ "GetButtonDown:" + GetButtonDown(index) + "\n"
  64. //+ "IsTouching:" + IsTouching(index) + "\n"
  65. //+ "GetTouchUp:" + GetTouchUp(index) + "\n"
  66. //+ "GetTouchDown:" + GetTouchDown(index) + "\n"
  67. //+ "GetTouch:" + GetTouch(index).ToString("F3") + "\n";
  68. //NRDebugger.Info(msg);
  69. //}
  70. /// <summary> Gets controller count. </summary>
  71. /// <returns> The controller count. </returns>
  72. public int GetControllerCount()
  73. {
  74. if (m_ControllerHandle == 0)
  75. {
  76. return 0;
  77. }
  78. int count = 0;
  79. if (NativeApi.NRControllerGetCount(m_ControllerHandle, ref count) != NativeResult.Success)
  80. NRDebugger.Error("Get Controller Count Failed!");
  81. return Mathf.Min(count, m_StateHandles.Length);
  82. }
  83. /// <summary> Pauses this object. </summary>
  84. public void Pause()
  85. {
  86. if (m_ControllerHandle == 0)
  87. {
  88. return;
  89. }
  90. NativeApi.NRControllerPause(m_ControllerHandle);
  91. }
  92. /// <summary> Resumes this object. </summary>
  93. public void Resume()
  94. {
  95. if (m_ControllerHandle == 0)
  96. {
  97. return;
  98. }
  99. NativeApi.NRControllerResume(m_ControllerHandle);
  100. }
  101. /// <summary> Stops this object. </summary>
  102. public void Stop()
  103. {
  104. if (m_ControllerHandle == 0)
  105. {
  106. return;
  107. }
  108. NativeApi.NRControllerStop(m_ControllerHandle);
  109. }
  110. /// <summary> Destroys this object. </summary>
  111. public void Destroy()
  112. {
  113. if (m_ControllerHandle == 0)
  114. {
  115. return;
  116. }
  117. Stop();
  118. NativeApi.NRControllerDestroy(m_ControllerHandle);
  119. }
  120. /// <summary> Gets available features. </summary>
  121. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  122. /// <returns> The available features. </returns>
  123. public uint GetAvailableFeatures(int controllerIndex)
  124. {
  125. if (m_ControllerHandle == 0)
  126. {
  127. return 0;
  128. }
  129. uint availableFeature = 0;
  130. NativeApi.NRControllerGetAvailableFeatures(m_ControllerHandle, controllerIndex, ref availableFeature);
  131. return availableFeature;
  132. }
  133. /// <summary> Gets controller type. </summary>
  134. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  135. /// <returns> The controller type. </returns>
  136. public ControllerType GetControllerType(int controllerIndex)
  137. {
  138. if (m_ControllerHandle == 0)
  139. {
  140. return ControllerType.CONTROLLER_TYPE_UNKNOWN;
  141. }
  142. ControllerType controllerType = ControllerType.CONTROLLER_TYPE_UNKNOWN;
  143. NativeApi.NRControllerGetType(m_ControllerHandle, controllerIndex, ref controllerType);
  144. return controllerType;
  145. }
  146. /// <summary> Recenter controller. </summary>
  147. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  148. public void RecenterController(int controllerIndex)
  149. {
  150. if (m_ControllerHandle == 0)
  151. {
  152. return;
  153. }
  154. NativeApi.NRControllerRecenter(m_ControllerHandle, controllerIndex);
  155. }
  156. /// <summary> Trigger haptic vibrate. </summary>
  157. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  158. /// <param name="duration"> The duration.</param>
  159. /// <param name="frequency"> The frequency.</param>
  160. /// <param name="amplitude"> The amplitude.</param>
  161. public void TriggerHapticVibrate(int controllerIndex, Int64 duration, float frequency, float amplitude)
  162. {
  163. if (m_ControllerHandle == 0)
  164. {
  165. return;
  166. }
  167. NativeApi.NRControllerHapticVibrate(m_ControllerHandle, controllerIndex, duration, frequency, amplitude);
  168. }
  169. /// <summary> Updates the state described by controllerIndex. </summary>
  170. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  171. /// <returns> True if it succeeds, false if it fails. </returns>
  172. public bool UpdateState(int controllerIndex)
  173. {
  174. if (m_ControllerHandle == 0)
  175. {
  176. return false;
  177. }
  178. if (m_StateHandles[controllerIndex] == 0)
  179. NativeApi.NRControllerStateCreate(m_ControllerHandle, controllerIndex, ref m_StateHandles[controllerIndex]);
  180. if (m_StateHandles[controllerIndex] == 0)
  181. return false;
  182. NativeResult result = NativeApi.NRControllerStateUpdate(m_StateHandles[controllerIndex]);
  183. return result == NativeResult.Success;
  184. }
  185. /// <summary> Destroys the state described by controllerIndex. </summary>
  186. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  187. public void DestroyState(int controllerIndex)
  188. {
  189. NativeApi.NRControllerStateDestroy(m_StateHandles[controllerIndex]);
  190. }
  191. /// <summary> Gets connection state. </summary>
  192. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  193. /// <returns> The connection state. </returns>
  194. public ControllerConnectionState GetConnectionState(int controllerIndex)
  195. {
  196. ControllerConnectionState state = ControllerConnectionState.CONTROLLER_CONNECTION_STATE_NOT_INITIALIZED;
  197. NativeApi.NRControllerStateGetConnectionState(m_StateHandles[controllerIndex], ref state);
  198. return state;
  199. }
  200. /// <summary> Gets battery level. </summary>
  201. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  202. /// <returns> The battery level. </returns>
  203. public int GetBatteryLevel(int controllerIndex)
  204. {
  205. int batteryLevel = -1;
  206. NativeApi.NRControllerStateGetBatteryLevel(m_StateHandles[controllerIndex], ref batteryLevel);
  207. return batteryLevel;
  208. }
  209. /// <summary> Query if 'controllerIndex' is charging. </summary>
  210. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  211. /// <returns> True if charging, false if not. </returns>
  212. public bool IsCharging(int controllerIndex)
  213. {
  214. int isCharging = 0;
  215. NativeApi.NRControllerStateGetCharging(m_StateHandles[controllerIndex], ref isCharging);
  216. return isCharging == 1;
  217. }
  218. /// <summary> Gets a pose. </summary>
  219. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  220. /// <returns> The pose. </returns>
  221. public Pose GetPose(int controllerIndex)
  222. {
  223. Pose controllerPos = Pose.identity;
  224. NativeMat4f mat4f = new NativeMat4f(Matrix4x4.identity);
  225. NativeResult result = NativeApi.NRControllerStateGetPose(m_StateHandles[controllerIndex], ref mat4f);
  226. if (result == NativeResult.Success)
  227. ConversionUtility.ApiPoseToUnityPose(mat4f, out controllerPos);
  228. return controllerPos;
  229. }
  230. /// <summary> Gets a gyro. </summary>
  231. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  232. /// <returns> The gyro. </returns>
  233. public Vector3 GetGyro(int controllerIndex)
  234. {
  235. NativeVector3f vec3f = new NativeVector3f();
  236. NativeResult result = NativeApi.NRControllerStateGetGyro(m_StateHandles[controllerIndex], ref vec3f);
  237. if (result == NativeResult.Success)
  238. return vec3f.ToUnityVector3();
  239. return Vector3.zero;
  240. }
  241. /// <summary> Gets an accel. </summary>
  242. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  243. /// <returns> The accel. </returns>
  244. public Vector3 GetAccel(int controllerIndex)
  245. {
  246. NativeVector3f vec3f = new NativeVector3f();
  247. NativeResult result = NativeApi.NRControllerStateGetAccel(m_StateHandles[controllerIndex], ref vec3f);
  248. if (result == NativeResult.Success)
  249. return vec3f.ToUnityVector3();
  250. return Vector3.zero;
  251. }
  252. /// <summary> Gets a magnitude. </summary>
  253. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  254. /// <returns> The magnitude. </returns>
  255. public Vector3 GetMag(int controllerIndex)
  256. {
  257. NativeVector3f vec3f = new NativeVector3f();
  258. NativeResult result = NativeApi.NRControllerStateGetMag(m_StateHandles[controllerIndex], ref vec3f);
  259. if (result == NativeResult.Success)
  260. return vec3f.ToUnityVector3();
  261. return Vector3.zero;
  262. }
  263. /// <summary> Gets button state. </summary>
  264. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  265. /// <returns> The button state. </returns>
  266. public uint GetButtonState(int controllerIndex)
  267. {
  268. uint buttonPress = 0;
  269. NativeApi.NRControllerStateGetButtonState(m_StateHandles[controllerIndex], ref buttonPress);
  270. return buttonPress;
  271. }
  272. /// <summary> Gets button up. </summary>
  273. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  274. /// <returns> The button up. </returns>
  275. public uint GetButtonUp(int controllerIndex)
  276. {
  277. uint buttonUp = 0;
  278. NativeApi.NRControllerStateGetButtonUp(m_StateHandles[controllerIndex], ref buttonUp);
  279. return buttonUp;
  280. }
  281. /// <summary> Gets button down. </summary>
  282. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  283. /// <returns> The button down. </returns>
  284. public uint GetButtonDown(int controllerIndex)
  285. {
  286. uint buttonDown = 0;
  287. NativeApi.NRControllerStateGetButtonDown(m_StateHandles[controllerIndex], ref buttonDown);
  288. return buttonDown;
  289. }
  290. /// <summary> Query if 'controllerIndex' is touching. </summary>
  291. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  292. /// <returns> True if touching, false if not. </returns>
  293. public bool IsTouching(int controllerIndex)
  294. {
  295. uint touchState = 0;
  296. NativeApi.NRControllerStateTouchState(m_StateHandles[controllerIndex], ref touchState);
  297. return touchState == 1;
  298. }
  299. /// <summary> Gets touch up. </summary>
  300. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  301. /// <returns> True if it succeeds, false if it fails. </returns>
  302. public bool GetTouchUp(int controllerIndex)
  303. {
  304. uint touchUp = 0;
  305. NativeApi.NRControllerStateGetTouchUp(m_StateHandles[controllerIndex], ref touchUp);
  306. return touchUp == 1;
  307. }
  308. /// <summary> Gets touch down. </summary>
  309. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  310. /// <returns> True if it succeeds, false if it fails. </returns>
  311. public bool GetTouchDown(int controllerIndex)
  312. {
  313. uint touchDown = 0;
  314. NativeApi.NRControllerStateGetTouchDown(m_StateHandles[controllerIndex], ref touchDown);
  315. return touchDown == 1;
  316. }
  317. /// <summary> Gets a touch. </summary>
  318. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  319. /// <returns> The touch. </returns>
  320. public Vector2 GetTouch(int controllerIndex)
  321. {
  322. NativeVector2f touchPos = new NativeVector2f();
  323. NativeResult result = NativeApi.NRControllerStateGetTouchPose(m_StateHandles[controllerIndex], ref touchPos);
  324. if (result == NativeResult.Success)
  325. return touchPos.ToUnityVector2();
  326. return Vector3.zero;
  327. }
  328. /// <summary> Updates the head pose described by hmdPose. </summary>
  329. /// <param name="hmdPose"> The hmd pose.</param>
  330. public void UpdateHeadPose(Pose hmdPose)
  331. {
  332. NativeMat4f apiPose;
  333. ConversionUtility.UnityPoseToApiPose(hmdPose, out apiPose);
  334. NativeApi.NRControllerSetHeadPose(m_ControllerHandle, ref apiPose);
  335. }
  336. /// <summary> Gets a version. </summary>
  337. /// <param name="controllerIndex"> Zero-based index of the controller.</param>
  338. /// <returns> The version. </returns>
  339. public string GetVersion(int controllerIndex)
  340. {
  341. if (m_ControllerHandle == 0)
  342. {
  343. return "";
  344. }
  345. byte[] bytes = new byte[128];
  346. var result = NativeApi.NRControllerGetVersion(m_ControllerHandle, controllerIndex, bytes, bytes.Length);
  347. if (result == NativeResult.Success)
  348. {
  349. return System.Text.Encoding.ASCII.GetString(bytes, 0, bytes.Length);
  350. }
  351. else
  352. {
  353. return "";
  354. }
  355. }
  356. public HandednessType GetHandednessType()
  357. {
  358. HandednessType handedness_type = HandednessType.RIGHT_HANDEDNESS;
  359. var result = NativeApi.NRControllerGetHandednessType(m_ControllerHandle, ref handedness_type);
  360. NativeErrorListener.Check(result, this, "GetHandednessType");
  361. return handedness_type;
  362. }
  363. private partial struct NativeApi
  364. {
  365. /// <summary> Nr controller create. </summary>
  366. /// <param name="out_controller_handle"> [in,out] Handle of the out controller.</param>
  367. /// <returns> A NativeResult. </returns>
  368. [DllImport(NativeConstants.NRNativeLibrary)]
  369. public static extern NativeResult NRControllerCreate(ref UInt64 out_controller_handle);
  370. /// <summary> Nr controller start. </summary>
  371. /// <param name="controller_handle"> Handle of the controller.</param>
  372. /// <returns> A NativeResult. </returns>
  373. [DllImport(NativeConstants.NRNativeLibrary)]
  374. public static extern NativeResult NRControllerStart(UInt64 controller_handle);
  375. /// <summary> Nr controller pause. </summary>
  376. /// <param name="controller_handle"> Handle of the controller.</param>
  377. /// <returns> A NativeResult. </returns>
  378. [DllImport(NativeConstants.NRNativeLibrary)]
  379. public static extern NativeResult NRControllerPause(UInt64 controller_handle);
  380. /// <summary> Nr controller resume. </summary>
  381. /// <param name="controller_handle"> Handle of the controller.</param>
  382. /// <returns> A NativeResult. </returns>
  383. [DllImport(NativeConstants.NRNativeLibrary)]
  384. public static extern NativeResult NRControllerResume(UInt64 controller_handle);
  385. /// <summary> Nr controller stop. </summary>
  386. /// <param name="controller_handle"> Handle of the controller.</param>
  387. /// <returns> A NativeResult. </returns>
  388. [DllImport(NativeConstants.NRNativeLibrary)]
  389. public static extern NativeResult NRControllerStop(UInt64 controller_handle);
  390. /// <summary> Nr controller destroy. </summary>
  391. /// <param name="controller_handle"> Handle of the controller.</param>
  392. /// <returns> A NativeResult. </returns>
  393. [DllImport(NativeConstants.NRNativeLibrary)]
  394. public static extern NativeResult NRControllerDestroy(UInt64 controller_handle);
  395. /// <summary> Nr controller get count. </summary>
  396. /// <param name="controller_handle"> Handle of the controller.</param>
  397. /// <param name="out_controller_count"> [in,out] Number of out controllers.</param>
  398. /// <returns> A NativeResult. </returns>
  399. [DllImport(NativeConstants.NRNativeLibrary)]
  400. public static extern NativeResult NRControllerGetCount(UInt64 controller_handle, ref int out_controller_count);
  401. /// <summary> Nr controller get available features. </summary>
  402. /// <param name="controller_handle"> Handle of the controller.</param>
  403. /// <param name="controller_index"> Zero-based index of the controller.</param>
  404. /// <param name="out_controller_available_features"> [in,out] The out controller available
  405. /// features.</param>
  406. /// <returns> A NativeResult. </returns>
  407. [DllImport(NativeConstants.NRNativeLibrary)]
  408. public static extern NativeResult NRControllerGetAvailableFeatures(UInt64 controller_handle, int controller_index, ref uint out_controller_available_features);
  409. /// <summary> Nr controller get type. </summary>
  410. /// <param name="controller_handle"> Handle of the controller.</param>
  411. /// <param name="controller_index"> Zero-based index of the controller.</param>
  412. /// <param name="out_controller_type"> [in,out] Type of the out controller.</param>
  413. /// <returns> A NativeResult. </returns>
  414. [DllImport(NativeConstants.NRNativeLibrary)]
  415. public static extern NativeResult NRControllerGetType(UInt64 controller_handle, int controller_index, ref ControllerType out_controller_type);
  416. /// <summary> Nr controller recenter. </summary>
  417. /// <param name="controller_handle"> Handle of the controller.</param>
  418. /// <param name="controller_index"> Zero-based index of the controller.</param>
  419. /// <returns> A NativeResult. </returns>
  420. [DllImport(NativeConstants.NRNativeLibrary)]
  421. public static extern NativeResult NRControllerRecenter(UInt64 controller_handle, int controller_index);
  422. /// <summary> Nr controller state create. </summary>
  423. /// <param name="controller_handle"> Handle of the controller.</param>
  424. /// <param name="controller_index"> Zero-based index of the controller.</param>
  425. /// <param name="out_controller_state_handle"> [in,out] Handle of the out controller state.</param>
  426. /// <returns> A NativeResult. </returns>
  427. [DllImport(NativeConstants.NRNativeLibrary)]
  428. public static extern NativeResult NRControllerStateCreate(UInt64 controller_handle, int controller_index, ref UInt64 out_controller_state_handle);
  429. /// <summary> Nr controller state update. </summary>
  430. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  431. /// <returns> A NativeResult. </returns>
  432. [DllImport(NativeConstants.NRNativeLibrary)]
  433. public static extern NativeResult NRControllerStateUpdate(UInt64 controller_state_handle);
  434. /// <summary> Nr controller state destroy. </summary>
  435. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  436. /// <returns> A NativeResult. </returns>
  437. [DllImport(NativeConstants.NRNativeLibrary)]
  438. public static extern NativeResult NRControllerStateDestroy(UInt64 controller_state_handle);
  439. /// <summary> duration(nanoseconds), frequency(Hz), amplitude(0.0f ~ 1.0f) </summary>
  440. /// <param name="controller_handle"> Handle of the controller.</param>
  441. /// <param name="controller_index"> Zero-based index of the controller.</param>
  442. /// <param name="duration"> The duration.</param>
  443. /// <param name="frequency"> The frequency.</param>
  444. /// <param name="amplitude"> The amplitude.</param>
  445. /// <returns> A NativeResult. </returns>
  446. [DllImport(NativeConstants.NRNativeLibrary)]
  447. public static extern NativeResult NRControllerHapticVibrate(UInt64 controller_handle, int controller_index, Int64 duration, float frequency, float amplitude);
  448. /// <summary> Nr controller state get connection state. </summary>
  449. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  450. /// <param name="out_controller_connection_state"> [in,out] State of the out controller
  451. /// connection.</param>
  452. /// <returns> A NativeResult. </returns>
  453. [DllImport(NativeConstants.NRNativeLibrary)]
  454. public static extern NativeResult NRControllerStateGetConnectionState(UInt64 controller_state_handle, ref ControllerConnectionState out_controller_connection_state);
  455. /// <summary> Nr controller state get battery level. </summary>
  456. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  457. /// <param name="out_controller_battery_level"> [in,out] The out controller battery level.</param>
  458. /// <returns> A NativeResult. </returns>
  459. [DllImport(NativeConstants.NRNativeLibrary)]
  460. public static extern NativeResult NRControllerStateGetBatteryLevel(UInt64 controller_state_handle, ref int out_controller_battery_level);
  461. /// <summary> Nr controller state get charging. </summary>
  462. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  463. /// <param name="out_controller_charging"> [in,out] The out controller charging.</param>
  464. /// <returns> A NativeResult. </returns>
  465. [DllImport(NativeConstants.NRNativeLibrary)]
  466. public static extern NativeResult NRControllerStateGetCharging(UInt64 controller_state_handle, ref int out_controller_charging);
  467. /// <summary> Nr controller state get pose. </summary>
  468. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  469. /// <param name="out_controller_pose"> [in,out] The out controller pose.</param>
  470. /// <returns> A NativeResult. </returns>
  471. [DllImport(NativeConstants.NRNativeLibrary)]
  472. public static extern NativeResult NRControllerStateGetPose(UInt64 controller_state_handle, ref NativeMat4f out_controller_pose);
  473. /// <summary> Nr controller state get gyro. </summary>
  474. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  475. /// <param name="out_controller_gyro"> [in,out] The out controller gyro.</param>
  476. /// <returns> A NativeResult. </returns>
  477. [DllImport(NativeConstants.NRNativeLibrary)]
  478. public static extern NativeResult NRControllerStateGetGyro(UInt64 controller_state_handle, ref NativeVector3f out_controller_gyro);
  479. /// <summary> Nr controller state get accel. </summary>
  480. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  481. /// <param name="out_controller_accel"> [in,out] The out controller accel.</param>
  482. /// <returns> A NativeResult. </returns>
  483. [DllImport(NativeConstants.NRNativeLibrary)]
  484. public static extern NativeResult NRControllerStateGetAccel(UInt64 controller_state_handle, ref NativeVector3f out_controller_accel);
  485. /// <summary> Nr controller state get magnitude. </summary>
  486. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  487. /// <param name="out_controller_mag"> [in,out] The out controller magnitude.</param>
  488. /// <returns> A NativeResult. </returns>
  489. [DllImport(NativeConstants.NRNativeLibrary)]
  490. public static extern NativeResult NRControllerStateGetMag(UInt64 controller_state_handle, ref NativeVector3f out_controller_mag);
  491. /// <summary> Nr controller state get button state. </summary>
  492. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  493. /// <param name="out_controller_button_state"> [in,out] State of the out controller button.</param>
  494. /// <returns> A NativeResult. </returns>
  495. [DllImport(NativeConstants.NRNativeLibrary)]
  496. public static extern NativeResult NRControllerStateGetButtonState(UInt64 controller_state_handle, ref uint out_controller_button_state);
  497. /// <summary> Nr controller state get button up. </summary>
  498. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  499. /// <param name="out_controller_button_up"> [in,out] The out controller button up.</param>
  500. /// <returns> A NativeResult. </returns>
  501. [DllImport(NativeConstants.NRNativeLibrary)]
  502. public static extern NativeResult NRControllerStateGetButtonUp(UInt64 controller_state_handle, ref uint out_controller_button_up);
  503. /// <summary> Nr controller state get button down. </summary>
  504. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  505. /// <param name="out_controller_button_down"> [in,out] The out controller button down.</param>
  506. /// <returns> A NativeResult. </returns>
  507. [DllImport(NativeConstants.NRNativeLibrary)]
  508. public static extern NativeResult NRControllerStateGetButtonDown(UInt64 controller_state_handle, ref uint out_controller_button_down);
  509. /// <summary> Nr controller state touch state. </summary>
  510. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  511. /// <param name="out_controller_touch_state"> [in,out] State of the out controller touch.</param>
  512. /// <returns> A NativeResult. </returns>
  513. [DllImport(NativeConstants.NRNativeLibrary)]
  514. public static extern NativeResult NRControllerStateTouchState(UInt64 controller_state_handle, ref uint out_controller_touch_state);
  515. /// <summary> Nr controller state get touch up. </summary>
  516. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  517. /// <param name="out_controller_touch_up"> [in,out] The out controller touch up.</param>
  518. /// <returns> A NativeResult. </returns>
  519. [DllImport(NativeConstants.NRNativeLibrary)]
  520. public static extern NativeResult NRControllerStateGetTouchUp(UInt64 controller_state_handle, ref uint out_controller_touch_up);
  521. /// <summary> Nr controller state get touch down. </summary>
  522. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  523. /// <param name="out_controller_touch_down"> [in,out] The out controller touch down.</param>
  524. /// <returns> A NativeResult. </returns>
  525. [DllImport(NativeConstants.NRNativeLibrary)]
  526. public static extern NativeResult NRControllerStateGetTouchDown(UInt64 controller_state_handle, ref uint out_controller_touch_down);
  527. /// <summary> Nr controller state get touch pose. </summary>
  528. /// <param name="controller_state_handle"> Handle of the controller state.</param>
  529. /// <param name="out_controller_touch_pose"> [in,out] The out controller touch pose.</param>
  530. /// <returns> A NativeResult. </returns>
  531. [DllImport(NativeConstants.NRNativeLibrary)]
  532. public static extern NativeResult NRControllerStateGetTouchPose(UInt64 controller_state_handle, ref NativeVector2f out_controller_touch_pose);
  533. /// <summary> Nr controller set head pose. </summary>
  534. /// <param name="controller_handle"> Handle of the controller.</param>
  535. /// <param name="out_controller_pose"> [in,out] The out controller pose.</param>
  536. /// <returns> A NativeResult. </returns>
  537. [DllImport(NativeConstants.NRNativeLibrary)]
  538. public static extern NativeResult NRControllerSetHeadPose(UInt64 controller_handle, ref NativeMat4f out_controller_pose);
  539. /// <summary> Nr controller get version. </summary>
  540. /// <param name="controller_handle"> Handle of the controller.</param>
  541. /// <param name="controller_index"> Zero-based index of the controller.</param>
  542. /// <param name="out_version"> The out version.</param>
  543. /// <param name="len"> The length.</param>
  544. /// <returns> A NativeResult. </returns>
  545. [DllImport(NativeConstants.NRNativeLibrary)]
  546. public static extern NativeResult NRControllerGetVersion(UInt64 controller_handle, int controller_index, byte[] out_version, int len);
  547. /// <summary> Get the handedness left or right. </summary>
  548. /// <param name="controller_handle"> The handle of controller state object. </param>
  549. /// <param name="handedness_type"> The handedness type returned. </param>
  550. /// <returns>The result of operation.</returns>
  551. [DllImport(NativeConstants.NRNativeLibrary)]
  552. public static extern NativeResult NRControllerGetHandednessType(UInt64 controller_handle, ref HandednessType handedness_type);
  553. };
  554. }
  555. }