예제 #1
0
    /// <summary>
    /// Recenters the head pose.
    /// </summary>
    public void RecenterPose()
    {
#if USING_XR_SDK
        XRInputSubsystem currentInputSubsystem = OVRManager.GetCurrentInputSubsystem();
        if (currentInputSubsystem != null)
        {
            currentInputSubsystem.TryRecenter();
        }
#elif !REQUIRES_XR_SDK
#pragma warning disable 618
        InputTracking.Recenter();
#pragma warning restore 618
#endif

        // The current poses are cached for the current frame and won't be updated immediately
        // after UnityEngine.VR.InputTracking.Recenter(). So we need to wait until next frame
        // to trigger the RecenteredPose delegate. The application could expect the correct pose
        // when the RecenteredPose delegate get called.
        recenterRequested           = true;
        recenterRequestedFrameCount = Time.frameCount;

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
        OVRMixedReality.RecenterPose();
#endif
    }
 public void TryRecenter()
 {
     if (m_InputSubsystem.TryRecenter())
     {
         SetStatus("Recentered");
     }
     else
     {
         SetStatus("Could not recenter. Recenter can only function in Device TrackingMode, and may not be available on this provider.");
     }
 }
예제 #3
0
        bool SetupCamera(XRInputSubsystem subsystem)
        {
            if (subsystem == null)
            {
                return(false);
            }

            bool trackingSettingsSet = false;

            float desiredOffset = cameraYOffset;

            if (m_TrackingSpace == TrackingSpaceType.RoomScale)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((subsystem.GetSupportedTrackingOriginModes() & (TrackingOriginModeFlags.Floor | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("XRRig.SetupCamera: Attempting to set the tracking space to Room, but that is not supported by the SDK.");
                    return(true);
                }

                if (subsystem.TrySetTrackingOriginMode(TrackingOriginModeFlags.Floor))
                {
                    desiredOffset       = 0;
                    trackingSettingsSet = true;
                }
            }

            if (m_TrackingSpace == TrackingSpaceType.Stationary)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((subsystem.GetSupportedTrackingOriginModes() & (TrackingOriginModeFlags.Device | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("XRRig.SetupCamera: Attempting to set the tracking space to Stationary, but that is not supported by the SDK.");
                    return(true);
                }

                if (subsystem.TrySetTrackingOriginMode(TrackingOriginModeFlags.Device))
                {
                    trackingSettingsSet = subsystem.TryRecenter();
                }
            }

            if (trackingSettingsSet)
            {
                // Move camera to correct height
                if (m_CameraFloorOffsetObject)
                {
                    m_CameraFloorOffsetObject.transform.localPosition = new Vector3(m_CameraFloorOffsetObject.transform.localPosition.x, desiredOffset, m_CameraFloorOffsetObject.transform.localPosition.z);
                }
            }
            return(trackingSettingsSet);
        }
예제 #4
0
        bool SetupCamera(XRInputSubsystem subsystem)
        {
            if (subsystem == null)
            {
                return(false);
            }

            bool trackingSettingsSet = false;

            var currentMode    = subsystem.GetTrackingOriginMode();
            var supportedModes = subsystem.GetSupportedTrackingOriginModes();
            TrackingOriginModeFlags requestedMode = TrackingOriginModeFlags.Unknown;

            // map between the user requested options, and the actual options.
            if (m_RequestedTrackingMode == UserRequestedTrackingMode.Default)
            {
                requestedMode = currentMode;
            }
            else if (m_RequestedTrackingMode == UserRequestedTrackingMode.Device)
            {
                requestedMode = TrackingOriginModeFlags.Device;
            }
            else if (m_RequestedTrackingMode == UserRequestedTrackingMode.Floor)
            {
                requestedMode = TrackingOriginModeFlags.Floor;
            }
            else
            {
                Debug.LogWarning("Unknown Requested Tracking Mode");
            }

            // now we've mapped em. actually go set em.
            if (requestedMode == TrackingOriginModeFlags.Floor)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((supportedModes & (TrackingOriginModeFlags.Floor | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("CameraOffset.SetupCamera: Attempting to set the tracking space to Floor, but that is not supported by the SDK.");
                }
                else
                {
                    trackingSettingsSet = subsystem.TrySetTrackingOriginMode(requestedMode);
                }
            }
            else if (requestedMode == TrackingOriginModeFlags.Device)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((supportedModes & (TrackingOriginModeFlags.Device | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("CameraOffset.SetupCamera: Attempting to set the tracking space to Device, but that is not supported by the SDK.");
                }
                else
                {
                    trackingSettingsSet = subsystem.TrySetTrackingOriginMode(requestedMode) && subsystem.TryRecenter();
                }
            }

            if (trackingSettingsSet)
            {
                UpdateTrackingOrigin(subsystem.GetTrackingOriginMode());
            }

            return(trackingSettingsSet);
        }
예제 #5
0
        bool SetupCamera(XRInputSubsystem subsystem)
        {
            if (subsystem == null)
            {
                return(false);
            }

            bool trackingSettingsSet = false;

            float desiredOffset = cameraYOffset;

            var currentMode    = subsystem.GetTrackingOriginMode();
            var supportedModes = subsystem.GetSupportedTrackingOriginModes();
            TrackingOriginModeFlags requestedMode = TrackingOriginModeFlags.Unknown;

            // map between the user requested options, and the actual options.
            if (m_RequestedTrackingMode == UserRequestedTrackingMode.Default)
            {
                requestedMode = currentMode;
            }
            else if (m_RequestedTrackingMode == UserRequestedTrackingMode.Device)
            {
                requestedMode = TrackingOriginModeFlags.Device;
            }
            else if (m_RequestedTrackingMode == UserRequestedTrackingMode.Floor)
            {
                requestedMode = TrackingOriginModeFlags.Floor;
            }
            else
            {
                Debug.LogWarning("Unknown Requested Tracking Mode");
            }

            // now we've mapped em. actually go set em.
            if (requestedMode == TrackingOriginModeFlags.Floor)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((supportedModes & (TrackingOriginModeFlags.Floor | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("CameraOffset.SetupCamera: Attempting to set the tracking space to Floor, but that is not supported by the SDK.");
                    m_TrackingOriginMode = subsystem.GetTrackingOriginMode();
                    return(true);
                }

                if (subsystem.TrySetTrackingOriginMode(requestedMode))
                {
                    desiredOffset       = 0.0f;
                    trackingSettingsSet = true;
                }
            }
            else if (requestedMode == TrackingOriginModeFlags.Device)
            {
                // We need to check for Unknown because we may not be in a state where we can read this data yet.
                if ((supportedModes & (TrackingOriginModeFlags.Device | TrackingOriginModeFlags.Unknown)) == 0)
                {
                    Debug.LogWarning("CameraOffset.SetupCamera: Attempting to set the tracking space to Device, but that is not supported by the SDK.");
                    m_TrackingOriginMode = subsystem.GetTrackingOriginMode();
                    return(true);
                }

                if (subsystem.TrySetTrackingOriginMode(requestedMode))
                {
                    trackingSettingsSet = subsystem.TryRecenter();
                }
            }

            // what did we actually set?
            m_TrackingOriginMode = subsystem.GetTrackingOriginMode();

            if (trackingSettingsSet)
            {
                // Move camera to correct height
                if (m_CameraFloorOffsetObject)
                {
                    m_CameraFloorOffsetObject.transform.localPosition = new Vector3(m_CameraFloorOffsetObject.transform.localPosition.x, desiredOffset, m_CameraFloorOffsetObject.transform.localPosition.z);
                }
            }
            return(trackingSettingsSet);
        }