Inheritance: System.Windows.Media.Media3D.ModelVisual3D
        private GradientBall InitGradientBall(string imageSrc, double offsetx, double offsety)
        {
            var p3D  = new Point3D(offsetx, offsety, -8);
            var ball = new GradientBall {
                ImageSource = imageSrc, Offset = p3D
            };

            visualModel.Children.Add(ball);
            return(ball);
        }
 private void RestoreBalls()
 {
     if (_movingBall != null)
     {
         GradientBall tempball = _movingBall;
         _movingBall = null;
         Do3DAnimation(tempball, _animatingBallOriginalPosition);
     }
     if (_centerscreenBall != null)
     {
         GradientBall tempball = _centerscreenBall;
         _centerscreenBall = null;
         Do3DAnimation(tempball, _animatingBallOriginalPosition);
     }
 }
        private void Do3DAnimation(GradientBall ball, Point3D nextPosition)
        {
            Action animation = () =>
            {
                var     speed           = new Duration(new TimeSpan(0, 0, 3));
                Point3D currentPosition = ball.Offset;

                var animationX = new DoubleAnimation(currentPosition.X, nextPosition.X, speed);
                var animationY = new DoubleAnimation(currentPosition.Y, nextPosition.Y, speed);
                var animationZ = new DoubleAnimation(currentPosition.Z, nextPosition.Z, speed);

                var tt3D = new TranslateTransform3D(currentPosition.X, currentPosition.Y, currentPosition.Z);
                ball.Transform = tt3D;
                tt3D.BeginAnimation(TranslateTransform3D.OffsetXProperty, animationX);
                tt3D.BeginAnimation(TranslateTransform3D.OffsetYProperty, animationY);
                tt3D.BeginAnimation(TranslateTransform3D.OffsetZProperty, animationZ);
            };

            ball.Dispatcher.BeginInvoke(DispatcherPriority.Send, animation);
        }
        private void Move(Point position)
        {
            try
            {
                var pos = position;
                //pos = Mouse.GetPosition(viewPort);

                //update hand
                Action setHand = () =>
                {
                    Canvas.SetTop(HandImage, pos.Y);
                    Canvas.SetLeft(HandImage, pos.X);
                };
                HandImage.Dispatcher.BeginInvoke(DispatcherPriority.Send, setHand);

                _mouse3DPosition.X = ((_viewPortSize.X / (viewPort.ActualWidth / pos.X)) - (_viewPortSize.X / 2)) * -1;
                _mouse3DPosition.Y = ((_viewPortSize.Y / (viewPort.ActualHeight / pos.Y)) - (_viewPortSize.Y / 2)) * -1;

                if (_movingBall == null && _centerscreenBall == null)
                {
                    //Er is geen bal geanimeerd. We kunnen een nieuwe ball zoeken
                    int index = MouseOnBall();
                    if (index != -1)
                    {
                        GradientBall tempBall        = _balls[index];
                        Action       getBallPosition = delegate { _animatingBallOriginalPosition = tempBall.Offset; };
                        tempBall.Dispatcher.BeginInvoke(DispatcherPriority.Send, getBallPosition);
                        _movingBallIndex = index;
                        _movingBall      = tempBall;
                    }
                }
                else if (_movingBall != null)
                {
                    Action moveBall = () =>
                    {
                        if (_movingBall != null)
                        {
                            var tt3D = new TranslateTransform3D(_mouse3DPosition.X, _mouse3DPosition.Y, -10);
                            if (_movingBall != null)
                            {
                                _movingBall.Transform = tt3D;
                            }
                        }
                    };

                    _movingBall.Dispatcher.BeginInvoke(DispatcherPriority.Send, moveBall);

                    //movingBall.Transform = tt3d;
                    if (WithinMargin(_mouse3DPosition.X, 0, Sensitivity))
                    // && WithinMargin(mouse3dPosition.Y, 0, sensitivity * 2))
                    {
                        if (_movingBallIndex != -1)
                        {
                            int    index = _movingBallIndex;
                            Action del3  = () =>
                            {
                                lblNaam.Content    = _names[index];
                                lblNaam.Visibility = Visibility.Visible;
                            };
                            Action del4 = () =>
                            {
                                lblWorkshop.Text       = _workshops[index];
                                lblWorkshop.Visibility = Visibility.Visible;
                            };
                            lblNaam.Dispatcher.BeginInvoke(DispatcherPriority.Send, del3);
                            lblWorkshop.Dispatcher.BeginInvoke(DispatcherPriority.Send, del4);
                        }
                        //The ball is on the center of the screen. Please make it bigger
                        _centerscreenBall = _movingBall;
                        _movingBall       = null;
                        _movingBallIndex  = -1;
                        Do3DAnimation(_centerscreenBall, _centerScreen);
                    }
                }
            }
            catch
            {
                //do nothing
            }
        }
示例#5
0
 private void RestoreBalls()
 {
     if (_movingBall != null)
     {
         GradientBall tempball = _movingBall;
         _movingBall = null;
         Do3DAnimation(tempball, _animatingBallOriginalPosition);
     }
     if (_centerscreenBall != null)
     {
         GradientBall tempball = _centerscreenBall;
         _centerscreenBall = null;
         Do3DAnimation(tempball, _animatingBallOriginalPosition);
     }
 }
示例#6
0
        private void Move(Point position)
        {
            try
            {
                var pos = position;
                //pos = Mouse.GetPosition(viewPort);

                //update hand
                Action setHand = () =>
                {
                    Canvas.SetTop(HandImage, pos.Y);
                    Canvas.SetLeft(HandImage, pos.X);
                };
                HandImage.Dispatcher.BeginInvoke(DispatcherPriority.Send, setHand);

                _mouse3DPosition.X = ((_viewPortSize.X / (viewPort.ActualWidth / pos.X)) - (_viewPortSize.X / 2)) * -1;
                _mouse3DPosition.Y = ((_viewPortSize.Y / (viewPort.ActualHeight / pos.Y)) - (_viewPortSize.Y / 2)) * -1;

                if (_movingBall == null && _centerscreenBall == null)
                {
                    //Er is geen bal geanimeerd. We kunnen een nieuwe ball zoeken
                    int index = MouseOnBall();
                    if (index != -1)
                    {
                        GradientBall tempBall = _balls[index];
                        Action getBallPosition = delegate { _animatingBallOriginalPosition = tempBall.Offset; };
                        tempBall.Dispatcher.BeginInvoke(DispatcherPriority.Send, getBallPosition);
                        _movingBallIndex = index;
                        _movingBall = tempBall;
                    }
                }
                else if (_movingBall != null)
                {
                    Action moveBall = () =>
                    {
                        if (_movingBall != null)
                        {
                            var tt3D = new TranslateTransform3D(_mouse3DPosition.X, _mouse3DPosition.Y, -10);
                            if (_movingBall != null)
                                _movingBall.Transform = tt3D;
                        }
                    };

                    _movingBall.Dispatcher.BeginInvoke(DispatcherPriority.Send, moveBall);

                    //movingBall.Transform = tt3d;
                    if (WithinMargin(_mouse3DPosition.X, 0, Sensitivity))
                    // && WithinMargin(mouse3dPosition.Y, 0, sensitivity * 2))
                    {
                        if (_movingBallIndex != -1)
                        {
                            int index = _movingBallIndex;
                            Action del3 = () =>
                            {
                                lblNaam.Content = _names[index];
                                lblNaam.Visibility = Visibility.Visible;
                            };
                            Action del4 = () =>
                            {
                                lblWorkshop.Text = _workshops[index];
                                lblWorkshop.Visibility = Visibility.Visible;
                            };
                            lblNaam.Dispatcher.BeginInvoke(DispatcherPriority.Send, del3);
                            lblWorkshop.Dispatcher.BeginInvoke(DispatcherPriority.Send, del4);
                        }
                        //The ball is on the center of the screen. Please make it bigger
                        _centerscreenBall = _movingBall;
                        _movingBall = null;
                        _movingBallIndex = -1;
                        Do3DAnimation(_centerscreenBall, _centerScreen);
                    }
                }
            }
            catch
            {
                //do nothing
            }
        }
示例#7
0
        private void Do3DAnimation(GradientBall ball, Point3D nextPosition)
        {
            Action animation = () =>
            {
                var speed = new Duration(new TimeSpan(0, 0, 3));
                Point3D currentPosition = ball.Offset;

                var animationX = new DoubleAnimation(currentPosition.X, nextPosition.X, speed);
                var animationY = new DoubleAnimation(currentPosition.Y, nextPosition.Y, speed);
                var animationZ = new DoubleAnimation(currentPosition.Z, nextPosition.Z, speed);

                var tt3D = new TranslateTransform3D(currentPosition.X, currentPosition.Y, currentPosition.Z);
                ball.Transform = tt3D;
                tt3D.BeginAnimation(TranslateTransform3D.OffsetXProperty, animationX);
                tt3D.BeginAnimation(TranslateTransform3D.OffsetYProperty, animationY);
                tt3D.BeginAnimation(TranslateTransform3D.OffsetZProperty, animationZ);
            };
            ball.Dispatcher.BeginInvoke(DispatcherPriority.Send, animation);
        }
示例#8
0
        private GradientBall InitGradientBall(string imageSrc, double offsetx, double offsety)
        {
            var p3D = new Point3D(offsetx, offsety, -8);
            var ball = new GradientBall { ImageSource = imageSrc, Offset = p3D };

            visualModel.Children.Add(ball);
            return ball;
        }