예제 #1
0
    protected IEnumerator WaitChange(DoWhat enterFirst, float wait, DoWhat enterEnd)
    {
        behaviour = enterFirst;
        yield return(new WaitForSeconds(wait));

        behaviour = enterEnd;
    }
예제 #2
0
        private async void CompareImage_Tapped(object sender, TappedRoutedEventArgs e)
        {
            BaseImage.IsTapEnabled = false;
            try
            {
                StorageBaseImage = await doWhat.GetImageFromAlbum();

                var stream = await StorageBaseImage.OpenAsync(FileAccessMode.Read);

                var image = new BitmapImage();
                image.SetSource(stream);
                BaseImage.Source = image;
            }
            catch
            {
                DoWhat.ShowNotify("图片获取失败");
            }
            BaseImage.IsTapEnabled = true;
        }
예제 #3
0
        private async void MenuFlyoutItem_Click(object sender, RoutedEventArgs e)
        {
            MenuFlyoutItem menuItem = sender as MenuFlyoutItem;

            switch (menuItem.Tag.ToString())
            {
            case "FromCamera": {
                MainCanvas.Children.Clear();
                StorageFile photo = await doWhat.GetImageFromCamera();

                if (photo != null)
                {
                    var stream = await photo.OpenAsync(FileAccessMode.Read);

                    var image = new BitmapImage();
                    image.SetSource(stream);
                    MainImage.Source = image;
                    size_image       = new Size(image.PixelWidth, image.PixelHeight);

                    //开始请求认知服务
                    LoadingRing.IsActive = true;
                    try
                    {
                        faces = await cognitiveService.GetFaces(photo);

                        emotions = await cognitiveService.GetEmotions(photo);
                    }
                    catch
                    {
                        DoWhat.ShowNotify("获取服务失败,请检查网络状况");
                    }

                    if (faces != null)
                    {
                        DisplayFaces(faces);
                    }
                    if (emotions != null)
                    {
                        DisplayEmotions(emotions);
                    }

                    LoadingRing.IsActive = false;
                }
                break;
            }

            case "FromAlbum": {
                StorageFile file = await doWhat.GetImageFromAlbum();

                if (file != null)
                {
                    var stream = await file.OpenAsync(FileAccessMode.Read);

                    var image = new BitmapImage();
                    image.SetSource(stream);
                    MainImage.Source = image;
                    size_image       = new Size(image.PixelWidth, image.PixelWidth);

                    LoadingRing.IsActive = true;
                    try
                    {
                        faces = await cognitiveService.GetFaces(file);

                        emotions = await cognitiveService.GetEmotions(file);
                    }
                    catch
                    {
                        DoWhat.ShowNotify("获取服务失败,请检查网络状况");
                    }

                    if (faces != null)
                    {
                        DisplayFaces_Me(faces);
                    }
                    if (emotions != null)
                    {
                        DisplayEmotions(emotions);
                    }
                    LoadingRing.IsActive = false;
                }
                break;
            }

            case "FromURL": {
                var content = Clipboard.GetContent();
                if (content != null && content.Contains(StandardDataFormats.Text))
                {
                    var url = await content.GetTextAsync();

                    imageLocation.Text   = url;
                    MainImage.Source     = new BitmapImage(new Uri(imageLocation.Text));
                    LoadingRing.IsActive = true;
                }
                break;
            }

            default:
                break;
            }
        }
        private Object notifyUpdate(SimObject objectUpdated, ObjectMovementUpdate before, ObjectMovementUpdate after, DoWhat didUpdate)
        {
            ObjectMovementUpdate diff  = updateDiff(before, after);
            bool wasChanged            = false;
            bool wasPositionUpdateSent = false;

            if (before.Acceleration != after.Acceleration)
            {
                after.Acceleration =
                    (Vector3)
                    didUpdate(objectUpdated, "Acceleration", before.Acceleration, after.Acceleration, diff.Acceleration);
                wasChanged = true;
            }
            if (before.AngularVelocity != after.AngularVelocity)
            {
                after.AngularVelocity =
                    (Vector3)
                    didUpdate(objectUpdated, "AngularVelocity", before.AngularVelocity, after.AngularVelocity,
                              diff.AngularVelocity);
                wasChanged = true;
            }
            if (false)
            {
                if (before.CollisionPlane != after.CollisionPlane)
                {
                    after.CollisionPlane =
                        (Vector4)
                        didUpdate(objectUpdated, "CollisionPlane", before.CollisionPlane, after.CollisionPlane,
                                  diff.CollisionPlane);
                    wasChanged = true;
                }
            }
            if (before.Position != after.Position)
            {
                after.Position =
                    (Vector3)didUpdate(objectUpdated, "Position", before.Position, after.Position, diff.Position);
                wasChanged            = true;
                wasPositionUpdateSent = true;
            }
            Quaternion diff1 = before.Rotation - after.Rotation;

            if (diff1.Length() > 0.1f)
            {
                after.Rotation =
                    (Quaternion)didUpdate(objectUpdated, "Rotation", before.Rotation, after.Rotation, diff.Rotation);
                wasChanged = true;
            }
            if (false)
            {
                if (before.State != after.State)
                {
                    didUpdate(objectUpdated, "State", before.State, after.State, diff.State);
                    wasChanged = true;
                }
            }
            if (before.Textures != after.Textures)
            {
                //didUpdate(objectUpdated, "Textures", before.Textures, after.Textures, diff.Textures);
                //wasChanged = true;
            }
            if (before.Velocity != after.Velocity)
            {
                // didUpdate(objectUpdated, "Velocity", before.Velocity, after.Velocity, diff.Velocity);
                if (before.Velocity == Vector3.Zero)
                {
                    SendNewUpdateEvent("on-object-start-velocity", objectUpdated, after.Velocity);
                    if (!wasPositionUpdateSent)
                    {
                        SendNewUpdateEvent("on-object-position", objectUpdated, after.Position);
                    }
                }
                else if (after.Velocity == Vector3.Zero)
                {
                    if (!wasPositionUpdateSent)
                    {
                        SendNewUpdateEvent("on-object-position", objectUpdated, after.Position);
                    }
                    SendNewUpdateEvent("on-object-stop-velocity", objectUpdated, -before.Velocity);
                }
                else
                {
                    //SendNewUpdateEvent("on-object-change-velosity", objectUpdated, after.Velocity);
                    if (!wasPositionUpdateSent)
                    {
                        SendNewUpdateEvent("on-object-position", objectUpdated, after.Position);
                    }
                }
                wasChanged = true;
            }
            if (!wasChanged)
            {
                return(null);
            }
            return(diff);
        }
예제 #5
0
 private Object notifyUpdate(SimObject objectUpdated, ObjectMovementUpdate before, ObjectMovementUpdate after, DoWhat didUpdate)
 {
     ObjectMovementUpdate diff = updateDiff(before, after);
     bool wasChanged = false;
     bool wasPositionUpdateSent = false;
     if (before.Acceleration != after.Acceleration)
     {
         after.Acceleration =
             (Vector3)
             didUpdate(objectUpdated, "Acceleration", before.Acceleration, after.Acceleration, diff.Acceleration);
         wasChanged = true;
     }
     if (before.AngularVelocity != after.AngularVelocity)
     {
         after.AngularVelocity =
             (Vector3)
             didUpdate(objectUpdated, "AngularVelocity", before.AngularVelocity, after.AngularVelocity,
                       diff.AngularVelocity);
         wasChanged = true;
     }
     if (false) if (before.CollisionPlane != after.CollisionPlane)
     {
         after.CollisionPlane =
             (Vector4)
             didUpdate(objectUpdated, "CollisionPlane", before.CollisionPlane, after.CollisionPlane,
                       diff.CollisionPlane);
         wasChanged = true;
     }
     if (before.Position != after.Position)
     {
         after.Position =
             (Vector3)didUpdate(objectUpdated, "Position", before.Position, after.Position, diff.Position);
         wasChanged = true;
         wasPositionUpdateSent = true;
     }
     Quaternion diff1 = before.Rotation - after.Rotation;
     if (diff1.Length() > 0.1f)
     {
         after.Rotation =
             (Quaternion)didUpdate(objectUpdated, "Rotation", before.Rotation, after.Rotation, diff.Rotation);
         wasChanged = true;
     }
     if (false) if (before.State != after.State)
     {
         didUpdate(objectUpdated, "State", before.State, after.State, diff.State);
         wasChanged = true;
     }
     if (before.Textures != after.Textures)
     {
         //didUpdate(objectUpdated, "Textures", before.Textures, after.Textures, diff.Textures);
         //wasChanged = true;
     }
     if (before.Velocity != after.Velocity)
     {
         // didUpdate(objectUpdated, "Velocity", before.Velocity, after.Velocity, diff.Velocity);
         if (before.Velocity == Vector3.Zero)
         {
             SendNewUpdateEvent("on-object-start-velocity", objectUpdated, after.Velocity);
             if (!wasPositionUpdateSent) SendNewUpdateEvent("on-object-position", objectUpdated, after.Position);
         }
         else if (after.Velocity == Vector3.Zero)
         {
             if (!wasPositionUpdateSent) SendNewUpdateEvent("on-object-position", objectUpdated, after.Position);
             SendNewUpdateEvent("on-object-stop-velocity", objectUpdated, -before.Velocity);
         }
         else
         {
             //SendNewUpdateEvent("on-object-change-velosity", objectUpdated, after.Velocity);
             if (!wasPositionUpdateSent) SendNewUpdateEvent("on-object-position", objectUpdated, after.Position);
         }
         wasChanged = true;
     }
     if (!wasChanged) return null;
     return diff;
 }