private static void InvokeTrackingEvent(InputTracking.TrackingStateEventType eventType, XRNode nodeType, long uniqueID, bool tracked) { XRNodeState obj = default(XRNodeState); obj.uniqueID = (ulong)uniqueID; obj.nodeType = nodeType; obj.tracked = tracked; Action <XRNodeState> action; switch (eventType) { case InputTracking.TrackingStateEventType.NodeAdded: action = InputTracking.nodeAdded; break; case InputTracking.TrackingStateEventType.NodeRemoved: action = InputTracking.nodeRemoved; break; case InputTracking.TrackingStateEventType.TrackingAcquired: action = InputTracking.trackingAcquired; break; case InputTracking.TrackingStateEventType.TrackingLost: action = InputTracking.trackingLost; break; default: throw new ArgumentException("TrackingEventHandler - Invalid EventType: " + eventType); } if (action != null) { action(obj); } }
private static bool ValidateProperty(Node nodeType, ref NodeState requestedNodeState) { InputTracking.GetNodeStates(nodeStateList); if (nodeStateList.Count == 0) { return(false); } bool nodeStateFound = false; requestedNodeState = nodeStateList[0]; for (int i = 0; i < nodeStateList.Count; i++) { if (nodeStateList[i].nodeType == nodeType) { requestedNodeState = nodeStateList[i]; nodeStateFound = true; break; } } return(nodeStateFound); }
private static bool GetUnityXRNodeStateVector3(Node nodeType, NodeStatePropertyType propertyType, out Vector3 retVec) { retVec = Vector3.zero; NodeState requestedNodeState = default(NodeState); if (!ValidateProperty(nodeType, ref requestedNodeState)) { return(false); } if (propertyType == NodeStatePropertyType.Acceleration) { if (requestedNodeState.TryGetAcceleration(out retVec)) { return(true); } } else if (propertyType == NodeStatePropertyType.AngularAcceleration) { #if UNITY_2017_2_OR_NEWER if (requestedNodeState.TryGetAngularAcceleration(out retVec)) { return(true); } #endif } else if (propertyType == NodeStatePropertyType.Velocity) { if (requestedNodeState.TryGetVelocity(out retVec)) { return(true); } } else if (propertyType == NodeStatePropertyType.AngularVelocity) { #if UNITY_2017_2_OR_NEWER if (requestedNodeState.TryGetAngularVelocity(out retVec)) { return(true); } #endif } else if (propertyType == NodeStatePropertyType.Position) { if (requestedNodeState.TryGetPosition(out retVec)) { return(true); } } return(false); }
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); }
private static void InvokeTrackingEvent(TrackingStateEventType eventType, XRNode nodeType, long uniqueID, bool tracked) { Action <XRNodeState> callback = null; XRNodeState callbackParam = new XRNodeState(); callbackParam.uniqueID = (ulong)uniqueID; callbackParam.nodeType = nodeType; callbackParam.tracked = tracked; switch (eventType) { case TrackingStateEventType.TrackingAcquired: callback = trackingAcquired; break; case TrackingStateEventType.TrackingLost: callback = trackingLost; break; case TrackingStateEventType.NodeAdded: callback = nodeAdded; break; case TrackingStateEventType.NodeRemoved: callback = nodeRemoved; break; default: throw new ArgumentException("TrackingEventHandler - Invalid EventType: " + eventType); } if (null != callback) { callback(callbackParam); } }
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); }
public Vector3 GetNodeStateProperty(Node nodeType, NodeStatePropertyType propertyType) { List <NodeState> nodeStateList = new List <NodeState>(); InputTracking.GetNodeStates(nodeStateList); if (nodeStateList.Count == 0) { return(Vector3.zero); } bool nodeStateFound = false; NodeState requestedNodeState = nodeStateList[0]; for (int i = 0; i < nodeStateList.Count; i++) { if (nodeStateList[i].nodeType == nodeType) { requestedNodeState = nodeStateList[i]; nodeStateFound = true; break; } } if (!nodeStateFound) { return(Vector3.zero); } Vector3 retVec; if (propertyType == NodeStatePropertyType.Acceleration) { if (requestedNodeState.TryGetAcceleration(out retVec)) { return(retVec); } } else if (propertyType == NodeStatePropertyType.AngularAcceleration) { #if UNITY_2017_2_OR_NEWER if (requestedNodeState.TryGetAngularAcceleration(out retVec)) { retVec = retVec * Mathf.Rad2Deg; return(retVec); } #endif } else if (propertyType == NodeStatePropertyType.Velocity) { if (requestedNodeState.TryGetVelocity(out retVec)) { return(retVec); } } else if (propertyType == NodeStatePropertyType.AngularVelocity) { #if UNITY_2017_2_OR_NEWER if (requestedNodeState.TryGetAngularVelocity(out retVec)) { retVec = retVec * Mathf.Rad2Deg; return(retVec); } #endif } return(Vector3.zero); }