示例#1
0
        public void votingInitiated(IdeaBall b)
        {
            if (!votingMode)
            {
                disableNonFocusedBalls(b);
                cancelBall.fill.Color       = b.fill.Color;
                cancelBall.selectedBall     = b;
                cancelBall.ballClicked      = true;
                cancelBall.Title.Visibility = Visibility.Visible;
                Canvas.SetZIndex(cancelBall.Ellipse, this._mainCanvas.Children.Count - 3);
                yesBall.fill.Color       = Color.FromArgb(123, yesBall.fill.Color.R, yesBall.fill.Color.G, yesBall.fill.Color.B);
                yesBall.selectedBall     = b;
                yesBall.ballClicked      = true;
                yesBall.Title.Visibility = Visibility.Visible;
                Canvas.SetZIndex(yesBall.Ellipse, this._mainCanvas.Children.Count - 2);
                noBall.fill.Color       = Color.FromArgb(123, noBall.fill.Color.R, noBall.fill.Color.G, noBall.fill.Color.B);
                noBall.selectedBall     = b;
                noBall.ballClicked      = true;
                noBall.Title.Visibility = Visibility.Visible;
                Canvas.SetZIndex(noBall.Ellipse, this._mainCanvas.Children.Count - 1);
                ballInfoText.grid.Visibility = Visibility.Visible;
                Canvas.SetZIndex(ballInfoText.textBlock, this._mainCanvas.Children.Count);

                this.votingMode = true;
            }
        }
示例#2
0
 public static bool Intersects(IdeaBall a, IdeaBall b)
 {
     return(a.Position.X + a.Radius + b.Radius > b.Position.X &&
            a.Position.X < b.Position.X + a.Radius + b.Radius &&
            a.Position.Y + a.Radius + b.Radius > b.Position.Y &&
            a.Position.Y < b.Position.Y + a.Radius + b.Radius);
 }
示例#3
0
        private double gravDist(IdeaBall a, IdeaBall b)
        {
            double dX      = a.Position.X - b.Position.X;
            double dY      = a.Position.Y - b.Position.Y;
            double distSqr = (dX * dX) + (dY * dY);

            return(distSqr);
        }
示例#4
0
 public void enableNonFocusedBalls(IdeaBall b)
 {
     foreach (IdeaBall ball in allBalls)
     {
         if (ball != b)
         {
             int x = ball.fill.Color.A * 10;
             ball.fill.Color = Color.FromArgb((byte)x, ball.fill.Color.R, ball.fill.Color.G, ball.fill.Color.B);
             ball.runHandler = true;
         }
     }
 }
示例#5
0
 public void disableNonFocusedBalls(IdeaBall b)
 {
     foreach (IdeaBall ball in allBalls)
     {
         if (!ball.Equals(b))
         {
             int x = ball.fill.Color.A / 10;
             ball.fill.Color = Color.FromArgb((byte)x, ball.fill.Color.R, ball.fill.Color.G, ball.fill.Color.B);
             ball.runHandler = false;
         }
     }
 }
示例#6
0
        internal void AddBall(string text)
        {
            addButtonBall.Clicked = false;
            enableNonFocusedBalls(addButtonBall);
            Debug.WriteLine("Add Ball");
            IdeaBall ideaBall = new IdeaBall(new Vector(random.Next(151, 800), random.Next(0, 600)), new Vector(0, 0), this._mainCanvas, 6 * 10, Color.FromArgb((byte)random.Next(55, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255), (byte)random.Next(0, 255)), this, text);

            safeZoneX += 10;
            safeZoneY += 10;
            ideaBalls.Add(ideaBall);
            ideaBall.AttachTo(this._mainCanvas);
            allBalls.Add(ideaBall);
        }
示例#7
0
 public void voteGotCancelled(IdeaBall b)
 {
     enableNonFocusedBalls(b);
     cancelBall.fill.Color        = Color.FromArgb(0, cancelBall.fill.Color.R, cancelBall.fill.Color.G, cancelBall.fill.Color.B);
     cancelBall.Title.Visibility  = Visibility.Hidden;
     cancelBall.ballClicked       = false;
     yesBall.fill.Color           = Color.FromArgb(0, yesBall.fill.Color.R, yesBall.fill.Color.G, yesBall.fill.Color.B);
     yesBall.Title.Visibility     = Visibility.Hidden;
     yesBall.ballClicked          = false;
     noBall.fill.Color            = Color.FromArgb(0, noBall.fill.Color.R, noBall.fill.Color.G, noBall.fill.Color.B);
     noBall.Title.Visibility      = Visibility.Hidden;
     noBall.ballClicked           = false;
     ballInfoText.grid.Visibility = Visibility.Hidden;
     this.votingMode = false;
 }
示例#8
0
        private static bool inGravityRange(IdeaBall a, IdeaBall b)
        {
            double dX = a.Position.X - b.Position.X;
            double dY = a.Position.Y - b.Position.Y;

            double gravRadius = a.Radius * 2 + b.Radius;
            double sqrRadius  = gravRadius * gravRadius;

            double distSqr = (dX * dX) + (dY * dY);

            if (distSqr <= sqrRadius)
            {
                return(true);
            }

            return(false);
        }
示例#9
0
        private static bool Collides(IdeaBall a, IdeaBall b)
        {
            double dX = a.Position.X - b.Position.X;
            double dY = a.Position.Y - b.Position.Y;

            double sumRadius = a.Radius + b.Radius;
            double sqrRadius = sumRadius * sumRadius;

            double distSqr = (dX * dX) + (dY * dY);

            if (distSqr <= sqrRadius)
            {
                return(true);
            }

            return(false);
        }
示例#10
0
        private Vector calcGravity(double vX, double vY, Point attractor, double G, IdeaBall b)
        {
            double dY = vY - attractor.Y;
            double dX = vX - attractor.X;


            Vector newGravVelocity = new Vector();



            if (gravityEnabled)
            {
                double angleInDegrees = Math.Atan2(dY, dX) * 180 / Math.PI;

                //b.Text = System.Convert.ToString("Cos = " + Math.Cos(angleInDegrees) + "Sin = " + Math.Sin(angleInDegrees));

                if (Math.Abs(dY) < 3 && dX < 0)
                {
                    newGravVelocity.X = G;
                }
                else if (Math.Abs(dY) < 3 && dX > 0)
                {
                    newGravVelocity.X = -G;
                }
                else if (Math.Abs(dX) < 3 && dY > 0)
                {
                    newGravVelocity.Y = -G;
                }
                else if (Math.Abs(dX) < 3 && dY > 0)
                {
                    newGravVelocity.Y = -G;
                }
                else
                {
                    if (attractor != centerOfGravity)
                    {
                        if (Math.Abs(dY) < (b.Radius + 30) && Math.Abs(dX) < (b.Radius + 30))
                        {
                            newGravVelocity.X = G * (Math.Cos(angleInDegrees)) * 0.1;
                            newGravVelocity.Y = G * (Math.Sin(angleInDegrees)) * 0.1;
                        }
                        else
                        {
                            newGravVelocity.X = G * (Math.Cos(angleInDegrees));
                            newGravVelocity.Y = G * (Math.Sin(angleInDegrees));
                        }
                    }
                    else
                    {
                        if (Math.Abs(dY) < safeZoneY && Math.Abs(dX) < safeZoneX)
                        {
                            newGravVelocity.X = G * (Math.Cos(angleInDegrees)) * 0.1;
                            newGravVelocity.Y = G * (Math.Sin(angleInDegrees)) * 0.1;
                        }
                        else
                        {
                            newGravVelocity.X = G * (Math.Cos(angleInDegrees));
                            newGravVelocity.Y = G * (Math.Sin(angleInDegrees));
                        }
                    }
                }
            }

            return(newGravVelocity);
        }
示例#11
0
 public void removeGravityPoints(IdeaBall b)
 {
     gravityWells.Remove(b);
 }
示例#12
0
 public void addGravityPoints(IdeaBall b)
 {
     this.gravityWells.Add(b);
 }
示例#13
0
        //protected virtual void Canvas_TapGestureEvent(object sender, RoutedEventArgs e)
        //{
        //    if(addButtonBall.Clicked){
        //        SurfaceWindow1.messageHub.Publish(new DismissTextboxEvent());
        //        addButtonBall.Clicked = false;
        //    }
        //}

        void BackgroundUpdate(object sender, ElapsedEventArgs e)
        {
            int currentTime = stopWatch.Elapsed.Milliseconds;

            deltaTime = lastTime - currentTime;

            lastTime = currentTime;
            Random randomGenerator = new Random();


            foreach (IdeaBall ball in allBalls)
            {
                if (!ball.IsTouched)
                {
                    ball.Velocity *= 0.99;
                    if (Math.Abs(ball.Velocity.X) < 0.00001) //TODO threashold
                    {
                        ball.Velocity = new Vector(0, ball.Velocity.Y);
                    }
                    if (Math.Abs(ball.Velocity.Y) < 0.00001)
                    {
                        ball.Velocity = new Vector(ball.Velocity.Y, 0);
                    }

                    ball.Position += ball.Velocity;
                    if (rotationDampening <= 1)
                    {
                        centerOfRotation  = RotatePoint(centerOfRotation, centerOfGravity, 1);
                        rotationDampening = 15;
                    }
                    else
                    {
                        rotationDampening--;
                    }


                    ball.Velocity = ball.Velocity * 0.95;
                    if (!ball.IsTouched && ball.affectedByGravity)
                    {
                        IdeaBall cloxest = null;

                        foreach (IdeaBall ib in gravityWells)
                        {
                            if (inGravityRange(ib, ball))
                            {
                                if (cloxest != null)
                                {
                                    if ((gravDist(ib, ball) < gravDist(cloxest, ball)))
                                    {
                                        cloxest = ib;
                                    }
                                }
                                else
                                {
                                    cloxest = ib;
                                }
                            }
                        }



                        if (cloxest != null)
                        {
                            ball.Velocity = ball.Velocity + calcGravity(ball.Position.X, ball.Position.Y, (Point)cloxest.Position, gravity, cloxest);
                        }
                        else
                        {
                            ball.Velocity = ball.Velocity + calcGravity(ball.Position.X, ball.Position.Y, centerOfGravity, gravity, null);
                        }
                    }
                    if (ball.Position.X >= _viewportWidthMax - ball.Radius && ball.Velocity.X > 0)
                    {
                        ball.Velocity = new Vector(-ball.Velocity.X, ball.Velocity.Y);
                    }
                    if (ball.Position.X <= _viewportWidthMin + ball.Radius && ball.Velocity.X < 0)
                    {
                        ball.Velocity = new Vector(-ball.Velocity.X, ball.Velocity.Y);
                    }
                    if (ball.Position.Y >= _viewportHeightMax - ball.Radius && ball.Velocity.Y > 0)
                    {
                        ball.Velocity = new Vector(ball.Velocity.X, -ball.Velocity.Y);
                    }
                    if (ball.Position.Y <= _viewportHeightMin + ball.Radius && ball.Velocity.Y < 0)
                    {
                        ball.Velocity = new Vector(ball.Velocity.X, -ball.Velocity.Y);
                    }
                    if (!ball.affectedByGravity && !ball.IsTouched)
                    {
                        ball.Position = ball.gravPosition;
                    }
                }
            }
            foreach (IdeaBall ball in allBalls)
            {
                ball.DetectCollisions(allBalls);
                if (this.votingMode)
                {
                    if (ball.runHandler)
                    {
                        yesBall.position.X      = ball.Position.X + ball.Radius + 55;
                        yesBall.position.Y      = ball.Position.Y;
                        noBall.position.X       = ball.Position.X - ball.Radius - 55;
                        noBall.position.Y       = ball.Position.Y;
                        cancelBall.position.X   = ball.Position.X;
                        cancelBall.position.Y   = ball.Position.Y - ball.Radius - 35;
                        ballInfoText.position.X = ball.Position.X;
                        ballInfoText.position.Y = ball.Position.Y + ball.Radius + 75;
                    }
                }
            }
        }
示例#14
0
        public void ResolveCollision(IdeaBall a, IdeaBall b)
        {
            // get the mtd
            //Vector deltaPosition = new Vector(a.Position.X - b.Position.X, a.Position.Y - b.Position.Y-0.00001);


            Vector deltaPosition = a.Position - b.Position;

            double deltaLength = deltaPosition.Length;

            if ((a.Radius + b.Radius) - deltaLength == 0)
            {
                return;
            }
            // minimum translation distance to push balls apart after intersecting
            Vector mtd = deltaPosition * (((a.Radius + b.Radius) - deltaLength) / deltaLength);



            // resolve intersection --
            // inverse mass quantities
            double im1 = 1.0 / a.Radius;
            double im2 = 1.0 / b.Radius;

            // push-pull them apart based off their mass
            if (a.affectedByGravity)
            {
                a.Position = a.Position + (mtd * (im1 / (im1 + im2))) + adjustment;
            }
            if (b.affectedByGravity)
            {
                b.Position = b.Position - (mtd * (im2 / (im1 + im2))) - adjustment;
            }



            // impact speed
            Vector v             = a.Velocity - b.Velocity;
            Vector mtdNormalized = new Vector(mtd.X, mtd.Y);

            mtdNormalized.Normalize();
            double vn = v * mtdNormalized;

            // sphere intersecting but moving away from each other already
            if (vn > 0.0f)
            {
                return;
            }

            // collision impulse
            if (vn >= -28.0f)
            {
                return;
            }

            double i       = (-(1.0 + Restitution) * vn) / (im1 + im2);
            Vector impulse = mtdNormalized * (i);

            Vector aNewVelocity = a.Velocity + (impulse * (im1));
            Vector bNewVelocity = b.Velocity - (impulse * (im2));

            // change in momentum
            a.Velocity = aNewVelocity * 0.3;
            b.Velocity = bNewVelocity * 0.3;
        }