123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- using UnityEngine;
- using System;
- using System.Collections;
- using System.Runtime.InteropServices;
- using SC.XR.Unity;
- class GSXRPluginOther : GSXRPlugin
- {
- public static GSXRPluginOther Create()
- {
- return new GSXRPluginOther();
- }
- private GSXRPluginOther() { }
- public override bool IsInitialized() { return slamManager != null; }
- public override bool IsRunning() { return eyes != null; }
- public override IEnumerator Initialize()
- {
- yield return base.Initialize();
- deviceInfo = GetDeviceInfo();
- yield break;
- }
- public override IEnumerator BeginVr(int cpuPerfLevel, int gpuPerfLevel)
- {
- yield return base.BeginVr(cpuPerfLevel, gpuPerfLevel);
- yield break;
- }
-
- public override void SetVSyncCount(int vSyncCount)
- {
- QualitySettings.vSyncCount = vSyncCount;
- }
- Vector2 mouseNDCRotate = Vector2.zero;
- Vector2 mouseNDCPosition = Vector2.zero;
- Vector2 mousePressPointTemp1 = Vector2.zero;
- Vector3 mousePressEuler = Vector3.zero;
- public Vector3 GetPosition {
- get {
- if (Input.touchCount >= 1) {
- return Camera.main.ScreenToWorldPoint(Input.touches[0].position);
- } else if (Input.mousePresent) {
- ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- Debug.DrawRay(ray.origin, ray.direction, Color.white);
- return Camera.main.ScreenToWorldPoint(Input.mousePosition);
- }
- return Vector3.zero;
- }
- }
- Ray ray;
- public Quaternion GetRotation {
- get {
- if (Input.touchCount >= 1) {
- ray = Camera.main.ScreenPointToRay(Input.touches[0].position);
- return Quaternion.LookRotation(ray.direction, Camera.main.transform.up);
- } else if (Input.mousePresent) {
- ray = Camera.main.ScreenPointToRay(Input.mousePosition);
- Debug.DrawRay(ray.origin, ray.direction, Color.yellow);
- return Quaternion.LookRotation(ray.direction, Camera.main.transform.up);
- }
- return Quaternion.identity;
- }
- }
- public override int GetHeadPose(ref HeadPose headPose, int frameIndex)
- {
- int poseStatus = 0;
- headPose.orientation = GetRotation;
- headPose.position = GetPosition;
-
- poseStatus |= (int)TrackingMode.kTrackingOrientation;
- poseStatus |= (int)TrackingMode.kTrackingPosition;
- //Debug.Log("Input.mousePosition:"+ Input.mousePosition+" "+ Screen.width+" "+Screen.height);
- //if (Input.GetMouseButton(0)) // 0/Left mouse button
- //{
- // poseStatus |= (int)TrackingMode.kTrackingOrientation;
- // poseStatus |= (int)TrackingMode.kTrackingPosition;
- //}
- //if(Input.GetMouseButtonDown(0) || Input.GetMouseButtonDown(1)) // 1/Right mouse button
- //{
- // mousePressPointTemp1 = Input.mousePosition;
- // mousePressEuler = Camera.main.transform.eulerAngles;
- //} else if(Input.GetMouseButton(0) || Input.GetMouseButton(1)) {
- // mouseNDCRotate.x = 2 * ((Input.mousePosition.x - mousePressPointTemp1.x) / Screen.width) ;
- // mouseNDCRotate.y = 2 * ((Input.mousePosition.y - mousePressPointTemp1.y) / Screen.height) ;
- // poseStatus |= (int)TrackingMode.kTrackingOrientation;
- //}
- //if(Input.GetKey(KeyCode.W)) {
- // mouseNDCPosition.y += Time.deltaTime * 0.2f;
- // poseStatus |= (int)TrackingMode.kTrackingPosition;
- //} else if(Input.GetKey(KeyCode.S)) {
- // mouseNDCPosition.y -= Time.deltaTime * 0.2f;
- // poseStatus |= (int)TrackingMode.kTrackingPosition;
- //} else {
- // mouseNDCPosition.y = 0;
- //}
- //if(Input.GetKey(KeyCode.A)) {
- // mouseNDCPosition.x -= Time.deltaTime * 0.2f;
- // poseStatus |= (int)TrackingMode.kTrackingPosition;
- //} else if(Input.GetKey(KeyCode.D)) {
- // mouseNDCPosition.x += Time.deltaTime * 0.2f;
- // poseStatus |= (int)TrackingMode.kTrackingPosition;
- //} else {
- // mouseNDCPosition.x = 0;
- //}
- ////if(Input.mouseScrollDelta.y != 0) {
- //// mouseNDCPosition.x = 0;
- //// mouseNDCPosition.y = Input.mouseScrollDelta.y * 0.2f;
- //// poseStatus |= (int)TrackingMode.kTrackingPosition;
- ////} else {
- //// mouseNDCPosition = Vector2.zero;
- ////}
- /////复位
- //if(Input.GetKey(KeyCode.Escape) == true) {
- // mouseNDCRotate = Vector2.zero;
- // mouseNDCPosition = Vector2.zero;
- // mousePressPointTemp1 = Vector2.zero;
- // mousePressEuler = Vector3.zero;
- // Camera.main.transform.position = Vector3.zero;
- // poseStatus |= (int)TrackingMode.kTrackingOrientation;
- // poseStatus |= (int)TrackingMode.kTrackingPosition;
- //}
- //headPose.orientation.eulerAngles = mousePressEuler + new Vector3(-mouseNDCRotate.y * 45f, mouseNDCRotate.x * 90f, 0);
- //headPose.position = new Vector3(mouseNDCPosition.x,0, mouseNDCPosition.y);
- //headPose.position = Camera.main.transform.TransformPoint(headPose.position);
- return poseStatus;
- }
- public override DeviceInfo GetDeviceInfo()
- {
- DeviceInfo info = new DeviceInfo();
- info.displayWidthPixels = Screen.width;
- info.displayHeightPixels = Screen.height;
- info.displayRefreshRateHz = 60.0f;
- info.targetEyeWidthPixels = Screen.width / 2;
- info.targetEyeHeightPixels = Screen.height;
- info.targetFovXRad = Mathf.Deg2Rad * 47;
- info.targetFovYRad = Mathf.Deg2Rad * 20.1f;
- info.targetFrustumLeft.left = -0.02208847f;
- info.targetFrustumLeft.right = 0.02208847f;
- info.targetFrustumLeft.top = 0.0123837f;
- info.targetFrustumLeft.bottom = -0.0123837f;
- info.targetFrustumLeft.near = 0.0508f;
- info.targetFrustumLeft.far = 100f;
- info.targetFrustumRight.left = -0.02208847f;
- info.targetFrustumRight.right = 0.02208847f;
- info.targetFrustumRight.top = 0.0123837f;
- info.targetFrustumRight.bottom = -0.0123837f;
- info.targetFrustumRight.near = 0.0508f;
- info.targetFrustumRight.far = 100f;
- return info;
- }
- public override void SubmitFrame(int frameIndex, float fieldOfView, int frameType)
- {
- }
- public override void Shutdown()
- {
- base.Shutdown();
- }
- #region Controller
- public override bool GSXR_Is_SupportController() { return false; }
- #endregion Controller
- #region HandTracking
- public override bool GSXR_Is_SupportHandTracking() {
- return false;
- }
- #endregion HandTracking
- #region Deflection
- #endregion Deflection
- #region PointCloud & Map
- #endregion PointCloud & Map
- #region FishEye Data
- #endregion FishEye Data
- #region Optics Calibration
- #endregion Optics Calibration
- #region EyeTracking
- #endregion EyeTracking
- #region USBDisconnect
- #endregion
- #region luncher
- #endregion
- #region Device
- public override XRType GSXR_Get_XRType() { return XRType.AR; }
- public override string GSXR_Get_DeviceName() { return "Phone AR"; }
- public override string SN => "000";
- public override string RELEASE_VERSION => "0.0.0";
- public override int BatteryLevel => 60;
- #endregion
- }
|