Пример #1
0
        /// <summary>
        /// Animates the camera view matrix after user screen drag completed
        /// </summary>
        private void AnimateCameraAfterFreeDrag()
        {
            _onDragEndAnimation = true;
            XNAMatrixAnimation camAnim = new XNAMatrixAnimation(_cameraMatrix, _cameraMatrixBehindDrag, TimeSpan.FromSeconds(0.5), 30);

            camAnim.OnAnimating += (XNAMatrixAnimation sender, XNAMatrixAnimationEventArgs e) =>
            {
                _cameraMatrix = e.Value;
            };
            camAnim.OnCompleted += (XNAMatrixAnimation sender, XNAMatrixAnimationEventArgs e) =>
            {
                _cameraMatrix       = e.Value;
                _onDragEndAnimation = false;
                _gestureState       = GestureStateEnum.OnMotion;
            };
            camAnim.Start();
        }
Пример #2
0
        private void HandleGesture()
        {
            while (TouchPanel.IsGestureAvailable)
            {
                GestureSample gestureSample = TouchPanel.ReadGesture();
                switch (gestureSample.GestureType)
                {
                case GestureType.FreeDrag:
                    _gestureTimer.Stop();
                    _gestureState = GestureStateEnum.OnFreeDrag;

                    float rotateRate    = 0.01f;
                    float translateRate = 0.1f;
                    _cameraMatrix = _cameraMatrix * Matrix.CreateRotationY(-gestureSample.Delta.X * rotateRate);
                    _cameraMatrix = _cameraMatrix * Matrix.CreateTranslation(0f, -gestureSample.Delta.Y * translateRate, 0f);

                    //rotate radar
                    Dispatcher.BeginInvoke(delegate()
                    {
                        (radarCanvas.RenderTransform as System.Windows.Media.RotateTransform).Angle += MathHelper.ToDegrees((gestureSample.Delta.X * rotateRate));
                    });

                    break;

                case GestureType.DragComplete:
                    _gestureTime = 0;
                    _gestureTimer.Start();

                    break;

                case GestureType.Tap:
                    _gestureState = GestureStateEnum.OnMotion;

                    if (myVM.ClickedNearbyLocation != null)
                    {
                        AnimateLocationDeselection(myVM.ClickedNearbyLocation);
                        myVM.ClickedNearbyLocation.IsClickedOnView = false;
                        if (OnLocationReleased != null)
                        {
                            OnLocationReleased(this, myVM.ClickedNearbyLocation);
                        }
                    }

                    if (_gestureState != GestureStateEnum.OnPressHold)
                    {
                        _gestureState = GestureStateEnum.OnPressHold;

                        float   mouseX     = gestureSample.Position.X;
                        float   mouseY     = gestureSample.Position.Y;
                        Vector3 nearsource = new Vector3((float)mouseX, (float)mouseY, 0f);
                        Vector3 farsource  = new Vector3((float)mouseX, (float)mouseY, -1f);

                        Vector3 nearPoint = _device.Viewport.Unproject(nearsource, _projectionMatrix, _cameraMatrix, _phoneWorld);
                        Vector3 farPoint  = _device.Viewport.Unproject(farsource, _projectionMatrix, _cameraMatrix, _phoneWorld);

                        Vector3 direction = -farPoint + nearPoint;
                        direction.Normalize();
                        Ray pickRay = new Ray(nearPoint, direction);

                        if (myVM.ClickedNearbyLocation != null)
                        {
                            AnimateLocationDeselection(myVM.ClickedNearbyLocation);
                            myVM.ClickedNearbyLocation.IsClickedOnView = false;
                            if (OnLocationReleased != null)
                            {
                                OnLocationReleased(this, myVM.ClickedNearbyLocation);
                            }
                        }

                        foreach (LocationsVM.Location l in myVM.SelectedNearbyLocations)
                        {
                            float?result = pickRay.Intersects(l.PlacemarkBoundingSphere);
                            if (result.HasValue)
                            {
                                AnimateLocationSelection(l);
                                l.IsClickedOnView = true;
                                if (OnLocationSelected != null)
                                {
                                    OnLocationSelected(this, l);
                                }

                                break;
                            }
                        }
                    }

                    break;
                }
            }
        }