private void btnResetTotal_Click(object sender, EventArgs e) { chkCoupledXPos.Checked = false; chkCoupledYPos.Checked = false; _rigidBody = new RigidBody(new MyVector(0, 0, 0), new DoubleVector(1, 0, 0, 0, 1, 0), 1, _boundryLower, _boundryUpper); // Set up PointMasses _north = _rigidBody.AddPointMass(0, 0, 0, MINMASS); _south = _rigidBody.AddPointMass(0, 0, 0, MINMASS); _east = _rigidBody.AddPointMass(0, 0, 0, MINMASS); _west = _rigidBody.AddPointMass(0, 0, 0, MINMASS); trkNorthPos.Value = 500; trkNorthPos_Scroll(this, new EventArgs()); trkSouthPos.Value = 500; trkSouthPos_Scroll(this, new EventArgs()); trkEastPos.Value = 500; trkEastPos_Scroll(this, new EventArgs()); trkWestPos.Value = 500; trkWestPos_Scroll(this, new EventArgs()); trkNorthMass.Value = 500; trkNorthMass_Scroll(this, new EventArgs()); trkSouthMass.Value = 500; trkSouthMass_Scroll(this, new EventArgs()); trkEastMass.Value = 500; trkEastMass_Scroll(this, new EventArgs()); trkWestMass.Value = 500; trkWestMass_Scroll(this, new EventArgs()); // Set the momentum trkAngularMomentum.Value = 500; trkAngularMomentum_Scroll(this, new EventArgs()); }
private void btnResetPartial_Click(object sender, EventArgs e) { _rigidBody = new RigidBody(new MyVector(0, 0, 0), new DoubleVector(1, 0, 0, 0, 1, 0), 1, _boundryLower, _boundryUpper); // Set up PointMasses _north = _rigidBody.AddPointMass(0, 0, 0, MINMASS); _south = _rigidBody.AddPointMass(0, 0, 0, MINMASS); _east = _rigidBody.AddPointMass(0, 0, 0, MINMASS); _west = _rigidBody.AddPointMass(0, 0, 0, MINMASS); trkNorthPos_Scroll(this, new EventArgs()); trkSouthPos_Scroll(this, new EventArgs()); trkEastPos_Scroll(this, new EventArgs()); trkWestPos_Scroll(this, new EventArgs()); trkNorthMass_Scroll(this, new EventArgs()); trkSouthMass_Scroll(this, new EventArgs()); trkEastMass_Scroll(this, new EventArgs()); trkWestMass_Scroll(this, new EventArgs()); // Set the momentum trkAngularMomentum_Scroll(this, new EventArgs()); }
private void btnAddRigidBody_Click(object sender, EventArgs e) { const int MINPOINTMASSES = 3; const int MAXPOINTMASSES = 8; const double MINPOINTMASSRADIUS = MINRADIUSMASS / MINPOINTMASSES; const double MAXPOINTMASSRADIUS = MAXRADIUSMASS / MAXPOINTMASSES; // Make the chassis RigidBody ball = new RigidBody(Utility3D.GetRandomVector(_boundryLower, _boundryUpper), new DoubleVector(0, -1, 0, -1, 0, 0), .1d, GetElasticity(), 1, 1, _boundryLower, _boundryUpper); int numPointMasses = _rand.Next(MINPOINTMASSES, MAXPOINTMASSES + 1); //double maxOffset = MAXRADIUSMASS - ((MINPOINTMASSRADIUS + MAXPOINTMASSRADIUS) / 2d); // this could result in bodies slightly larger than the other two types, but it should be close double maxOffset = MAXRADIUSMASS - MAXPOINTMASSRADIUS; double ballRadius = ball.Radius; double curRadius; // Add point masses for (int massCntr = 1; massCntr <= numPointMasses; massCntr++) { MyVector pointMassPos = Utility3D.GetRandomVectorSpherical(maxOffset); pointMassPos.Z = 0; // I do this here for the radius calculation below double pointMassMass = MINPOINTMASSRADIUS + (_rand.NextDouble() * (MAXPOINTMASSRADIUS - MINPOINTMASSRADIUS)); // Add a point mass ball.AddPointMass(pointMassPos.X, pointMassPos.Y, 0, pointMassMass); // See if this pushes out the ball's overall radius curRadius = pointMassPos.GetMagnitude() + pointMassMass; // I assume that the pointmass's mass is the same as its radius if (curRadius > ballRadius) { ballRadius = curRadius; } } // Store the new radius ball.Radius = ballRadius * 1.1d; // make it slightly bigger // Set the velocity ball.Velocity.Add(Utility3D.GetRandomVector(MAXVELOCITY)); ball.Velocity.Z = 0; BallBlip blip = new BallBlip(ball, CollisionStyle.Standard, RadarBlipQual.BallUserDefined02, TokenGenerator.NextToken()); _map.Add(blip); }
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(); }