Ejemplo n.º 1
0
        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (e.ClickedItem == displayItem1)
            {
                // Do nothing
            }
            else if (e.ClickedItem == btnNormalize)
            {
                #region Normalize

                if (_vector.IsZero)
                {
                    MessageBox.Show("The vector is zero length.  It can't be normalized.", "Context Menu Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    StoreNewValue(MyVector.BecomeUnitVector(_vector));
                }

                #endregion
            }
            else if (e.ClickedItem == btnMaximize)
            {
                #region Maximize

                if (_vector.IsZero)
                {
                    MessageBox.Show("The vector is zero length.  It can't be maximized.", "Context Menu Click", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    MyVector newVect = MyVector.BecomeUnitVector(_vector);
                    newVect.Multiply(_multiplier);

                    StoreNewValue(newVect);
                }

                #endregion
            }
            else if (e.ClickedItem == btnRandom)
            {
                StoreNewValue(Utility3D.GetRandomVectorSpherical2D(_multiplier * SAFEPERCENT));         // go under just to be safe
            }
            else if (e.ClickedItem == btnNegate)
            {
                StoreNewValue(_vector.X * -1d, _vector.Y * -1d, _vector.Z * -1d);
            }
            else if (e.ClickedItem == btnZero)
            {
                StoreNewValue(0, 0, 0);
            }
            else if (e.ClickedItem == btnZeroX)
            {
                StoreNewValue(0, _vector.Y, _vector.Z);
            }
            else if (e.ClickedItem == btnZeroY)
            {
                StoreNewValue(_vector.X, 0, _vector.Z);
            }
            else if (e.ClickedItem == btnZeroZ)
            {
                StoreNewValue(_vector.X, _vector.Y, 0);
            }
            else if (e.ClickedItem == btnShowToolTip)
            {
                this.ShowToolTip = !btnShowToolTip.Checked;             // note: I turned off CheckOnClick (with that on, I got a feedback loop, and it kept negating itself)
            }
            else if (e.ClickedItem is ToolStripSeparator)
            {
                // Do Nothing
            }
            else
            {
                MessageBox.Show("Menu item is unknown", "Context Menu Click", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 2
0
        private Ball BuildObject()
        {
            double radius;

            #region Calculate Radius

            switch (_newBallProps.SizeMode)
            {
            case BallProps.SizeModes.Draw:
                radius = .01d;                  // this function will only get called during mouse down if it's in draw mode, so I need to start with an arbitrarily small radius
                break;

            case BallProps.SizeModes.Fixed:
                radius = _newBallProps.SizeIfFixed;
                break;

            case BallProps.SizeModes.Random:
                radius = _rand.Next(Convert.ToInt32(_newBallProps.MinRandSize), Convert.ToInt32(_newBallProps.MaxRandSize));
                break;

            default:
                throw new ApplicationException("Unknown BallProps.SizeModes: " + _newBallProps.SizeMode);
            }

            if (radius < MINRADIUS)
            {
                radius = MINRADIUS;
            }

            #endregion

            double mass = UtilityCore.GetMassForRadius(radius, 1d);

            MyVector velocity;
            #region Calculate Velocity

            if (_newBallProps.RandomVelocity)
            {
                velocity = Utility3D.GetRandomVectorSpherical2D(_newBallProps.MaxVelocity);
            }
            else
            {
                velocity = _newBallProps.Velocity;              // no need to clone it.  I won't manipulate it
            }

            #endregion

            //TODO:  Listen to global props
            double elasticity      = .75d;
            double kineticFriction = .75d;
            double staticFriction  = 1d;

            Ball retVal;
            #region Build the ball

            switch (_mode)
            {
            case AddingMode.AddBall:
                #region Create Ball

                retVal = new Ball(_curMousePoint.Clone(), new DoubleVector(0, 1, 0, 1, 0, 0), radius, mass, elasticity, kineticFriction, staticFriction, _boundryLower, _boundryUpper);
                retVal.Velocity.Add(velocity);

                #endregion
                break;

            case AddingMode.AddSolidBall:
                #region Create Solid Ball

                retVal = new SolidBall(_curMousePoint.Clone(), new DoubleVector(0, 1, 0, 1, 0, 0), radius, mass, elasticity, kineticFriction, staticFriction, _boundryLower, _boundryUpper);
                retVal.Velocity.Add(velocity);
                //StoreAngularVelocity(retVal);		// no reason to do this here.  it will be applied during commit (if I'm in draw mode, the size will change, and the angular velocity will need to be reapplied anyway)

                #endregion
                break;

            default:
                throw new ApplicationException("Unsupported AddingMode: " + _mode.ToString());
            }

            #endregion

            // Exit Function
            return(retVal);
        }