Пример #1
0
        private void SetConstraints(Ellipse ball, PhysicsInfo info)
        {
            Size bounds = _container.RenderSize;

            if (info.X <= 0)
            {
                info.X   = 0;
                info.AX *= -1 * Damping;
            }
            else if (info.X >= bounds.Width - ball.Width)
            {
                info.X   = bounds.Width - ball.Width;
                info.AX *= -1 * Damping;
            }

            if (info.Y <= 0)
            {
                info.Y   = 0;
                info.AY *= -1 * Damping;
            }
            else if (info.Y >= bounds.Height - ball.Height)
            {
                info.Y   = bounds.Height - ball.Height;
                info.AY *= -1 * Damping;
            }
        }
Пример #2
0
 private void Randomize(object sender, RoutedEventArgs e)
 {
     for (int i = 0; i < TotalBalls; i++)
     {
         PhysicsInfo info = InitPhysicsForBall();
         (_container.Children[i] as Ellipse).Tag = info;
     }
 }
Пример #3
0
        private void UpdateBall(PhysicsInfo info)
        {
            info.AX *= Resistance;
            info.AY += Gravity;
            info.AY *= Resistance;

            info.X += info.AX;
            info.Y += info.AY;
        }
Пример #4
0
        private void CreateBalls()
        {
            for (int i = 0; i < TotalBalls; i++)
            {
                Ellipse e = new Ellipse();
                e.Width  = 20;
                e.Height = 20;
                _container.Children.Add(e);

                PhysicsInfo info = InitPhysicsForBall();
                e.Tag = info;
            }
        }
Пример #5
0
        void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            for (int i = 0; i < TotalBalls; i++)
            {
                Ellipse ball = _container.Children[i] as Ellipse;

                PhysicsInfo info = ball.Tag as PhysicsInfo;
                UpdateBall(info);
                SetConstraints(ball, info);

                ball.SetValue(Canvas.LeftProperty, info.X);
                ball.SetValue(Canvas.TopProperty, info.Y);
            }
        }