123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- using EZXR.Glass.Inputs;
- using EZXR.Glass.SixDof;
- #if SpatialComputing
- using EZXR.Glass.SpatialComputing;
- #endif
- using UnityEngine;
- namespace EZXR.Glass.Core
- {
- [ScriptExecutionOrder(-58)]
- public class XRMan : MonoBehaviour
- {
- #region 单例
- private static XRMan instance;
- public static XRMan Instance
- {
- get
- {
- return instance;
- }
- }
- #endregion
- #region Encapsulation
- //SixDof
- public HMDPoseTracker.DegreeOfFreedom m_dof = HMDPoseTracker.DegreeOfFreedom.SixDof;
- public class TwoEyes
- {
- public Camera left
- {
- get
- {
- return HMDPoseTracker.Instance.leftCamera;
- }
- }
- public Camera right
- {
- get
- {
- return HMDPoseTracker.Instance.rightCamera;
- }
- }
- }
- public TwoEyes Eyes;
- //Hand
- public class TwoHands
- {
- /// <summary>
- /// 记录了左手柄的所有信息
- /// </summary>
- public InputInfoBase left
- {
- get
- {
- return InputSystem.leftHand;
- }
- }
- /// <summary>
- /// 记录了右手柄的所有信息
- /// </summary>
- public InputInfoBase right
- {
- get
- {
- return InputSystem.rightHand;
- }
- }
- }
- public TwoHands Hands;
- #endregion
- /// <summary>
- /// 专门用于放置各种附加组件
- /// </summary>
- public Transform attachments;
- [HideInInspector]
- public Vector3 position_SpatialTracking;
- [HideInInspector]
- public Quaternion rotation_SpatialTracking;
- [HideInInspector]
- public Vector3 position_SpatialComputing;
- [HideInInspector]
- public Quaternion rotation_SpatialComputing;
- [HideInInspector]
- public Matrix4x4 offset_SpatialComputing = Matrix4x4.identity;
- Vector3 tempPosition;
- Quaternion tempRotation;
- Matrix4x4 tempMatrix;
- private void Awake()
- {
- instance = this;
- if (attachments == null)
- {
- attachments = transform.Find("Attachments");
- }
- }
- // Start is called before the first frame update
- void Start()
- {
- InvokeRepeating("DoFramerate", 0, 1);
- }
- void DoFramerate()
- {
- Utilities.Android.SendIntent("ToSystem", "com.ezxr.glass.systemui", "DebugInfo", (1 / Time.smoothDeltaTime).ToString("##.#"));
- }
- // Update is called once per frame
- void Update()
- {
- if (HMDPoseTracker.Instance != null)
- {
- tempPosition = position_SpatialTracking;
- tempRotation = rotation_SpatialTracking;
- }
- #if SpatialComputing
- if (EZXRSpatialComputingManager.Instance != null)
- {
- tempMatrix = offset_SpatialComputing * Matrix4x4.TRS(tempPosition, tempRotation, Vector3.one);
- tempPosition = tempMatrix.GetColumn(3);
- tempRotation = tempMatrix.rotation;
- }
- #endif
- transform.position = tempPosition;
- transform.rotation = tempRotation;
- }
- }
- }
|