private void SetRandomVelocities(double maxVelocity) { foreach (BallBlip blip in _map.GetAllBlips()) { blip.Ball.Velocity.StoreNewValues(Utility3D.GetRandomVectorSpherical(maxVelocity)); } }
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); }