private static bool GetUnityXRNodeStateQuaternion(Node nodeType, NodeStatePropertyType propertyType, out Quaternion retQuat) { retQuat = Quaternion.identity; NodeState requestedNodeState = default(NodeState); if (!ValidateProperty(nodeType, ref requestedNodeState)) { return(false); } if (propertyType == NodeStatePropertyType.Orientation) { if (requestedNodeState.TryGetRotation(out retQuat)) { return(true); } } return(false); }
static internal NullablePose GetPoseData() { NullablePose resultPose = new NullablePose(); #if UNITY_2020_1_OR_NEWER if (!SixDoFCardboardStartup.isStarted && s_CardboardHMDInputTrackingDevice != null) { s_CardboardHMDInputTrackingDevice = null; } if (s_CardboardHMDInputTrackingDevice != null) { var pose = Pose.identity; var positionSuccess = false; var rotationSuccess = false; if (!(positionSuccess = s_CardboardHMDInputTrackingDevice.Value.TryGetFeatureValue(CommonUsages.centerEyePosition, out pose.position))) { positionSuccess = s_CardboardHMDInputTrackingDevice.Value.TryGetFeatureValue(CommonUsages.colorCameraPosition, out pose.position); } if (!(rotationSuccess = s_CardboardHMDInputTrackingDevice.Value.TryGetFeatureValue(CommonUsages.centerEyeRotation, out pose.rotation))) { rotationSuccess = s_CardboardHMDInputTrackingDevice.Value.TryGetFeatureValue(CommonUsages.colorCameraRotation, out pose.rotation); } if (positionSuccess) { resultPose.position = pose.position; } if (rotationSuccess) { resultPose.rotation = pose.rotation; } Debug.Log("x: " + pose.position.x + " y: " + pose.position.y + " z: " + pose.position.z); if (positionSuccess || rotationSuccess) { return(resultPose); } } else if (s_InputTrackingDevice != null) { var pose = Pose.identity; var positionSuccess = false; var rotationSuccess = false; if (!(positionSuccess = s_InputTrackingDevice.Value.TryGetFeatureValue(CommonUsages.centerEyePosition, out pose.position))) { positionSuccess = s_InputTrackingDevice.Value.TryGetFeatureValue(CommonUsages.colorCameraPosition, out pose.position); } if (!(rotationSuccess = s_InputTrackingDevice.Value.TryGetFeatureValue(CommonUsages.centerEyeRotation, out pose.rotation))) { rotationSuccess = s_InputTrackingDevice.Value.TryGetFeatureValue(CommonUsages.colorCameraRotation, out pose.rotation); } if (positionSuccess) { resultPose.position = pose.position; } if (rotationSuccess) { resultPose.rotation = pose.rotation; } if (positionSuccess || rotationSuccess) { return(resultPose); } } #else UnityEngine.XR.InputTracking.GetNodeStates(nodeStates); List <UnityEngine.XR.XRNodeState> states = new List <UnityEngine.XR.XRNodeState>(); if (!SixDoFCardboardStartup.isStarted) { foreach (UnityEngine.XR.XRNodeState nodeState in nodeStates) { if (nodeState.nodeType == UnityEngine.XR.XRNode.CenterEye) { var pose = Pose.identity; var positionSuccess = nodeState.TryGetPosition(out pose.position); var rotationSuccess = nodeState.TryGetRotation(out pose.rotation); if (positionSuccess) { resultPose.position = pose.position; } if (rotationSuccess) { resultPose.rotation = pose.rotation; } break; } } } else { foreach (UnityEngine.XR.XRNodeState nodeState in nodeStates) { if (nodeState.nodeType == UnityEngine.XR.XRNode.CenterEye) { states.Add(nodeState); } } if (nodeStates.Count > 0) { UnityEngine.XR.XRNodeState nodeState = nodeStates[nodeStates.Count - 1]; var pose = Pose.identity; var positionSuccess = nodeState.TryGetPosition(out pose.position); var rotationSuccess = nodeState.TryGetRotation(out pose.rotation); if (positionSuccess) { resultPose.position = pose.position; } if (rotationSuccess) { resultPose.rotation = pose.rotation; } return(resultPose); } } #endif // UNITY_2020_1_OR_NEWER return(resultPose); }