Beispiel #1
0
        private void radPolygon_CheckedChanged(object sender, EventArgs e)
        {
            const double POLYSIZE = 200d;

            lblNotes.Text = "";

            MyPolygon poly = null;

            // Get the polygon
            if (radCube.Checked)
            {
                poly = MyPolygon.CreateCube(POLYSIZE, true);
            }
            else if (radTetrahedron.Checked)
            {
                poly          = MyPolygon.CreateTetrahedron(POLYSIZE, true);
                lblNotes.Text = "Lengths:\n0,1=" + MyVector.Subtract(poly.UniquePoints[1], poly.UniquePoints[0]).GetMagnitude().ToString() + "\n0,2=" + MyVector.Subtract(poly.UniquePoints[2], poly.UniquePoints[0]).GetMagnitude().ToString() + "\n0,3=" + MyVector.Subtract(poly.UniquePoints[3], poly.UniquePoints[0]).GetMagnitude().ToString() + "\n1,2=" + MyVector.Subtract(poly.UniquePoints[2], poly.UniquePoints[1]).GetMagnitude().ToString() + "\n1,3=" + MyVector.Subtract(poly.UniquePoints[3], poly.UniquePoints[1]).GetMagnitude().ToString() + "\n2,3=" + MyVector.Subtract(poly.UniquePoints[3], poly.UniquePoints[2]).GetMagnitude().ToString();
            }
            else
            {
                _polygon = null;
                MessageBox.Show("Unknown Polygon", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            // Make a new solidball
            _polygon = new SolidBallPolygon(new MyVector(0, 0, 0), new DoubleVector(1, 0, 0, 0, 1, 0), poly, 10, 10);
        }
Beispiel #2
0
        private void ShipBuildingTick()
        {
            MyVector centerPoint = GetMiddlePoint();

            // If there is a new mass, add it before drawing the ship
            if (_isMouseJustReleased)
            {
                _isMouseJustReleased = false;
                #region Add Mass

                double mass = MyVector.Subtract(new MyVector(_curMousePoint), new MyVector(_mouseDownPoint)).GetMagnitude();

                if (mass > 0)           // it was erroring out when I clicked without moving the mouse
                {
                    // They just added a new mass
                    MyVector massPos = new MyVector(_mouseDownPoint) - centerPoint;

                    _ship.AddPointMass(massPos.X, massPos.Y, massPos.Z, mass);

                    if (_ship.PointMassCount > 2)
                    {
                        chkRunning.Enabled = true;
                    }

                    _ship.Radius = GetLargestRadius();
                }

                #endregion
            }

            // Draw the ship
            DrawShipDesign(Color.MediumSlateBlue, Color.White);
            DrawThrustDesign(Color.DimGray, .5d);

            if (_isMouseDown)
            {
                // They are in the middle of adding a mass
                DrawDot(new MyVector(_mouseDownPoint), MyVector.Subtract(new MyVector(_curMousePoint), new MyVector(_mouseDownPoint)).GetMagnitude(), Color.Gray);
                DrawVector(new MyVector(_curMousePoint), new MyVector(_mouseDownPoint), Color.Yellow);
            }

            txtNumPointMasses.Text = _ship.PointMassCount.ToString();
            txtTotalMass.Text      = Math.Round(_ship.Mass, 1).ToString();
        }
Beispiel #3
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            const double ELAPSEDTIME = .5;

            #region Do Physics

            _poolBall.PrepareForNewTimerCycle();


            if (_isMouseJustReleased)
            {
                _isMouseJustReleased = false;

                MyVector force = new MyVector(_mouseDownPoint);
                force.Subtract(new MyVector(_curMousePoint));

                MyVector offset = new MyVector(_mouseDownPoint);
                offset.Subtract(_poolBall.Position);

                _poolBall.ApplyExternalForce(offset, force);
            }


            _poolBall.TimerTestPosition(ELAPSEDTIME);
            _poolBall.TimerFinish();

            #endregion

            #region Draw

            ClearPictureBox();

            if (_isMouseDown)
            {
                DrawVector(_poolBall.Position, new MyVector(_mouseDownPoint.X, _mouseDownPoint.Y, 0), Color.Olive);
                DrawVector(new MyVector(_mouseDownPoint.X, _mouseDownPoint.Y, 0), new MyVector(_curMousePoint.X, _curMousePoint.Y, 0), Color.Gold);
            }

            DrawBall(_poolBall, Color.Silver, Color.MediumPurple, Color.Purple);

            BlitImage();

            #endregion
        }