Example #1
0
        private void Collider_BeginCollision(ICollisionInfo2D contact)
        {
            WaveForegroundTask.Run(() =>
            {
                var colliderA = contact.ColliderA; // Obstacle
                var colliderB = contact.ColliderB; // Arrow

                if (colliderA != null && colliderB != null && colliderA.CollisionCategories == ColliderCategory2D.Cat2)
                {
                    var physicBodyA = colliderA.RigidBody.UserData as RigidBody2D;
                    var physicBodyB = colliderB.RigidBody.UserData as RigidBody2D;

                    Entity obstacle = physicBodyA.Owner;
                    Entity arrow    = physicBodyB.Owner;
                    Transform2D obstacleTransform = obstacle.FindComponent <Transform2D>();
                    Transform2D arrowTransform    = arrow.FindComponent <Transform2D>();

                    Vector2 arrowHeadLocalPosition = Vector2.UnitX * 178;
                    Vector2 arrowHeadWorldPosition = Vector2.Transform(arrowHeadLocalPosition, arrowTransform.WorldTransform);
                    Vector2 obstacleLocalPosition  = Vector2.Transform(arrowHeadWorldPosition, obstacleTransform.WorldInverseTransform);


                    WeldJoint2D distance = new WeldJoint2D()
                    {
                        ConnectedEntityPath = obstacle.EntityPath,
                        Anchor          = arrowHeadLocalPosition,
                        ConnectedAnchor = obstacleLocalPosition,
                        ReferenceAngle  = obstacleTransform.LocalRotation - arrowTransform.LocalRotation,
                    };
                    arrow.AddComponent(distance);
                }
            });
        }
            public override Task <Observation> Reset(ServiceMessage request, ServerCallContext context)
            {
                return(WaveForegroundTask.Run(() =>
                {
                    var newScene = new MyScene();
                    WaveServices.ScreenContextManager.To(new ScreenContext(newScene), true);

                    var tcs = new TaskCompletionSource <Observation>();
                    void StartedHandler(object sender, EventArgs args)
                    {
                        newScene.Started -= StartedHandler;
                        WaveForegroundTask.Run(() =>
                        {
                            this.service.SetScene(newScene);
                            this.service.enginesComponent.ApplyInitialForce();
                            this.service.enginesComponent.ApplyEngineAction(EngineActions.None);
                            this.service.scene.NextStep(TimeSpan.FromSeconds(1 / LunarConstants.FPS));
                            var actionResult = this.service.GetActionResult(EngineActions.None);
                            tcs.SetResult(actionResult.Observation);
                        });
                    }
                    newScene.Started += StartedHandler;
                    return tcs.Task;
                }));
            }
            public override Task <ServiceMessage> Render(ServiceMessage request, ServerCallContext context)
            {
                return(WaveForegroundTask.Run(() =>
                {
                    this.service.Rendered?.Invoke(this, null);

                    return new ServiceMessage();
                }));
            }
 private void OnGestureRecognitionStarted(SpatialGestureRecognizer sender, SpatialRecognitionStartedEventArgs args)
 {
     if (this.RecognitionStartedEvent != null)
     {
         WaveForegroundTask.Run(() =>
         {
             this.RecognitionStartedEvent(this.service, (SpatialSource)args.InteractionSourceKind);
         });
     }
 }
 public override Task <ActionResult> PerformAction(Lunar2D.Action request, ServerCallContext context)
 {
     return(WaveForegroundTask.Run(() =>
     {
         var action = request.EngineAction.ToEngineAction();
         this.service.enginesComponent.ApplyEngineAction(action);
         this.service.scene.NextStep(TimeSpan.FromSeconds(1 / LunarConstants.FPS));
         return this.service.GetActionResult(action);
     }));
 }
 private void InternalRaiseEvent(Action eventAction)
 {
     if (Framework.Game.Current != null)
     {
         WaveForegroundTask.Run(eventAction);
     }
     else
     {
         Task.Factory.StartNew(eventAction, CancellationToken.None, TaskCreationOptions.HideScheduler, this.concurrentSchedulerPair.Value.ExclusiveScheduler);
     }
 }
        /// <summary>
        /// Occurs when a hand or controller has experienced a change to its SpatialInteractionSourceState.
        /// </summary>
        /// <param name="sender">Sender object.</param>
        /// <param name="args">Raw args.</param>
        private void OnSourceUpdated(SpatialInteractionManager sender, SpatialInteractionSourceEventArgs args)
        {
            this.UpdatedState(args);

            if (this.SourceUpdated != null)
            {
                WaveForegroundTask.Run(() =>
                {
                    this.SourceUpdated(this.service, this.currentSpatialState);
                });
            }
        }
 private void OnGestureNavigationCanceled(SpatialGestureRecognizer sender, SpatialNavigationCanceledEventArgs args)
 {
     if (this.NavigationCanceledEvent != null)
     {
         WaveForegroundTask.Run(() =>
         {
             this.NavigationCanceledEvent(
                 this.service,
                 (SpatialSource)args.InteractionSourceKind,
                 this.mixedRealityApplication.HeadRay);
         });
     }
 }
 private void OnGestureManipulationUpdated(SpatialGestureRecognizer sender, SpatialManipulationUpdatedEventArgs args)
 {
     if (this.ManipulationUpdatedEvent != null)
     {
         WaveForegroundTask.Run(() =>
         {
             this.ManipulationUpdatedEvent(
                 this.service,
                 (SpatialSource)args.InteractionSourceKind,
                 args.TryGetCumulativeDelta(this.CoordinateSystem).Translation.ToWave(),
                 this.mixedRealityApplication.HeadRay);
         });
     }
 }
        /// <summary>
        /// Handle events fired when a result is generated.
        /// </summary>
        /// <param name="sender">The Recognition session that generated this result</param>
        /// <param name="args">Details about the recognized speech</param>
        private void ContinuousRecognitionSession_ResultGenerated(SpeechContinuousRecognitionSession sender, SpeechContinuousRecognitionResultGeneratedEventArgs args)
        {
            var confidence = args.Result.Confidence;
            var text = args.Result.Text;
            Debug.WriteLine($"VoiceCommand: Text recognized '{text}' with condifence {confidence}");

            // We may choose to discard content that has low confidence, as that could indicate that we're picking up
            // noise via the microphone, or someone could be talking out of earshot.
            if (confidence == SpeechRecognitionConfidence.Medium ||
                confidence == SpeechRecognitionConfidence.High)
            {
                WaveForegroundTask.Run(() => this.CommandRecognized?.Invoke(this, text));
            }
        }
Example #11
0
        /// <summary>
        /// Handles the SurfaceObserver's OnSurfaceChanged event.
        /// </summary>
        /// <param name="id">The identifier assigned to the surface which has changed.</param>
        /// <param name="surface">The surface</param>
        /// <param name="changeType">The type of change that occurred on the surface.</param>
        /// <param name="updateTime">The date and time at which the change occurred.</param>
        protected virtual void OnSurfaceChanged(Guid id, SpatialMappingSurface surface, SurfaceChange changeType, DateTimeOffset updateTime)
        {
            WaveForegroundTask.Run(() =>
            {
                if (surface.Mesh == null)
                {
                    return;
                }

                Debug.WriteLine("OnSurfaceChanged [" + changeType + "] " + id);

                string entityId = this.GetEntityNameFromSurfaceId(id);

                switch (changeType)
                {
                case SurfaceChange.Added:
                case SurfaceChange.Updated:

                    var surfaceEntity = this.Owner.FindChild(entityId);
                    if (surfaceEntity == null)
                    {
                        surfaceEntity     = this.CreateNewSurfaceEntity(entityId, surface);
                        surfaceEntity.Tag = SurfaceEntityTag;

                        if (surfaceEntity != null)
                        {
                            this.Owner.AddChild(surfaceEntity);
                        }
                    }
                    else
                    {
                        this.RefreshModel(surface, surfaceEntity);
                        this.UpdateSurfaceEntity(surface, surfaceEntity);
                    }

                    break;

                case SurfaceChange.Removed:

                    // Remove the child entity
                    this.Owner.RemoveChild(entityId);

                    break;

                default:
                    break;
                }
            });
        }
        /// <inheritdoc/>
        protected override void Terminate()
        {
            base.Terminate();

            if (this.noesisInitialized)
            {
                this.noesisInitialized = false;

                WaveForegroundTask.Run(() =>
                {
                    Noesis.GUI.UnregisterNativeTypes();
                    this.renderDevice = null;
                });
            }
        }
Example #13
0
        protected override void CreateScene()
        {
            this.Load(WaveContent.Scenes.MyScene);

            this.camera3DEntity = this.EntityManager.Find("defaultCamera3D");

            // Create effects
            this.CreateEffects();

            // Button next effect
            this.effectButton = new Button()
            {
                Text = "Original",
                VerticalTextAlignment = VerticalAlignment.Center,
                Width               = 250,
                BackgroundColor     = Color.Purple,
                HorizontalAlignment = HorizontalAlignment.Center,
            };
            this.effectButton.Click += (s, o) =>
            {
                if (!this.flag)
                {
                    WaveForegroundTask.Run(() =>
                    {
                        this.flag = true;

                        if (this.lastEffect != null)
                        {
                            this.camera3DEntity.RemoveComponent(this.lastEffect);
                        }

                        this.lastEffect         = this.effects[this.currentEffectIndex];
                        this.currentEffectIndex = (this.currentEffectIndex + 1) % this.effects.Count;
                        this.effectButton.Text  = this.lastEffect.GetType().Name;
                        WaveServices.Layout.PerformLayout();

                        if (this.lastEffect != null)
                        {
                            this.camera3DEntity.AddComponent(this.lastEffect);
                        }

                        this.flag = false;
                    });
                }
            };
            this.EntityManager.Add(this.effectButton);
        }
Example #14
0
        private async Task <Texture2D> LoadTextureAsync(string imageUrl, CancellationToken cancellationToken)
        {
            using (var imageStreamResult = await ImagesHelper.LoadImageStreamAsync(imageUrl, cancellationToken).ConfigureWaveAwait(WaveTaskContinueOn.Background))
            {
                if (!imageStreamResult.IsSuccess)
                {
                    return(null);
                }

                cancellationToken.ThrowIfCancellationRequested();
                var texture = Texture2D.FromFile(this.RenderManager.GraphicsDevice, imageStreamResult.Stream);
                this.downloadedImages++;
                await WaveForegroundTask.Run((Action)UpdateText, cancellationToken).ConfigureAwait(false);

                return(texture);
            }
        }
            public override Task <Observation> Reset(ServiceMessage request, ServerCallContext context)
            {
                return(WaveForegroundTask.Run(() =>
                {
                    if (!this.service.sceneLoaded)
                    {
                        this.service.sceneLoaded = true;
                        var newScene = new MyScene3D();
                        WaveServices.ScreenContextManager.To(new ScreenContext(newScene), true);
                        newScene.Initialize(WaveServices.GraphicsDevice);
                    }

                    this.service.OnReset?.Invoke(this.service, null);

                    return this.service.GetUpdatedObservation();
                }));
            }
Example #16
0
        protected async Task InitializeAsync(bool forceCreateContextInWaveThread)
        {
            base.Initialize();

            // Get ScreenContextManager
            var screenContextManager = this.Container.Resolve <ScreenContextManager>();

            ScreenContext screenContext;

            if (forceCreateContextInWaveThread)
            {
                screenContext = await WaveForegroundTask.Run(() => this.CreateScreenContext());
            }
            else
            {
                screenContext = this.CreateScreenContext();
            }

            // Navigate to scene
            screenContextManager.To(screenContext, false);
        }
            public override Task <ActionResult> PerformAction(Lunar3D.Action request, ServerCallContext context)
            {
                // count++;
                // test.Start();
                return(WaveForegroundTask.Run(() =>
                {
                    var action = request.EngineAction.ToEngineAction();
                    this.service.ActionReveiced?.Invoke(this, action);

                    // Next step
                    this.service.Updated?.Invoke(this, TimeSpan.FromSeconds(1 / LunarConstants.FPS));

                    return this.service.GetActionResult(action);
                }));/*.ContinueWith(t =>
                     * {
                     * test.Stop();
                     * if (count % 1000 == 0)
                     * {
                     *   Debug.WriteLine(test.ElapsedMilliseconds / (double)count);
                     * }
                     * return t.Result;
                     * });*/
            }
Example #18
0
        private void GetResponseCallback(IAsyncResult asynchronousResult)
        {
            WaveForegroundTask.Run(() =>
            {
                HttpWebRequest request = asynchronousResult.AsyncState as HttpWebRequest;

                try
                {
                    using (HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult))
                        using (var imageStream = response.GetResponseStream())
                        {
                            if (!this.disposed)
                            {
                                this.LoadTextureFromStream(imageStream);
                                this.IsImageDownloaded = true;
                            }
                        }
                }
                catch (Exception)
                {
                }
            });
        }
Example #19
0
 /// <summary>
 /// Called when message is received.
 /// </summary>
 /// <param name="host">The host endpoint that sent the message.</param>
 /// <param name="receivedMessage">The received message.</param>
 protected virtual void OnMessageReceived(NetworkEndpoint host, IncomingMessage receivedMessage)
 {
     WaveForegroundTask.Run(() => this.MessageReceived?.Invoke(this, new MessageReceivedEventArgs(host, receivedMessage)));
 }
Example #20
0
 /// <summary>
 /// Called when the client lose the connection with the host.
 /// </summary>
 /// <param name="host">The host endpoint.</param>
 protected virtual void OnHostDisconnected(NetworkEndpoint host)
 {
     WaveForegroundTask.Run(() => this.HostDisconnected?.Invoke(this, new HostDisconnectedEventArgs(host)));
 }