public static void StopHaptics(this InteractionSource interactionSource) { if (!WindowsApiChecker.UniversalApiContractV4_IsAvailable) { return; } #if !UNITY_EDITOR && UNITY_2017_2_OR_NEWER 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 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)); foreach (SpatialInteractionSourceState sourceState in sources) { if (sourceState.Source.Id.Equals(interactionSource.id)) { returnValue = sourceState.Source.Controller.TryGetRenderableModelAsync(); } } }, true); } return(returnValue); }
public static void StartHaptics(this InteractionSource interactionSource, float intensity, float durationInSeconds) { 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)) { 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); #elif UNITY_EDITOR_WIN StartHaptics(interactionSource.id, intensity, durationInSeconds); #endif // !UNITY_EDITOR }
/// <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); } }
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); } } }
private void SpatialInteractionManager_SourceLost(SpatialInteractionManager sender, SpatialInteractionSourceEventArgs args) { System.Diagnostics.Debug.WriteLine("SpatialInteractionManager_SourceLost: " + args.State.Source.Id); }
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); } } }
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); } } }
private void SpatialInteractionManager_SourceLost(SpatialInteractionManager sender, SpatialInteractionSourceEventArgs args) { OnSourceLost(args.State.Source.Id); }
/// <summary> /// Capture Spatial Gesture /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnInteractionDetected(SpatialInteractionManager sender, SpatialInteractionDetectedEventArgs args) { gestureRecognizer.CaptureInteraction(args.Interaction); }
public void OnSourcePressed(SpatialInteractionManager sender, SpatialInteractionSourceEventArgs args) { ClockworkSocket.processInput("tap", args.State.TryGetPointerPose(this.currentCoordinateSystem)); }