OVRDisplay.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using UnityEngine;
  4. using UnityEngine.VR;
  5. public class OVRDisplay
  6. {
  7. public OVRDisplay()
  8. {
  9. this.UpdateTextures();
  10. }
  11. public void Update()
  12. {
  13. this.UpdateTextures();
  14. }
  15. public event Action RecenteredPose;
  16. public void RecenterPose()
  17. {
  18. InputTracking.Recenter();
  19. if (this.RecenteredPose != null)
  20. {
  21. this.RecenteredPose();
  22. }
  23. }
  24. public Vector3 acceleration
  25. {
  26. get
  27. {
  28. if (!OVRManager.isHmdPresent)
  29. {
  30. return Vector3.zero;
  31. }
  32. return OVRPlugin.GetEyeAcceleration(OVRPlugin.Eye.None).ToOVRPose().position;
  33. }
  34. }
  35. public Quaternion angularAcceleration
  36. {
  37. get
  38. {
  39. if (!OVRManager.isHmdPresent)
  40. {
  41. return Quaternion.identity;
  42. }
  43. return OVRPlugin.GetEyeAcceleration(OVRPlugin.Eye.None).ToOVRPose().orientation;
  44. }
  45. }
  46. public Vector3 velocity
  47. {
  48. get
  49. {
  50. if (!OVRManager.isHmdPresent)
  51. {
  52. return Vector3.zero;
  53. }
  54. return OVRPlugin.GetEyeVelocity(OVRPlugin.Eye.None).ToOVRPose().position;
  55. }
  56. }
  57. public Quaternion angularVelocity
  58. {
  59. get
  60. {
  61. if (!OVRManager.isHmdPresent)
  62. {
  63. return Quaternion.identity;
  64. }
  65. return OVRPlugin.GetEyeVelocity(OVRPlugin.Eye.None).ToOVRPose().orientation;
  66. }
  67. }
  68. public OVRDisplay.EyeRenderDesc GetEyeRenderDesc(VRNode eye)
  69. {
  70. return this.eyeDescs[(int)eye];
  71. }
  72. public OVRDisplay.LatencyData latency
  73. {
  74. get
  75. {
  76. if (!OVRManager.isHmdPresent)
  77. {
  78. return default(OVRDisplay.LatencyData);
  79. }
  80. string latency = OVRPlugin.latency;
  81. Regex regex = new Regex("Render: ([0-9]+[.][0-9]+)ms, TimeWarp: ([0-9]+[.][0-9]+)ms, PostPresent: ([0-9]+[.][0-9]+)ms", RegexOptions.None);
  82. OVRDisplay.LatencyData result = default(OVRDisplay.LatencyData);
  83. Match match = regex.Match(latency);
  84. if (match.Success)
  85. {
  86. result.render = float.Parse(match.Groups[1].Value);
  87. result.timeWarp = float.Parse(match.Groups[2].Value);
  88. result.postPresent = float.Parse(match.Groups[3].Value);
  89. }
  90. return result;
  91. }
  92. }
  93. public int recommendedMSAALevel
  94. {
  95. get
  96. {
  97. int num = OVRPlugin.recommendedMSAALevel;
  98. if (num == 1)
  99. {
  100. num = 0;
  101. }
  102. return num;
  103. }
  104. }
  105. private void UpdateTextures()
  106. {
  107. this.ConfigureEyeDesc(VRNode.LeftEye);
  108. this.ConfigureEyeDesc(VRNode.RightEye);
  109. }
  110. private void ConfigureEyeDesc(VRNode eye)
  111. {
  112. if (!OVRManager.isHmdPresent)
  113. {
  114. return;
  115. }
  116. OVRPlugin.Sizei eyeTextureSize = OVRPlugin.GetEyeTextureSize((OVRPlugin.Eye)eye);
  117. OVRPlugin.Frustumf eyeFrustum = OVRPlugin.GetEyeFrustum((OVRPlugin.Eye)eye);
  118. this.eyeDescs[(int)eye] = new OVRDisplay.EyeRenderDesc
  119. {
  120. resolution = new Vector2((float)eyeTextureSize.w, (float)eyeTextureSize.h),
  121. fov = 57.29578f * new Vector2(eyeFrustum.fovX, eyeFrustum.fovY)
  122. };
  123. }
  124. private bool needsConfigureTexture;
  125. private OVRDisplay.EyeRenderDesc[] eyeDescs = new OVRDisplay.EyeRenderDesc[2];
  126. public struct EyeRenderDesc
  127. {
  128. public Vector2 resolution;
  129. public Vector2 fov;
  130. }
  131. public struct LatencyData
  132. {
  133. public float render;
  134. public float timeWarp;
  135. public float postPresent;
  136. public float renderError;
  137. public float timeWarpError;
  138. }
  139. }