PoseDebug.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using Immersal.AR;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using TMPro;
  7. using UnityEngine.Assertions;
  8. public class PoseDebug : MonoBehaviour
  9. {
  10. [SerializeField]
  11. private Toggle _orientationToggle = null;
  12. [SerializeField]
  13. private Toggle _handednessToggle = null;
  14. private TextMeshProUGUI _textMeshProUGUI = null;
  15. private Transform _cameraTransform = null;
  16. private bool isInitialized = false;
  17. void Start()
  18. {
  19. _textMeshProUGUI = GetComponent<TextMeshProUGUI>();
  20. _cameraTransform = Camera.main.transform;
  21. Assert.IsNotNull(_textMeshProUGUI);
  22. Assert.IsNotNull(_cameraTransform);
  23. Assert.IsNotNull(_orientationToggle);
  24. Assert.IsNotNull(_handednessToggle);
  25. isInitialized = true;
  26. }
  27. void Update()
  28. {
  29. if (isInitialized)
  30. {
  31. Quaternion rot = _cameraTransform.rotation;
  32. Vector3 pos = _cameraTransform.position;
  33. if (_orientationToggle.isOn)
  34. {
  35. ARHelper.GetRotation(ref rot);
  36. }
  37. if (_handednessToggle.isOn)
  38. {
  39. Matrix4x4 r = ARHelper.SwitchHandedness(Matrix4x4.Rotate(rot));
  40. rot = r.rotation;
  41. pos = ARHelper.SwitchHandedness(pos);
  42. // Just to debug that the order of the matrix sent to Immersal Cloud Service is the same as in Unity (column-major)
  43. if (Input.GetKeyDown(KeyCode.Space))
  44. {
  45. Debug.Log(string.Format(
  46. "r00:{0}\tr01: {1}\tr02: {2}\nr10: {3}\tr11: {4}\tr12: {5}\nr20: {6}\tr21: {7}\tr22: {8}\n",
  47. r.m00.ToString("F3"), r.m01.ToString("F3"), r.m02.ToString("F3"),
  48. r.m10.ToString("F3"), r.m11.ToString("F3"), r.m12.ToString("F3"),
  49. r.m20.ToString("F3"), r.m21.ToString("F3"), r.m22.ToString("F3")
  50. ));
  51. }
  52. }
  53. Matrix4x4 m = Matrix4x4.TRS(pos, rot, Vector3.one);
  54. string text = m.ToString("+0.00;-0.00;+0.00");
  55. _textMeshProUGUI.text = text;
  56. }
  57. }
  58. }
  59. //
  60. // Camera cam = this.mainCamera;
  61. // ARHelper.GetIntrinsics(out j.intrinsics);
  62. // Quaternion rot = cam.transform.rotation;
  63. // Vector3 pos = cam.transform.position;
  64. // ARHelper.GetRotation(ref rot);
  65. // j.rotation = ARHelper.SwitchHandedness(Matrix4x4.Rotate(rot));
  66. // j.position = ARHelper.SwitchHandedness(pos);