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); }
void Update() { XRInputSubsystem subsystem = null; SubsystemManager.GetInstances(s_InputSubsystems); if (s_InputSubsystems.Count > 0) { subsystem = s_InputSubsystems[0]; } m_SupportedTrackingOriginModes = subsystem?.GetSupportedTrackingOriginModes() ?? TrackingOriginModeFlags.Unknown; if (m_CurrentTrackingOriginMode != m_DesiredTrackingOriginMode & m_DesiredTrackingOriginMode != TrackingOriginModeFlags.Unknown) { subsystem?.TrySetTrackingOriginMode(m_DesiredTrackingOriginMode); } m_CurrentTrackingOriginMode = subsystem?.GetTrackingOriginMode() ?? TrackingOriginModeFlags.Unknown; if (m_CurrentTrackingOriginModeDisplay != null) { m_CurrentTrackingOriginModeDisplay.text = m_CurrentTrackingOriginMode.ToString(); } if (m_RecenteredImage != null) { float lerp = (Time.time - m_LastRecenteredTime) / m_RecenteredColorResetTime; lerp = Mathf.Clamp(lerp, 0.0f, 1.0f); m_RecenteredImage.color = Color.Lerp(m_RecenteredColor, m_RecenteredOffColor, lerp); } }
void UpdateSupportedTrackingOriginModes(XRInputSubsystem subsystem) { TrackingOriginModeFlags supportedOriginModes = subsystem.GetSupportedTrackingOriginModes(); s_SupportedTrackingOriginModes.Clear(); for (int i = 0; i < 31; i++) { uint modeToCheck = 1u << i; if ((modeToCheck & ((UInt32)supportedOriginModes)) != 0) { s_SupportedTrackingOriginModes.Add((TrackingOriginModeFlags)modeToCheck); } } }
public void UpdateCurrentOriginType(TrackingOriginModeFlags targetTrackingOriginMode) { Debug.Log((uint)targetTrackingOriginMode); Debug.Log(OnlyOneBitSet((uint)targetTrackingOriginMode)); if (!(OnlyOneBitSet((uint)targetTrackingOriginMode)) && (targetTrackingOriginMode != TrackingOriginModeFlags.Unknown)) { if (m_InputSubsystem.TrySetTrackingOriginMode(targetTrackingOriginMode)) { SetStatus("Error! Tracking mode set to multiple values!"); return; } } if (!m_InputSubsystem.TrySetTrackingOriginMode(targetTrackingOriginMode) && ((targetTrackingOriginMode & m_InputSubsystem.GetSupportedTrackingOriginModes()) != 0)) { SetStatus("Error! Tracking mode could not be set!"); return; } currentOriginType.text = m_InputSubsystem.GetTrackingOriginMode().ToString(); if ((m_InputSubsystem.GetTrackingOriginMode() & m_InputSubsystem.GetSupportedTrackingOriginModes()) == 0) { SetStatus("Error! Tracking mode set to an unsupported mode!"); } else if (targetTrackingOriginMode != m_InputSubsystem.GetTrackingOriginMode()) { SetStatus("Success! Tracking mode not set to an unsupported mode!"); } else { SetStatus("Success! Tracking mode set to a supported mode!"); } }
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); }
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); }