public static void StartHaptics(this InteractionSource interactionSource, float intensity, float durationInSeconds) { #if !UNITY_EDITOR UnityEngine.WSA.Application.InvokeOnUIThread(() => { IReadOnlyList <SpatialInteractionSourceState> sources = SpatialInteractionManager.GetForCurrentView().GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now)); foreach (SpatialInteractionSourceState sourceState in sources) { if (sourceState.Source.Id.Equals(interactionSource.id)) { SimpleHapticsController simpleHapticsController = sourceState.Source.Controller.SimpleHapticsController; foreach (SimpleHapticsControllerFeedback hapticsFeedback in simpleHapticsController.SupportedFeedback) { if (hapticsFeedback.Waveform.Equals(ContinuousBuzzWaveform)) { if (durationInSeconds.Equals(float.MaxValue)) { simpleHapticsController.SendHapticFeedback(hapticsFeedback, intensity); } else { simpleHapticsController.SendHapticFeedbackForDuration(hapticsFeedback, intensity, TimeSpan.FromSeconds(durationInSeconds)); } return; } } } } }, true); #endif }
public static IAsyncOperation <IRandomAccessStreamWithContentType> TryGetRenderableModelAsync(this InteractionSource interactionSource) { IAsyncOperation <IRandomAccessStreamWithContentType> returnValue = null; // GetForCurrentView and GetDetectedSourcesAtTimestamp were both introduced in the same Windows version. // We need only check for one of them. if (WindowsApiChecker.IsMethodAvailable( "Windows.UI.Input.Spatial", "SpatialInteractionManager", "GetForCurrentView")) { IReadOnlyList <SpatialInteractionSourceState> sources = null; UnityEngine.WSA.Application.InvokeOnUIThread(() => { sources = SpatialInteractionManager.GetForCurrentView()?.GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now)); }, true); for (var i = 0; i < sources?.Count; i++) { if (sources[i].Source.Id.Equals(interactionSource.id)) { returnValue = sources[i].Source.Controller.TryGetRenderableModelAsync(); } } } return(returnValue); }
public override void Initialize(Chirality chirality) { #if !UNITY_EDITOR && UNITY_2017_2_OR_NEWER && UNITY_WSA UnityEngine.WSA.Application.InvokeOnUIThread(() => { IReadOnlyList <SpatialInteractionSourceState> sources = SpatialInteractionManager .GetForCurrentView() .GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper .FromHistoricalTargetTime(DateTimeOffset .Now)); foreach (SpatialInteractionSourceState sourceState in sources) { if (sourceState.Source.Handedness == SpatialInteractionSourceHandedness.Left && chirality == Chirality.Left) { _interactionSourceId = sourceState.Source.Id; } if (sourceState.Source.Handedness == SpatialInteractionSourceHandedness.Right && chirality == Chirality.Right) { _interactionSourceId = sourceState.Source.Id; } } }, true); #endif }
private void Start() { #if !UNITY_EDITOR && UNITY_WSA && ENABLE_WINMD_SUPPORT TraceHelper.Log("ControllerModelProvider Using WSA"); UnityEngine.WSA.Application.InvokeOnUIThread(() => { var spatialInteractionManager = SpatialInteractionManager.GetForCurrentView(); if (spatialInteractionManager != null) { #if DEBUG var targetTime = DateTimeOffset.Now; var timeStamp = Windows.Perception.PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now); var sources = spatialInteractionManager.GetDetectedSourcesAtTimestamp(timeStamp); foreach (var source in sources) { System.Diagnostics.Debug.WriteLine("pre-defined source: " + source.Source.Id); } #endif spatialInteractionManager.SourceDetected += SpatialInteractionManager_SourceDetected; spatialInteractionManager.SourceLost += SpatialInteractionManager_SourceLost; } }, true); #endif }
public FingerTracking(SpatialStationaryFrameOfReference referenceFrame, HolographicSpace holographicSpace) { this.referenceFrame = referenceFrame; this.holographicSpace = holographicSpace; interactionManager = SpatialInteractionManager.GetForCurrentView(); interactionManager.SourceUpdated += this.sourceUpdate; }
// Creates and initializes a GestureRecognizer that listens to a Person. public SpatialInputHandler() { // The interaction manager provides an event that informs the app when // spatial interactions are detected. interactionManager = SpatialInteractionManager.GetForCurrentView(); // Bind a handler to the SourcePressed event. interactionManager.SourcePressed += this.OnSourcePressed; }
// Start is called before the first frame update void Start() { #if WINDOWS_UWP handJoints = new HandJointKind[] { HandJointKind.Palm, HandJointKind.Wrist, HandJointKind.ThumbMetacarpal, HandJointKind.ThumbProximal, HandJointKind.ThumbDistal, HandJointKind.ThumbTip, HandJointKind.IndexMetacarpal, HandJointKind.IndexProximal, HandJointKind.IndexIntermediate, HandJointKind.IndexDistal, HandJointKind.IndexTip, HandJointKind.MiddleMetacarpal, HandJointKind.MiddleProximal, HandJointKind.MiddleIntermediate, HandJointKind.MiddleDistal, HandJointKind.MiddleTip, HandJointKind.RingMetacarpal, HandJointKind.RingProximal, HandJointKind.RingIntermediate, HandJointKind.RingDistal, HandJointKind.RingTip, HandJointKind.LittleMetacarpal, HandJointKind.LittleProximal, HandJointKind.LittleIntermediate, HandJointKind.LittleDistal, HandJointKind.LittleTip }; jointPoses = new JointPose[handJoints.Length]; rightHandJoints = new GameObject[handJoints.Length]; leftHandJoints = new GameObject[handJoints.Length]; for (int i = 0; i < rightHandJoints.Length; i++) { rightHandJoints[i] = GameObject.CreatePrimitive(PrimitiveType.Cube); rightHandJoints[i].transform.localScale = Vector3.one * 0.01f; leftHandJoints[i] = GameObject.CreatePrimitive(PrimitiveType.Cube); leftHandJoints[i].transform.localScale = Vector3.one * 0.01f; } SpatialInteractionManager spatialInteraction = null; #if UNITY_2019 spatialCoordinateSystem = Marshal.GetObjectForIUnknown(WindowsMREnvironment.OriginSpatialCoordinateSystem) as SpatialCoordinateSystem; #else spatialCoordinateSystem = Marshal.GetObjectForIUnknown(WorldManager.GetNativeISpatialCoordinateSystemPtr()) as SpatialCoordinateSystem; #endif UnityEngine.WSA.Application.InvokeOnUIThread(() => { spatialInteraction = SpatialInteractionManager.GetForCurrentView(); }, true); spatialInteraction.SourceUpdated += SpatialInteraction_SourceUpdated; #endif }
/// <summary> /// Constructor. /// </summary> public WindowsMixedRealityArticulatedHand(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null) : base(trackingState, controllerHandedness, inputSource, interactions) { #if WINDOWS_UWP UnityEngine.WSA.Application.InvokeOnUIThread(() => { spatialInteractionManager = SpatialInteractionManager.GetForCurrentView(); }, true); #endif // WINDOWS_UWP }
// Start is called before the first frame update void Start() { #if WINDOWS_UWP SpatialInteractionManager spatialInteraction = null; UnityEngine.WSA.Application.InvokeOnUIThread(() => { spatialInteraction = SpatialInteractionManager.GetForCurrentView(); }, true); spatialInteraction.SourcePressed += SpatialInteraction_SourcePressed; spatialInteraction.SourceReleased += SpatialInteraction_SourceReleased; #endif }
private void Awake() { #if ENABLE_WINMD_SUPPORT if (!UnityEngine.WSA.Application.RunningOnUIThread()) { UnityEngine.WSA.Application.InvokeOnUIThread(() => { spatialInteractionManager = SpatialInteractionManager.GetForCurrentView(); spatialInteractionManager.SourcePressed += SpatialInteractionManager_SourcePressed; }, false); } #endif }
// Creates and initializes a GestureRecognizer that listens to a Person. public SpatialInputHandler() { // The interaction manager provides an event that informs the app when // spatial interactions are detected. interactionManager = SpatialInteractionManager.GetForCurrentView(); // Bind a handler to the SourcePressed event. interactionManager.SourcePressed += this.OnSourcePressed; // // TODO: Expand this class to use other gesture-based input events as applicable to // your app. // }
public SpatialInputHandler() { interactionManager = SpatialInteractionManager.GetForCurrentView(); interactionManager.InteractionDetected += OnInteractionDetected; gestureRecognizer = new SpatialGestureRecognizer( SpatialGestureSettings.Tap | SpatialGestureSettings.DoubleTap | SpatialGestureSettings.Hold ); gestureRecognizer.Tapped += OnTap; gestureRecognizer.HoldStarted += OnHoldStarted; gestureRecognizer.HoldCompleted += OnHoldComleted; }
private void Stop() { #if !UNITY_EDITOR && UNITY_WSA && ENABLE_WINMD_SUPPORT TraceHelper.Log("ControllerModelProvider Stopping WSA Event listening"); UnityEngine.WSA.Application.InvokeOnUIThread(() => { var spatialInteractionManager = SpatialInteractionManager.GetForCurrentView(); if (spatialInteractionManager != null) { spatialInteractionManager.SourceDetected -= SpatialInteractionManager_SourceDetected; spatialInteractionManager.SourceLost -= SpatialInteractionManager_SourceLost; IsListening = false; } }, true); #endif }
public static void StopHaptics(this InteractionSource interactionSource) { #if !UNITY_EDITOR UnityEngine.WSA.Application.InvokeOnUIThread(() => { IReadOnlyList <SpatialInteractionSourceState> sources = SpatialInteractionManager.GetForCurrentView().GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now)); foreach (SpatialInteractionSourceState sourceState in sources) { if (sourceState.Source.Id.Equals(interactionSource.id)) { sourceState.Source.Controller.SimpleHapticsController.StopFeedback(); } } }, true); #endif }
public GestureController() { spatialLocator = SpatialLocator.GetDefault(); gestureRecognizer = new SpatialGestureRecognizer( SpatialGestureSettings.Tap | SpatialGestureSettings.ManipulationTranslate); gestureRecognizer.ManipulationCanceled += OnManipulationCanceled; gestureRecognizer.ManipulationCompleted += OnManipulationCompleted; gestureRecognizer.ManipulationStarted += OnManipulationStarted; gestureRecognizer.ManipulationUpdated += OnManipulationUpdated; gestureRecognizer.Tapped += OnTapped; interactionManager = SpatialInteractionManager.GetForCurrentView(); interactionManager.InteractionDetected += OnInteractionDetected; }
private void Start() { controllerDictionary = new Dictionary <uint, ControllerInfo>(); #if UNITY_WSA #if !UNITY_EDITOR if (GLTFMaterial == null) { if (LeftControllerOverride == null && RightControllerOverride == null) { Debug.Log("If using glTF, please specify a material on " + name + ". Otherwise, please specify controller overrides."); } else if (LeftControllerOverride == null || RightControllerOverride == null) { Debug.Log("Only one override is specified, and no material is specified for the glTF model. Please set the material or the " + ((LeftControllerOverride == null) ? "left" : "right") + " controller override on " + name + "."); } } // Since the SpatialInteractionManager exists in the current CoreWindow, this call needs to run on the UI thread. UnityEngine.WSA.Application.InvokeOnUIThread(() => { spatialInteractionManager = SpatialInteractionManager.GetForCurrentView(); if (spatialInteractionManager != null) { spatialInteractionManager.SourceDetected += SpatialInteractionManager_SourceDetected; spatialInteractionManager.SourceLost += SpatialInteractionManager_SourceLost; } }, true); #else // Since we're using non-Unity APIs, glTF will only load in a UWP app. if (LeftControllerOverride == null && RightControllerOverride == null) { Debug.Log("Running in the editor won't render the glTF models, and no controller overrides are set. Please specify them on " + name + "."); } else if (LeftControllerOverride == null || RightControllerOverride == null) { Debug.Log("Running in the editor won't render the glTF models, and only one controller override is specified. Please set the " + ((LeftControllerOverride == null) ? "left" : "right") + " override on " + name + "."); } InteractionManager.InteractionSourceDetected += InteractionManager_InteractionSourceDetected; InteractionManager.InteractionSourceLost += InteractionManager_InteractionSourceLost; #endif InteractionManager.InteractionSourceUpdated += InteractionManager_InteractionSourceUpdated; #endif }
public static IAsyncOperation <IRandomAccessStreamWithContentType> TryGetRenderableModelAsync(this InteractionSource interactionSource) { IAsyncOperation <IRandomAccessStreamWithContentType> returnValue = null; UnityEngine.WSA.Application.InvokeOnUIThread(() => { IReadOnlyList <SpatialInteractionSourceState> sources = SpatialInteractionManager.GetForCurrentView().GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now)); foreach (SpatialInteractionSourceState sourceState in sources) { if (sourceState.Source.Id.Equals(interactionSource.id)) { returnValue = sourceState.Source.Controller.TryGetRenderableModelAsync(); } } }, true); return(returnValue); }
private async Task GetController() { var access = await VibrationDevice.RequestAccessAsync(); if (access == VibrationAccessStatus.Allowed) { var mgr = SpatialInteractionManager.GetForCurrentView(); var calendar = new Calendar(); var timestamp = PerceptionTimestampHelper.FromHistoricalTargetTime(calendar.GetDateTime()); controller = (from s in mgr.GetDetectedSourcesAtTimestamp(timestamp) where s.Source.Id == ControllerID select s.Source.Controller.SimpleHapticsController) .FirstOrDefault(); expressions = new Dictionary <ushort, SimpleHapticsControllerFeedback>(5); if (controller != null) { foreach (var fb in controller.SupportedFeedback) { if (fb.Waveform == KnownSimpleHapticsControllerWaveforms.BuzzContinuous) { buzz = fb; } else if (fb.Waveform == KnownSimpleHapticsControllerWaveforms.Click) { click = fb; } else if (fb.Waveform == KnownSimpleHapticsControllerWaveforms.Press) { press = fb; } else if (fb.Waveform == KnownSimpleHapticsControllerWaveforms.Release) { release = fb; } expressions[fb.Waveform] = fb; } } } }
public static IAsyncOperation <IRandomAccessStreamWithContentType> TryGetRenderableModelAsync(this InteractionSource interactionSource) { IAsyncOperation <IRandomAccessStreamWithContentType> returnValue = null; if (WindowsApiChecker.UniversalApiContractV5_IsAvailable) { UnityEngine.WSA.Application.InvokeOnUIThread(() => { IReadOnlyList <SpatialInteractionSourceState> sources = SpatialInteractionManager.GetForCurrentView().GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now)); for (var i = 0; i < sources.Count; i++) { if (sources[i].Source.Id.Equals(interactionSource.id)) { returnValue = sources[i].Source.Controller.TryGetRenderableModelAsync(); } } }, true); } return(returnValue); }
/// <summary> /// Initialize all resources used by this instance. /// </summary> public void Initialize() { var mixedRealityService = WaveServices.GetService <MixedRealityService>(); this.mixedRealityApplication = mixedRealityService?.MixedRealityApplication as BaseMixedRealityApplication; if (this.mixedRealityApplication != null) { this.isMixedRealityControllerAvailable = ApiInformation.IsApiContractPresent("Windows.Foundation.UniversalApiContract", 4); // The interaction manager provides an event that informs when spacial interactions are detected. this.interactionManager = SpatialInteractionManager.GetForCurrentView(); this.interactionManager.InteractionDetected += this.OnInteractionDetected; this.interactionManager.SourceDetected += this.OnSourceDetected; this.interactionManager.SourceLost += this.OnSourceLost; this.interactionManager.SourcePressed += this.OnSourcePressed; this.interactionManager.SourceReleased += this.OnSourceReleased; this.interactionManager.SourceUpdated += this.OnSourceUpdated; this.gestureRecognizer = new SpatialGestureRecognizer(SpatialGestureSettings.None); } }
public static void StopHaptics(this InteractionSource interactionSource) { if (!WindowsApiChecker.UniversalApiContractV4_IsAvailable && !Application.isEditor) { return; } #if !UNITY_EDITOR UnityEngine.WSA.Application.InvokeOnUIThread(() => { IReadOnlyList <SpatialInteractionSourceState> sources = SpatialInteractionManager.GetForCurrentView().GetDetectedSourcesAtTimestamp(PerceptionTimestampHelper.FromHistoricalTargetTime(DateTimeOffset.Now)); foreach (SpatialInteractionSourceState sourceState in sources) { if (sourceState.Source.Id.Equals(interactionSource.id)) { sourceState.Source.Controller.SimpleHapticsController.StopFeedback(); } } }, true); #elif UNITY_EDITOR_WIN StopHaptics(interactionSource.id); #endif // !UNITY_EDITOR }
private void _StartListeners() { #if TRACING_VERBOSE Debug.Log("ControllerModelProvider::Starting listeners "); #endif #if UNITY_EDITOR && UNITY_WSA InteractionManager.InteractionSourceDetected += InteractionManager_InteractionSourceDetected; InteractionManager.InteractionSourceLost += InteractionManager_InteractionSourceLost; IsListening = true; #elif !UNITY_EDITOR && UNITY_WSA && ENABLE_WINMD_SUPPORT UnityEngine.WSA.Application.InvokeOnUIThread(() => { var spatialInteractionManager = SpatialInteractionManager.GetForCurrentView(); if (spatialInteractionManager != null) { spatialInteractionManager.SourceDetected += SpatialInteractionManager_SourceDetected; spatialInteractionManager.SourceLost += SpatialInteractionManager_SourceLost; IsListening = true; } }, true); #endif }
public unsafe void Run() { AppStarting?.Invoke(); ReferenceFrame = SpatialLocator.GetDefault().CreateStationaryFrameOfReferenceAtCurrentLocation(); var coreWindow = CoreWindow.GetForCurrentThread(); coreWindow.CustomProperties.Add(nameof(HolographicSpace), HolographicSpace); InitializeSpace(); InteractionManager = SpatialInteractionManager.GetForCurrentView(); InteractionManager.InteractionDetected += (s, e) => GesturesManager?.HandleInteraction(e.Interaction); while (!windowClosed) { if (!appInited) { SpatialMappingManager = new SpatialMappingManager(); VoiceManager = new VoiceManager(); appInited = true; if (options == null) { options = new ApplicationOptions(); } //override some options: options.LimitFps = false; options.Width = 1268; //TODO: find system options.Height = 720; Game = (HoloApplication)Activator.CreateInstance(holoAppType, options); Game.Run(); GesturesManager = new GesturesManager(Game, ReferenceFrame); AppStarted?.Invoke(Game); } if (windowVisible && (null != HolographicSpace)) { if (Game != null) { CurrentFrame = HolographicSpace.CreateNextFrame(); CurrentFrame.UpdateCurrentPrediction(); var prediction = CurrentFrame.CurrentPrediction; if (prediction.CameraPoses.Count < 1) { continue; } var cameraPose = prediction.CameraPoses[0]; var viewBox = cameraPose.TryGetViewTransform(ReferenceFrame.CoordinateSystem); if (viewBox != null) { Matrix4x4 leftViewMatrixDx = viewBox.Value.Left; Matrix4x4 rightViewMatrixDx = viewBox.Value.Right; Matrix4x4 leftProjMatrixDx = cameraPose.ProjectionTransform.Left; Matrix4x4 rightProjMatrixDx = cameraPose.ProjectionTransform.Right; Matrix4 leftViewMatrixUrho = *(Matrix4 *)(void *)&leftViewMatrixDx; Matrix4 rightViewMatrixUrho = *(Matrix4 *)(void *)&rightViewMatrixDx; Matrix4 leftProjMatrixUrho = *(Matrix4 *)(void *)&leftProjMatrixDx; Matrix4 rightProjMatrixUrho = *(Matrix4 *)(void *)&rightProjMatrixDx; Game.UpdateStereoView(leftViewMatrixUrho, rightViewMatrixUrho, leftProjMatrixUrho, rightProjMatrixUrho); } var parameters = CurrentFrame.GetRenderingParameters(cameraPose); if (Game.FocusWorldPoint != Vector3.Zero) { parameters.SetFocusPoint(ReferenceFrame.CoordinateSystem, new System.Numerics.Vector3( Game.FocusWorldPoint.X, Game.FocusWorldPoint.Y, -Game.FocusWorldPoint.Z)); //LH->RH } Game.Engine.RunFrame(); CurrentFrame.PresentUsingCurrentPrediction(HolographicFramePresentWaitBehavior.WaitForFrameToFinish); } CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent); } else { CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessOneAndAllPending); } } }
public unsafe void Run() { LoadAssets(new[] { assetsPakName == null ? null : assetsPakName + ".pak" }); CoreWindow.GetForCurrentThread().CustomProperties.Add("HolographicSpace", HolographicSpace); InitializeSpace(); InteractionManager = SpatialInteractionManager.GetForCurrentView(); InteractionManager.InteractionDetected += (s, e) => GesturesManager?.HandleInteraction(e.Interaction); while (!windowClosed) { if (assetsLoaded && !appInited) { SpatialMappingManager = new SpatialMappingManager(); appInited = true; Game = (HoloApplication)Activator.CreateInstance(holoAppType, assetsPakName, false); Game.Run(); Game.Engine.PostUpdate += e => currentFrame?.UpdateCurrentPrediction(); GesturesManager = new GesturesManager(Game, ReferenceFrame); } if (windowVisible && (null != HolographicSpace)) { if (Game != null) { currentFrame = HolographicSpace.CreateNextFrame(); var prediction = currentFrame.CurrentPrediction; if (prediction.CameraPoses.Count < 1) { continue; } var cameraPose = prediction.CameraPoses[0]; var viewBox = cameraPose.TryGetViewTransform(ReferenceFrame.CoordinateSystem); if (viewBox != null) { Matrix4x4 leftViewMatrixDx = viewBox.Value.Left; Matrix4x4 rightViewMatrixDx = viewBox.Value.Right; Matrix4x4 leftProjMatrixDx = cameraPose.ProjectionTransform.Left; Matrix4x4 rightProjMatrixDx = cameraPose.ProjectionTransform.Right; Matrix4 leftViewMatrixUrho = *(Matrix4 *)(void *)&leftViewMatrixDx; Matrix4 rightViewMatrixUrho = *(Matrix4 *)(void *)&rightViewMatrixDx; Matrix4 leftProjMatrixUrho = *(Matrix4 *)(void *)&leftProjMatrixDx; Matrix4 rightProjMatrixUrho = *(Matrix4 *)(void *)&rightProjMatrixDx; Game.UpdateStereoView(leftViewMatrixUrho, rightViewMatrixUrho, leftProjMatrixUrho, rightProjMatrixUrho); } var parameters = currentFrame.GetRenderingParameters(cameraPose); if (Game.FocusWorldPoint != Vector3.Zero) { parameters.SetFocusPoint(ReferenceFrame.CoordinateSystem, new System.Numerics.Vector3( Game.FocusWorldPoint.X, Game.FocusWorldPoint.Y, -Game.FocusWorldPoint.Z)); //LH->RH } Game.Engine.RunFrame(); currentFrame.PresentUsingCurrentPrediction(HolographicFramePresentWaitBehavior.WaitForFrameToFinish); } CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent); } else { CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessOneAndAllPending); } } }
public unsafe void Run() { AppStarting?.Invoke(); ReferenceFrame = SpatialLocator.GetDefault().CreateStationaryFrameOfReferenceAtCurrentLocation(); var coreWindow = CoreWindow.GetForCurrentThread(); coreWindow.CustomProperties.Add(nameof(HolographicSpace), HolographicSpace); InitializeSpace(); HolographicSpace.CameraAdded += HolographicSpace_CameraAdded; InteractionManager = SpatialInteractionManager.GetForCurrentView(); if (InteractionManager != null) { InteractionManager.InteractionDetected += (s, e) => GesturesManager?.HandleInteraction(e.Interaction); } while (!windowClosed) { if (appInited && windowVisible && (null != HolographicSpace)) { if (Game != null) { CurrentFrame = HolographicSpace.CreateNextFrame(); CurrentFrame.UpdateCurrentPrediction(); var prediction = CurrentFrame.CurrentPrediction; if (prediction.CameraPoses.Count < 1) { continue; } var cameraPose = prediction.CameraPoses[0]; var viewBox = cameraPose.TryGetViewTransform(ReferenceFrame.CoordinateSystem); if (viewBox != null) { Matrix4x4 leftViewMatrixDx = viewBox.Value.Left; Matrix4x4 rightViewMatrixDx = viewBox.Value.Right; Matrix4x4 leftProjMatrixDx = cameraPose.ProjectionTransform.Left; Matrix4x4 rightProjMatrixDx = cameraPose.ProjectionTransform.Right; Matrix4 leftViewMatrixUrho = *(Matrix4 *)(void *)&leftViewMatrixDx; Matrix4 rightViewMatrixUrho = *(Matrix4 *)(void *)&rightViewMatrixDx; Matrix4 leftProjMatrixUrho = *(Matrix4 *)(void *)&leftProjMatrixDx; Matrix4 rightProjMatrixUrho = *(Matrix4 *)(void *)&rightProjMatrixDx; Game.UpdateStereoView(leftViewMatrixUrho, rightViewMatrixUrho, leftProjMatrixUrho, rightProjMatrixUrho); } var parameters = CurrentFrame.GetRenderingParameters(cameraPose); if (Game.FocusWorldPoint != Vector3.Zero) { parameters.SetFocusPoint(ReferenceFrame.CoordinateSystem, new System.Numerics.Vector3( Game.FocusWorldPoint.X, Game.FocusWorldPoint.Y, -Game.FocusWorldPoint.Z)); //LH->RH } Game.Engine.RunFrame(); CurrentFrame.PresentUsingCurrentPrediction(HolographicFramePresentWaitBehavior.WaitForFrameToFinish); } CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessAllIfPresent); } else { CoreWindow.GetForCurrentThread().Dispatcher.ProcessEvents(CoreProcessEventsOption.ProcessOneAndAllPending); } } }