예제 #1
0
        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());
        }
예제 #2
0
        public override Sphere Clone()
        {
            // Make a shell
            // I want a copy of the bounding box, not a clone (everything else gets cloned)
            RigidBody retVal = new RigidBody(this.Position.Clone(), this.OriginalDirectionFacing.Clone(), this.Rotation.Clone(), this.Radius, this.Elasticity, this.KineticFriction, this.StaticFriction, this.UsesBoundingBox, this.BoundryLower, this.BoundryUpper);

            PointMass[] clonedMasses = _masses.ToArray();		// sounds like an army

            // Clone them (I don't want the events to go with)
            for (int massCntr = 0; massCntr < clonedMasses.Length; massCntr++)
            {
                clonedMasses[massCntr] = clonedMasses[massCntr].Clone();
            }

            // Now I can add the masses to my return
            retVal.AddRangePointMasses(clonedMasses);

            // Exit Function
            return retVal;
        }
예제 #3
0
        private void DrawRigidBody(RigidBody body, Color massColor, Color massOutlineColor, bool drawRed)
        {
            // Radius
            if (drawRed)
            {
                pictureBox1.FillCircle(Color.FromArgb(160, Color.Tomato), body.Position, body.Radius);
            }
            else
            {
                pictureBox1.FillCircle(Color.FromArgb(32, Color.DarkTurquoise), body.Position, body.Radius);
            }
            pictureBox1.DrawCircle(UtilityGDI.AlphaBlend(Color.DarkTurquoise, Color.Black, .5d), .5d, body.Position, body.Radius);

            // Point Masses
            SolidBrush massBrush = new SolidBrush(massColor);

            foreach (PointMass pointMass in body.PointMasses)
            {
                MyVector rotatedMass = body.Rotation.GetRotatedVector(pointMass.Position, true);

                pictureBox1.FillCircle(massBrush, body.Position + rotatedMass, pointMass.Mass);
                pictureBox1.DrawCircle(massOutlineColor, 1, body.Position + rotatedMass, pointMass.Mass);
            }

            massBrush.Dispose();

            // Orientation
            //_viewer.DrawLine(Color.FromArgb(64, 64, 64), 1, body.Position, MyVector.AddVector(body.Position, MyVector.MultiplyConstant(body.DirectionFacing.Stanard, 100)));
            //_viewer.DrawLine(Color.FromArgb(32, 32, 32), 1, body.Position, MyVector.AddVector(body.Position, MyVector.MultiplyConstant(body.DirectionFacing.Orth, 100)));

            MyVector rotatedCenterMass = body.Rotation.GetRotatedVector(body.CenterOfMass, true);

            // Line from centerpoint to centermass
            pictureBox1.DrawLine(Color.DarkMagenta, 1, body.Position, body.Position + rotatedCenterMass);

            // Center Point
            pictureBox1.FillCircle(Color.DarkMagenta, body.Position, 10);

            // Center Mass
            pictureBox1.FillCircle(Color.HotPink, body.Position + rotatedCenterMass, 22);
        }
예제 #4
0
        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);
        }
예제 #5
0
        private void btnResetShip_Click(object sender, EventArgs e)
        {
            // Make sure the simulation isn't running (allow it to run when they've added 3 masses)
            chkRunning.Enabled = false;
            chkRunning.Checked = false;

            // Create a blank ship
            _ship = new RigidBody(new MyVector(0, 0, 0), new DoubleVector(0, -1, 0, -1, 0, 0), MINSHIPRADIUS, _boundryLower, _boundryUpper);

            // Tell the viewer to chase the center of mass
            _centerMassWorld = new MyVector();
            CalculateCenterMassWorld();
            pictureBox1.ChasePoint(_centerMassWorld);

            // Finally, put myself into a ship building state
            SetState(GlobalState.AddingMass);
        }
예제 #6
0
        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());
        }
예제 #7
0
 public void DrawRigidBody(RigidBody body, DrawMode mode, CollisionStyle collisionStyle, bool drawRed)
 {
 }