GSXRPluginOther.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Runtime.InteropServices;
  5. using SC.XR.Unity;
  6. class GSXRPluginOther : GSXRPlugin
  7. {
  8. public static GSXRPluginOther Create()
  9. {
  10. return new GSXRPluginOther();
  11. }
  12. private GSXRPluginOther() { }
  13. public override bool IsInitialized() { return slamManager != null; }
  14. public override bool IsRunning() { return eyes != null; }
  15. public override IEnumerator Initialize()
  16. {
  17. yield return base.Initialize();
  18. deviceInfo = GetDeviceInfo();
  19. yield break;
  20. }
  21. public override IEnumerator BeginVr(int cpuPerfLevel, int gpuPerfLevel)
  22. {
  23. yield return base.BeginVr(cpuPerfLevel, gpuPerfLevel);
  24. yield break;
  25. }
  26. public override void SetVSyncCount(int vSyncCount)
  27. {
  28. QualitySettings.vSyncCount = vSyncCount;
  29. }
  30. Vector2 mouseNDCRotate = Vector2.zero;
  31. Vector2 mouseNDCPosition = Vector2.zero;
  32. Vector2 mousePressPointTemp1 = Vector2.zero;
  33. Vector3 mousePressEuler = Vector3.zero;
  34. public Vector3 GetPosition {
  35. get {
  36. if (Input.touchCount >= 1) {
  37. return Camera.main.ScreenToWorldPoint(Input.touches[0].position);
  38. } else if (Input.mousePresent) {
  39. ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  40. Debug.DrawRay(ray.origin, ray.direction, Color.white);
  41. return Camera.main.ScreenToWorldPoint(Input.mousePosition);
  42. }
  43. return Vector3.zero;
  44. }
  45. }
  46. Ray ray;
  47. public Quaternion GetRotation {
  48. get {
  49. if (Input.touchCount >= 1) {
  50. ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
  51. return Quaternion.LookRotation(ray.direction, Camera.main.transform.up);
  52. } else if (Input.mousePresent) {
  53. ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  54. Debug.DrawRay(ray.origin, ray.direction, Color.yellow);
  55. return Quaternion.LookRotation(ray.direction, Camera.main.transform.up);
  56. }
  57. return Quaternion.identity;
  58. }
  59. }
  60. public override int GetHeadPose(ref HeadPose headPose, int frameIndex)
  61. {
  62. int poseStatus = 0;
  63. headPose.orientation = GetRotation;
  64. headPose.position = GetPosition;
  65. poseStatus |= (int)TrackingMode.kTrackingOrientation;
  66. poseStatus |= (int)TrackingMode.kTrackingPosition;
  67. //Debug.Log("Input.mousePosition:"+ Input.mousePosition+" "+ Screen.width+" "+Screen.height);
  68. //if (Input.GetMouseButton(0)) // 0/Left mouse button
  69. //{
  70. // poseStatus |= (int)TrackingMode.kTrackingOrientation;
  71. // poseStatus |= (int)TrackingMode.kTrackingPosition;
  72. //}
  73. //if(Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) // 1/Right mouse button
  74. //{
  75. // mousePressPointTemp1 = Input.mousePosition;
  76. // mousePressEuler = Camera.main.transform.eulerAngles;
  77. //} else if(Input.GetMouseButton(0) || Input.GetMouseButton(1)) {
  78. // mouseNDCRotate.x = 2 * ((Input.mousePosition.x - mousePressPointTemp1.x) / Screen.width) ;
  79. // mouseNDCRotate.y = 2 * ((Input.mousePosition.y - mousePressPointTemp1.y) / Screen.height) ;
  80. // poseStatus |= (int)TrackingMode.kTrackingOrientation;
  81. //}
  82. //if(Input.GetKey(KeyCode.W)) {
  83. // mouseNDCPosition.y += Time.deltaTime * 0.2f;
  84. // poseStatus |= (int)TrackingMode.kTrackingPosition;
  85. //} else if(Input.GetKey(KeyCode.S)) {
  86. // mouseNDCPosition.y -= Time.deltaTime * 0.2f;
  87. // poseStatus |= (int)TrackingMode.kTrackingPosition;
  88. //} else {
  89. // mouseNDCPosition.y = 0;
  90. //}
  91. //if(Input.GetKey(KeyCode.A)) {
  92. // mouseNDCPosition.x -= Time.deltaTime * 0.2f;
  93. // poseStatus |= (int)TrackingMode.kTrackingPosition;
  94. //} else if(Input.GetKey(KeyCode.D)) {
  95. // mouseNDCPosition.x += Time.deltaTime * 0.2f;
  96. // poseStatus |= (int)TrackingMode.kTrackingPosition;
  97. //} else {
  98. // mouseNDCPosition.x = 0;
  99. //}
  100. ////if(Input.mouseScrollDelta.y != 0) {
  101. //// mouseNDCPosition.x = 0;
  102. //// mouseNDCPosition.y = Input.mouseScrollDelta.y * 0.2f;
  103. //// poseStatus |= (int)TrackingMode.kTrackingPosition;
  104. ////} else {
  105. //// mouseNDCPosition = Vector2.zero;
  106. ////}
  107. /////复位
  108. //if(Input.GetKey(KeyCode.Escape) == true) {
  109. // mouseNDCRotate = Vector2.zero;
  110. // mouseNDCPosition = Vector2.zero;
  111. // mousePressPointTemp1 = Vector2.zero;
  112. // mousePressEuler = Vector3.zero;
  113. // Camera.main.transform.position = Vector3.zero;
  114. // poseStatus |= (int)TrackingMode.kTrackingOrientation;
  115. // poseStatus |= (int)TrackingMode.kTrackingPosition;
  116. //}
  117. //headPose.orientation.eulerAngles = mousePressEuler + new Vector3(-mouseNDCRotate.y * 45f, mouseNDCRotate.x * 90f, 0);
  118. //headPose.position = new Vector3(mouseNDCPosition.x,0, mouseNDCPosition.y);
  119. //headPose.position = Camera.main.transform.TransformPoint(headPose.position);
  120. return poseStatus;
  121. }
  122. public override DeviceInfo GetDeviceInfo()
  123. {
  124. DeviceInfo info = new DeviceInfo();
  125. info.displayWidthPixels = Screen.width;
  126. info.displayHeightPixels = Screen.height;
  127. info.displayRefreshRateHz = 60.0f;
  128. info.targetEyeWidthPixels = Screen.width / 2;
  129. info.targetEyeHeightPixels = Screen.height;
  130. info.targetFovXRad = Mathf.Deg2Rad * 47;
  131. info.targetFovYRad = Mathf.Deg2Rad * 20.1f;
  132. info.targetFrustumLeft.left = -0.02208847f;
  133. info.targetFrustumLeft.right = 0.02208847f;
  134. info.targetFrustumLeft.top = 0.0123837f;
  135. info.targetFrustumLeft.bottom = -0.0123837f;
  136. info.targetFrustumLeft.near = 0.0508f;
  137. info.targetFrustumLeft.far = 100f;
  138. info.targetFrustumRight.left = -0.02208847f;
  139. info.targetFrustumRight.right = 0.02208847f;
  140. info.targetFrustumRight.top = 0.0123837f;
  141. info.targetFrustumRight.bottom = -0.0123837f;
  142. info.targetFrustumRight.near = 0.0508f;
  143. info.targetFrustumRight.far = 100f;
  144. return info;
  145. }
  146. public override void SubmitFrame(int frameIndex, float fieldOfView, int frameType)
  147. {
  148. }
  149. public override void Shutdown()
  150. {
  151. base.Shutdown();
  152. }
  153. #region Controller
  154. public override bool GSXR_Is_SupportController() { return false; }
  155. #endregion Controller
  156. #region HandTracking
  157. public override bool GSXR_Is_SupportHandTracking() {
  158. return false;
  159. }
  160. #endregion HandTracking
  161. #region Deflection
  162. #endregion Deflection
  163. #region PointCloud & Map
  164. #endregion PointCloud & Map
  165. #region FishEye Data
  166. #endregion FishEye Data
  167. #region Optics Calibration
  168. #endregion Optics Calibration
  169. #region EyeTracking
  170. #endregion EyeTracking
  171. #region USBDisconnect
  172. #endregion
  173. #region luncher
  174. #endregion
  175. #region Device
  176. public override XRType GSXR_Get_XRType() { return XRType.AR; }
  177. public override string GSXR_Get_DeviceName() { return "Phone AR"; }
  178. public override string SN => "000";
  179. public override string RELEASE_VERSION => "0.0.0";
  180. public override int BatteryLevel => 60;
  181. #endregion
  182. }