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 CommitObject() { Ball newObject; #region Get the base object to add if (_drawingBall != null) { newObject = _drawingBall; _drawingBall = null; } else { newObject = BuildObject(); } #endregion RadarBlipQual blipQual; #region Figure out the blipqual //TODO: Define these as constants somewhere switch (_mode) { case AddingMode.AddBall: blipQual = RadarBlipQual.BallUserDefined00; break; case AddingMode.AddSolidBall: blipQual = RadarBlipQual.BallUserDefined01; break; case AddingMode.AddRigidBody: blipQual = RadarBlipQual.BallUserDefined02; break; default: throw new ApplicationException("Unknown AddingMode: " + _mode.ToString()); } #endregion // Create a blip to contain this object BallBlip blip = new BallBlip(newObject, _newBallProps.CollisionStyle, blipQual, TokenGenerator.NextToken()); // If this is a torqueball, then it will get the angular velocity. I have to wait until now, because // the size could change during a draw (you don't see it spin during the drag anyway, because I // don't call it's timer, so there is no reason to set angular velocity before now.) StoreAngularVelocity(blip.Ball); // Add it to the map _map.Add(blip); if (_newBallProps.Temporary) { _tempObjects.Add(blip.Token); } }
private void btnChase_Click(object sender, EventArgs e) { BallBlip ship = _shipController.Ship; if (ship == null) { MessageBox.Show("No ship to chase", "Ship Type Props", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } _picturebox.ChasePoint(ship.Ball.Position); }
public static RadarBlip CloneBlip(RadarBlip blip, SimpleMap map) { BallBlip retVal = new BallBlip((Ball)blip.Sphere.Clone(), blip.CollisionStyle, blip.Qual, TokenGenerator.NextToken()); retVal.Ball.Velocity.StoreNewValues(((Ball)blip.Sphere).Velocity); if (blip.Sphere is TorqueBall) { ((TorqueBall)retVal.Sphere).AngularMomentum.StoreNewValues(((TorqueBall)blip.Sphere).AngularMomentum); } return(retVal); }
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); }
public GravMouse(LargeMapViewer2D picturebox, SimpleMap map, MyVector boundryLower, MyVector boundryUpper) { const double RADIUS = 400; _picturebox = picturebox; _map = map; _boundryLower = boundryLower; _boundryUpper = boundryUpper; _cursorBlip = new BallBlip(new Ball(new MyVector(), new DoubleVector(1, 0, 0, 0, 1, 0), RADIUS, UtilityCore.GetMassForRadius(RADIUS, 1d), 1, 0, 0, _boundryLower, _boundryUpper), CollisionStyle.Stationary, RadarBlipQual.BallUserDefined05, TokenGenerator.NextToken()); _picturebox.MouseDown += new MouseEventHandler(picturebox_MouseDown); _picturebox.MouseUp += new MouseEventHandler(picturebox_MouseUp); _picturebox.MouseMove += new MouseEventHandler(picturebox_MouseMove); _picturebox.MouseLeave += new EventHandler(picturebox_MouseLeave); }
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); }
public TractorBeamCone(SimpleMap map, BallBlip ship, MyVector offset, DoubleVector dirFacing, BeamMode mode, bool isSoft, double sweepAngle, double maxDistance, double forceAtZero, double forceAtMax, double maxForcePerTick) { _map = map; _ship = ship; _offset = offset; _dirFacing = dirFacing; _mode = mode; _isSoft = isSoft; _sweepAngle = sweepAngle; _maxDistance = maxDistance; _forceAtZero = forceAtZero; _forceAtMax = forceAtMax; _maxForcePerTick = maxForcePerTick; }
private void ApplyExplosionForce(RadarBlip blip) { if (!(blip is BallBlip)) { return; } BallBlip castBlip = (BallBlip)blip; MyVector force = castBlip.Ball.Position - this.Ball.Position; force.BecomeUnitVector(); force.Multiply(_explosion.Force); // Setting the force does no good, because PrepareForNewTick is called before it can take affect //castBlip.Ball.ExternalForce.Add(force); force.Divide(castBlip.Ball.Mass); // F=MA castBlip.Ball.Velocity.Add(force); }
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 }
private void HurtBlip(Projectile projectile, RadarBlip blip) { #region See if a split should occur if (blip.CollisionStyle != CollisionStyle.Standard) { return; } if (!(blip is BallBlip)) { return; } BallBlip castBlip = (BallBlip)blip; double ratio = projectile.Pain / castBlip.Ball.Mass; double rand = _rand.NextDouble(); if (ratio < rand) { return; } #endregion #region Calculate Split Percents int numParts = 2 + _rand.Next(3); // between 2 and 4 parts double[] splitPercents = new double[numParts]; double remainder = 1d; for (int cntr = 0; cntr < numParts - 1; cntr++) { splitPercents[cntr] = _rand.NextDouble() * remainder; remainder -= splitPercents[cntr]; } splitPercents[numParts - 1] = remainder; #endregion #region Build Objects _map.Remove(blip.Token); foreach (double percent in splitPercents) { double size = castBlip.Ball.Mass * percent; if (size < 20) { continue; } Ball ball; if (castBlip.Ball is SolidBall) { ball = new SolidBall(castBlip.Ball.Position.Clone(), castBlip.Ball.OriginalDirectionFacing.Clone(), size, size, castBlip.Ball.Elasticity, castBlip.Ball.KineticFriction, castBlip.Ball.StaticFriction, _boundryLower, _boundryUpper); } else { ball = new Ball(castBlip.Ball.Position.Clone(), castBlip.Ball.OriginalDirectionFacing.Clone(), size, size, castBlip.Ball.Elasticity, castBlip.Ball.KineticFriction, castBlip.Ball.StaticFriction, _boundryLower, _boundryUpper); } ball.Velocity.StoreNewValues(castBlip.Ball.Velocity); //TODO: Lay them out so they aren't touching each other. The smallest ones should be closest // to the point of impact (maybe give them slightly tweaked velocities as well so they explode // outward) _map.Add(new BallBlip(ball, blip.CollisionStyle, blip.Qual, TokenGenerator.NextToken())); } #endregion }
public Interaction(BallBlip blip, MyVector forceDirection, double force) { this.Blip = blip; this.ForceDirection = forceDirection; this.Force = force; }
/// <summary> /// This ties this gun to a ship (null is an allowed value) /// </summary> public void SetShip(BallBlip ship) { _ship = ship; }