VPUTest.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Runtime.InteropServices;
  5. using UnityEngine;
  6. using Ximmerse.XR;
  7. public class VPUTest : MonoBehaviour
  8. {
  9. System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
  10. private void Awake()
  11. {
  12. //Debug.Log("vpu client init");
  13. //XDevicePlugin.xdevc_init();
  14. //XDevicePlugin.ResetTrackingMarkerSettings();
  15. //int[] ids = new int[10];
  16. // XDevicePlugin.LoadTrackingMarkerSettingsFile("/sdcard/BEACON-500.json", out ids, 100);
  17. //NativePluginApi.Unity_setMaxPredictTime(30.0f);
  18. //NativePluginApi.Unity_setHalfExposureTime(11.0f);
  19. }
  20. private void Start()
  21. {
  22. //XDevicePlugin.ConnectController(0, "E7:5B:F4:C8:B5:FA", true);
  23. }
  24. private void Update()
  25. {
  26. // XDevicePlugin.XAttrTrackingInfo info = new XDevicePlugin.XAttrTrackingInfo();
  27. //if (XDevicePlugin.GetTracking(66, 0, ref info)&& info.state!=0) {
  28. // Debug.Log("Tag-66:" + info.ToString());
  29. // }
  30. // if (XDevicePlugin.GetControllerState(0, 0, ref info) && info.state != 0) {
  31. // Debug.Log("Controller-0:" + info.ToString());
  32. // }
  33. TestAPI();
  34. }
  35. float px, py, pz, qx, qy, qz, qw;
  36. Int64 timestamp;
  37. float confidence;
  38. float marker_distance;
  39. int index;
  40. int state;
  41. long predictedTimeNs;
  42. int beacon_id;
  43. long beacon_timestamp;
  44. float beacon_pos0;
  45. float beacon_pos1;
  46. float beacon_pos2;
  47. float beacon_rot0;
  48. float beacon_rot1;
  49. float beacon_rot2;
  50. float beacon_rot3;
  51. float beacon_tracking_confidence;
  52. float beacon_min_distance;
  53. float beacon_correct_weight;
  54. private void TestAPI() {
  55. sw.Reset();
  56. sw.Start();
  57. int ret = NativePluginApi.Unity_TagPredict(0);
  58. if (ret >= 0){
  59. for (int i = 0; i < 100; i++) {
  60. bool ret2 = NativePluginApi.Unity_getTagTracking2(i,
  61. ref index, ref timestamp, ref state,
  62. ref px, ref py, ref pz,
  63. ref qx, ref qy, ref qz, ref qw,
  64. ref confidence, ref marker_distance);
  65. if (ret2 && state > 0) {
  66. Debug.Log("TestAPI:GetTrackingByIDs:" + i+","+ px+","+py+","+pz+","+qx+","+qy+","+qz+","+qw);
  67. }
  68. }
  69. }
  70. sw.Stop();
  71. Debug.Log("c:GetTrackingByIDs cost time:" + sw.ElapsedMilliseconds);
  72. NativePluginApi.Unity_getFusionResult(predictedTimeNs,
  73. ref beacon_id,
  74. ref beacon_timestamp,
  75. ref beacon_pos0,
  76. ref beacon_pos1,
  77. ref beacon_pos2,
  78. ref beacon_rot0,
  79. ref beacon_rot1,
  80. ref beacon_rot2,
  81. ref beacon_rot3,
  82. ref beacon_tracking_confidence,
  83. ref beacon_min_distance,
  84. ref beacon_correct_weight);
  85. Debug.Log("c:getFusionResult:" + beacon_id);
  86. }
  87. }