OVRTracker.cs 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using System;
  2. using UnityEngine;
  3. public class OVRTracker
  4. {
  5. public bool isPresent
  6. {
  7. get
  8. {
  9. return OVRManager.isHmdPresent && OVRPlugin.positionSupported;
  10. }
  11. }
  12. public bool isPositionTracked
  13. {
  14. get
  15. {
  16. return OVRPlugin.positionTracked;
  17. }
  18. }
  19. public bool isEnabled
  20. {
  21. get
  22. {
  23. return OVRManager.isHmdPresent && OVRPlugin.position;
  24. }
  25. set
  26. {
  27. if (!OVRManager.isHmdPresent)
  28. {
  29. return;
  30. }
  31. OVRPlugin.position = value;
  32. }
  33. }
  34. public int count
  35. {
  36. get
  37. {
  38. int num = 0;
  39. for (int i = 0; i < 4; i++)
  40. {
  41. if (this.GetPresent(i))
  42. {
  43. num++;
  44. }
  45. }
  46. return num;
  47. }
  48. }
  49. public OVRTracker.Frustum GetFrustum(int tracker = 0)
  50. {
  51. if (!OVRManager.isHmdPresent)
  52. {
  53. return default(OVRTracker.Frustum);
  54. }
  55. return OVRPlugin.GetTrackerFrustum((OVRPlugin.Tracker)tracker).ToFrustum();
  56. }
  57. public OVRPose GetPose(int tracker = 0)
  58. {
  59. if (!OVRManager.isHmdPresent)
  60. {
  61. return OVRPose.identity;
  62. }
  63. OVRPose ovrpose;
  64. switch (tracker)
  65. {
  66. case 0:
  67. ovrpose = OVRPlugin.GetNodePose(OVRPlugin.Node.TrackerZero, false).ToOVRPose();
  68. break;
  69. case 1:
  70. ovrpose = OVRPlugin.GetNodePose(OVRPlugin.Node.TrackerOne, false).ToOVRPose();
  71. break;
  72. case 2:
  73. ovrpose = OVRPlugin.GetNodePose(OVRPlugin.Node.TrackerTwo, false).ToOVRPose();
  74. break;
  75. case 3:
  76. ovrpose = OVRPlugin.GetNodePose(OVRPlugin.Node.TrackerThree, false).ToOVRPose();
  77. break;
  78. default:
  79. return OVRPose.identity;
  80. }
  81. return new OVRPose
  82. {
  83. position = ovrpose.position,
  84. orientation = ovrpose.orientation * Quaternion.Euler(0f, 180f, 0f)
  85. };
  86. }
  87. public bool GetPoseValid(int tracker = 0)
  88. {
  89. if (!OVRManager.isHmdPresent)
  90. {
  91. return false;
  92. }
  93. switch (tracker)
  94. {
  95. case 0:
  96. return OVRPlugin.GetNodePositionTracked(OVRPlugin.Node.TrackerZero);
  97. case 1:
  98. return OVRPlugin.GetNodePositionTracked(OVRPlugin.Node.TrackerOne);
  99. case 2:
  100. return OVRPlugin.GetNodePositionTracked(OVRPlugin.Node.TrackerTwo);
  101. case 3:
  102. return OVRPlugin.GetNodePositionTracked(OVRPlugin.Node.TrackerThree);
  103. default:
  104. return false;
  105. }
  106. }
  107. public bool GetPresent(int tracker = 0)
  108. {
  109. if (!OVRManager.isHmdPresent)
  110. {
  111. return false;
  112. }
  113. switch (tracker)
  114. {
  115. case 0:
  116. return OVRPlugin.GetNodePresent(OVRPlugin.Node.TrackerZero);
  117. case 1:
  118. return OVRPlugin.GetNodePresent(OVRPlugin.Node.TrackerOne);
  119. case 2:
  120. return OVRPlugin.GetNodePresent(OVRPlugin.Node.TrackerTwo);
  121. case 3:
  122. return OVRPlugin.GetNodePresent(OVRPlugin.Node.TrackerThree);
  123. default:
  124. return false;
  125. }
  126. }
  127. public struct Frustum
  128. {
  129. public float nearZ;
  130. public float farZ;
  131. public Vector2 fov;
  132. }
  133. }