コード例 #1
0
    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);
    }
コード例 #2
0
        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);
        }