Пример #1
0
 private void btnStop_Click(object sender, RoutedEventArgs e)
 {
     foreach (BallBlip blip in _map.GetAllBlips())
     {
         blip.Ball.StopBall();
     }
 }
Пример #2
0
 private void btnStopVelocity_Click(object sender, EventArgs e)
 {
     foreach (RadarBlip blip in _map.GetAllBlips())
     {
         if (blip.Sphere is Ball)
         {
             ((Ball)blip.Sphere).StopBall();
         }
     }
 }
Пример #3
0
        private void btnRemove_Click(object sender, EventArgs e)
        {
            if (_map.Count == 0)
            {
                MessageBox.Show("No blips to remove", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            RadarBlip[] blips = _map.GetAllBlips();

            if (_ship != null && blips.Length == 1)
            {
                // The only one left is the ship
                return;
            }

            do
            {
                // Pick a random ball
                int removeIndex = _rand.Next(blips.Length);

                // Make sure it's not the ship
                if (_ship != null && blips[removeIndex].Token == _ship.Token)
                {
                    continue;
                }

                // This one isn't the ship.  Remove it
                _map.Remove(blips[removeIndex].Token);
                return;
            } while (true);
        }
Пример #4
0
        /// <summary>
        /// This will help me adjust the velocity of any objects that are being physically dragged around
        /// </summary>
        public void TimerTick(double elapsedTime)
        {
            if (!(_isMouseDown == MouseButtonDown.Left && _mode == SelectionMode.Selected))
            {
                // They aren't actively dragging objects around.  There is nothing for this function to do.
                return;
            }

            // Figure out what their velocity should be
            MyVector newVelocity = TimerSprtCalculateVelocity();

            // Physics may have knocked the objects around.  Put them all where they are supposed to be
            foreach (RadarBlip blip in _map.GetAllBlips())
            {
                if (_selectedObjects.Contains(blip.Token))
                {
                    // Enforce the new position
                    blip.Sphere.Position.StoreNewValues(_curMousePoint + _draggingPositionOffsets[blip.Token]);

                    // Give them all the same velocity
                    if (blip.Sphere is Ball)
                    {
                        ((Ball)(blip.Sphere)).Velocity.StoreNewValues(newVelocity);
                    }
                }
            }
        }
Пример #5
0
        private void DoGravityDown()
        {
            const double ACCELDOWN = .1d;

            MyVector accel = new MyVector(0, ACCELDOWN * _gravityMultiplier, 0);

            foreach (BallBlip blip in _map.GetAllBlips())
            {
                if (blip.CollisionStyle != CollisionStyle.Standard)
                {
                    continue;
                }

                blip.Ball.Acceleration.Add(accel);       // I do acceleration instead of force so they all fall at the same rate
            }
        }
Пример #6
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (_map == null)
            {
                MessageBox.Show("Control hasn't been set up yet", "Save Scene", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            List <RadarBlip> clonedBlips = new List <RadarBlip>();

            // Clone them as fast as I can
            foreach (RadarBlip blip in _map.GetAllBlips())
            {
                if (_ignoreTokens.Contains(blip.Token))
                {
                    continue;
                }

                //TODO:  Clone this right (instead of hardcoding ballblip)
                clonedBlips.Add(CloneBlip(blip, _map));
            }

            // Store it
            _sceneBlips.Add(clonedBlips.ToArray());

            listView1.Items.Add("Scene " + ((int)(listView1.Items.Count + 1)).ToString());
            listView1.Items[listView1.Items.Count - 1].Selected = true;

            // Draw the scene
            DrawScene(clonedBlips.ToArray());
        }
Пример #7
0
        private List <BallBlip> FindBlipsInCone(MyVector centerWorld, MyVector dirFacingWorld)
        {
            List <BallBlip> retVal = new List <BallBlip>();

            // Cache some stuff for use inside the loop
            double halfSweepAngle = _sweepAngle / 2d;
            double maxDistSquared = _maxDistance * _maxDistance;

            // Scan for objects in my path
            foreach (RadarBlip blip in _map.GetAllBlips())
            {
                if (blip.Token == _ship.Token)
                {
                    // Can't manipulate me
                    continue;
                }

                if (blip.CollisionStyle == CollisionStyle.Ghost)
                {
                    // Ghost blips don't interact with anything
                    continue;
                }

                if (!(blip is BallBlip))
                {
                    // The blip needs to be at least a ball
                    continue;
                }

                MyVector lineBetween = blip.Sphere.Position - centerWorld;
                if (lineBetween.GetMagnitudeSquared() > maxDistSquared)
                {
                    // The object is too far away
                    continue;
                }

                MyVector rotationAxis;
                double   rotationRadians;
                dirFacingWorld.GetAngleAroundAxis(out rotationAxis, out rotationRadians, lineBetween);
                if (rotationRadians > halfSweepAngle)
                {
                    // The sweep angle is too great (not inside the cone)
                    continue;
                }

                // It's inside the cone
                retVal.Add(blip as BallBlip);
            }

            // Exit Function
            return(retVal);
        }
Пример #8
0
        private bool WillCollide(Ball ball)
        {
            // Make a temp blip to be a wrapper for this
            RadarBlip blip = new RadarBlip(ball, CollisionStyle.Standard, RadarBlipQual.BallUserDefined10, TokenGenerator.NextToken());

            foreach (RadarBlip existingBlip in _map.GetAllBlips())
            {
                if (_map.CollisionHandler.IsColliding(blip, existingBlip) != CollisionDepth.NotColliding)
                {
                    // It's colliding
                    return(true);
                }
            }

            return(false);
        }
Пример #9
0
        public void Timer()
        {
            if (!(_active && _cursorInMap))
            {
                return;
            }

            _accelLines.Clear();
            _accelColors.Clear();

            Ball   ball;
            double force;

            foreach (RadarBlip blip in _map.GetAllBlips())
            {
                #region Check for exempt blips

                if (blip.Token == _cursorBlip.Token)
                {
                    continue;
                }

                if (blip.CollisionStyle != CollisionStyle.Standard)
                {
                    continue;
                }

                if (!(blip is BallBlip))
                {
                    continue;
                }

                #endregion

                #region Pull Apart

                if (_map.CollisionHandler.IsColliding(blip, _cursorBlip) == CollisionDepth.Penetrating)
                {
                    _map.CollisionHandler.PullItemsApartInstant(blip, _cursorBlip);
                }

                #endregion

                ball = ((BallBlip)blip).Ball;

                #region Calculate Force

                // Apply Force (ball to mouse)
                MyVector ballToMouse = _curMousePoint - ball.Position;

                double distanceSquared = ballToMouse.GetMagnitudeSquared();

                // Force = G * (M1*M2) / R^2
                force = GRAVITATIONALCONSTANT * (ball.Mass / distanceSquared);

                if (_isMouseDown == MouseButtonDown.Left)
                {
                    force *= 10d;
                }
                else if (_isMouseDown == MouseButtonDown.Right)
                {
                    force *= -2d;
                }

                ballToMouse.BecomeUnitVector();
                ballToMouse.Multiply(force);

                ball.ExternalForce.Add(ballToMouse);

                #endregion

                #region Store Accel Line

                double acceleration = force / ball.Mass;
                double absAccel     = Math.Abs(acceleration);

                if (absAccel > .05d)            // otherwise, it's too faint to see anyway
                {
                    _accelLines.Add(ball);

                    int alpha = Convert.ToInt32((absAccel - .05d) * (255d / .95d));
                    if (alpha < 0)
                    {
                        alpha = 0;
                    }
                    if (alpha > 255)
                    {
                        alpha = 255;
                    }

                    if (acceleration > 0d)
                    {
                        _accelColors.Add(Color.FromArgb(alpha, _attractColor));
                    }
                    else
                    {
                        _accelColors.Add(Color.FromArgb(alpha, _repelColor));
                    }
                }

                #endregion
            }
        }