private void AddMultiBall(double radius, double mass) { // Physical Ball MyVector pos = Utility3D.GetRandomVector(BOUNDRY); DoubleVector dirFacing = new DoubleVector(1, 0, 0, 0, 1, 0); Ball ball = new Ball(pos, dirFacing, radius, mass, ELASTICITY, KINETICFRICTION, STATICFRICTION, _boundryLower, _boundryUpper); BallBlip blip = new BallBlip(ball, CollisionStyle.Standard, RadarBlipQual.BallUserDefined00, TokenGenerator.NextToken()); _map.Add(blip); // WPF Rendering Geometry3D geometry = UtilityWPF.GetSphere(5, radius); Material material = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(255, Convert.ToByte(_rand.Next(256)), Convert.ToByte(_rand.Next(256)), Convert.ToByte(_rand.Next(256))))); GeometryModel3D geometryModel = new GeometryModel3D(geometry, material); geometryModel.Transform = new Transform3DGroup(); //TODO: Tie this transform directly to the ball's velocity (the shpere class should take the transform group) Transform3DGroup group = geometryModel.Transform as Transform3DGroup; group.Children.Clear(); group.Children.Add(new TranslateTransform3D(pos.X, pos.Y, pos.Z)); _geometries.Add(geometryModel); _modelGroup.Children.Add(geometryModel); }
private void btnRandomVelocity_Click(object sender, EventArgs e) { foreach (BallBlip blip in _map.GetAllBlips()) { blip.Ball.Velocity.StoreNewValues(Utility3D.GetRandomVector(MAXVELOCITY)); blip.Ball.Velocity.Z = 0; } }
private void btnSpinRandom_Click(object sender, EventArgs e) { if (_polygon == null) { MessageBox.Show("No polygon to spin", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } _polygon.AngularMomentum.StoreNewValues(Utility3D.GetRandomVector(MOMENTUM)); }
private void btnGravBallRandomSpeed_Click(object sender, EventArgs e) { const double MAXSPEED = 40; Random rand = new Random(); foreach (Ball gravBall in _gravityBalls) { MyVector newVelocity = Utility3D.GetRandomVector(MAXSPEED); newVelocity.Z = 0; gravBall.Velocity.StoreNewValues(newVelocity); } }
private void chkIncludeShip_CheckedChanged(object sender, EventArgs e) { const double THRUSTERANGLE = 75; if (chkIncludeShip.Checked) { if (_ship == null) { #region Create Ship // Set up the ship double radius = MINRADIUSMASS + (_rand.NextDouble() * (MAXRADIUSMASS - MINRADIUSMASS)); SolidBall ship = new SolidBall(Utility3D.GetRandomVector(_boundryLower, _boundryUpper), new DoubleVector(0, 1, 0, 1, 0, 0), radius, GetMass(radius), GetElasticity(), 1, 1, _boundryLower, _boundryUpper); // Set up the thrusters MyVector thrusterSeed = new MyVector(0, ship.Radius, 0); MyVector zAxis = new MyVector(0, 0, 1); // Bottom Thrusters _shipThrusterOffset_BottomRight = thrusterSeed.Clone(); _shipThrusterOffset_BottomRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE * -1)); _shipThrusterOffset_BottomLeft = thrusterSeed.Clone(); _shipThrusterOffset_BottomLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE)); // Top Thrusters thrusterSeed = new MyVector(0, ship.Radius * -1, 0); _shipThrusterOffset_TopRight = thrusterSeed.Clone(); _shipThrusterOffset_TopRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE)); _shipThrusterOffset_TopLeft = thrusterSeed.Clone(); _shipThrusterOffset_TopLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(THRUSTERANGLE * -1)); // Add to the map _ship = new BallBlip(ship, CollisionStyle.Standard, RadarBlipQual.BallUserDefined03, TokenGenerator.NextToken()); _map.Add(_ship); #endregion } } else { if (_ship != null) { _map.Remove(_ship.Token); _ship = null; } } }
private void btnAddSolidBall_Click(object sender, EventArgs e) { double radius = _rand.Next(Convert.ToInt32(MINRADIUSMASS), Convert.ToInt32(MAXRADIUSMASS)); double mass = GetMass(radius); double elasticity = GetElasticity(); SolidBall ball = new SolidBall(Utility3D.GetRandomVector(_boundryLower, _boundryUpper), new DoubleVector(0, 1, 0, 1, 0, 0), radius, mass, elasticity, 1, 1, _boundryLower, _boundryUpper); ball.Velocity.Add(Utility3D.GetRandomVector(MAXVELOCITY)); ball.Velocity.Z = 0; BallBlip blip = new BallBlip(ball, CollisionStyle.Standard, RadarBlipQual.BallUserDefined01, TokenGenerator.NextToken()); _map.Add(blip); }
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 CreateGravityBall(Random rand) { const int MINMASS = 500; const int MAXMASS = 5000; const int MINCOLOR = 75; // Figure out ball properties int radius = rand.Next(100, 500); MyVector position = Utility3D.GetRandomVector(_boundryLower, _boundryUpper); DoubleVector dirFacing = new DoubleVector(new MyVector(1, 0, 0), new MyVector(0, 1, 0)); int mass = rand.Next(MINMASS, MAXMASS); double massPercent = Convert.ToDouble(mass - MINMASS) / Convert.ToDouble(MAXMASS - MINMASS); int colorValue = MINCOLOR + Convert.ToInt32((255 - MINCOLOR) * massPercent); // Make the ball _gravityBalls.Add(new Ball(position, dirFacing, radius, mass, _boundryLower, _boundryUpper)); _gravityBallColors.Add(Color.FromArgb(colorValue, colorValue, colorValue)); }
private void btnAdd_Click(object sender, EventArgs e) { const int MINMASS = 10; const int MAXMASS = 1000; const int MINCOLOR = 75; const double MAXVELOCITY = 7; // Figure out ball properties int radius = _rand.Next(2, 31); MyVector position = Utility3D.GetRandomVector(new MyVector(radius, radius, 0), new MyVector(pictureBox1.Width - radius, pictureBox1.Height - radius, 0)); DoubleVector dirFacing = new DoubleVector(new MyVector(1, 0, 0), new MyVector(0, 1, 0)); int mass = _rand.Next(MINMASS, MAXMASS); MyVector boundingLower = new MyVector(0, 0, -1); MyVector boundingUpper = new MyVector(pictureBox1.Width, pictureBox1.Height, 1); double massPercent = Convert.ToDouble(mass - MINMASS) / Convert.ToDouble(MAXMASS - MINMASS); int colorValue = MINCOLOR + Convert.ToInt32((255 - MINCOLOR) * massPercent); // Make the ball _balls.Add(new Ball(position, dirFacing, radius, mass, boundingLower, boundingUpper)); // Calculate the shell color if (chkRandVelocity.Checked) { _balls[_balls.Count - 1].Velocity.Add(Utility3D.GetRandomVector(MAXVELOCITY)); } _ballColors.Add(Color.FromArgb(colorValue, colorValue, colorValue)); // Make a tail _ballTails.Add(new Trail(100)); _ballTails[_ballTails.Count - 1].SetColors(Color.MediumOrchid, Color.Black); _ballTails[_ballTails.Count - 1].SetWidths(3f, 1f); // Make sure the checkbox is checked if (!chkRunningGravBalls.Checked) { chkRunningGravBalls.Checked = true; } }
private void PropsChangedSprtNew() { MyVector position = null; // Kill Existing if (_ship != null) { position = _ship.Ball.Position.Clone(); _map.Remove(_ship.Token); _ship = null; } else { position = Utility3D.GetRandomVector(_boundryLower, _boundryUpper); } _tractorBeams.Clear(); _cannon = null; _machineGuns.Clear(); #region New Ship //TODO: Listen to global props double elasticity = .75d; double kineticFriction = .75d; double staticFriction = 1d; // Build New Ball newBall; RadarBlipQual blipQual; // logic came from BallAdder.CommitObject switch (_type) { case ShipTypeQual.None: return; case ShipTypeQual.Ball: #region Ball newBall = new Ball(position, new DoubleVector(0, 1, 0, 1, 0, 0), _shipSize, UtilityCore.GetMassForRadius(_shipSize, 1d), elasticity, kineticFriction, staticFriction, _boundryLower, _boundryUpper); blipQual = RadarBlipQual.BallUserDefined00; _thrustForce = GetThrustForce(newBall.Mass); _torqueballLeftRightThrusterForce = _thrustForce; #endregion break; case ShipTypeQual.SolidBall: #region Solid Ball newBall = new SolidBall(position, new DoubleVector(0, 1, 0, 1, 0, 0), _shipSize, UtilityCore.GetMassForRadius(_shipSize, 1d), elasticity, kineticFriction, staticFriction, _boundryLower, _boundryUpper); blipQual = RadarBlipQual.BallUserDefined01; _thrustForce = GetThrustForce(newBall.Mass); _torqueballLeftRightThrusterForce = GetLeftRightThrusterMagnitude(((SolidBall)newBall).InertialTensorBody); #endregion break; default: throw new ApplicationException("Unknown ShipTypeQual: " + _type.ToString()); } newBall.RotateAroundAxis(new MyVector(0, 0, 1), Math.PI); // Finish Building _ship = new BallBlip(newBall, CollisionStyle.Standard, blipQual, _blipToken); _map.Add(_ship); #endregion if (this.CreateNewTractorBeams != null) { this.CreateNewTractorBeams(this, new EventArgs()); } #region Guns _cannon = new ProjectileWeapon(300, 150, UtilityCore.GetMassForRadius(150, 1d), 25, true, _ignoreOtherProjectiles, RadarBlipQual.Projectile, false, _map, _boundryLower, _boundryUpper); _cannon.AddBarrel(_ship.Ball.OriginalDirectionFacing.Standard.Clone()); _cannon.AddFiringMode(20); _cannon.SetProjectileExplosion(450, 2, 10000); _cannon.SeProjectileFuse(500); _cannon.SetShip(_ship); for (int cntr = 0; cntr < 2; cntr++) { ProjectileWeapon weapon = new ProjectileWeapon(30, 20, UtilityCore.GetMassForRadius(20, 1d), 100, true, _ignoreOtherProjectiles, RadarBlipQual.Projectile, false, _map, _boundryLower, _boundryUpper); weapon.AddBarrel(new MyVector(), new MyQuaternion()); weapon.AddFiringMode(2); weapon.SetProjectileExplosion(40, 2, 300); weapon.SeProjectileFuse(500); weapon.SetShip(_ship); _machineGuns.Add(weapon); } #endregion }