OVRDisplay.cs 3.1 KB

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