/// <summary> /// This should only be called if _newBallProps.SizeMode is Draw /// </summary> private void ResizeDrawingObject() { // Find the vector from the mousedown point to the current point MyVector fromToLine = _curMousePoint - _mouseDownPoint; // Adjust the radius and mass switch (_mode) { case AddingMode.AddBall: case AddingMode.AddSolidBall: double newValue = fromToLine.GetMagnitude(); if (newValue < MINRADIUS) { newValue = MINRADIUS; } _drawingBall.Radius = newValue; _drawingBall.Mass = UtilityCore.GetMassForRadius(newValue, 1d); break; //case AddingMode.AddRigidBody: // //TODO: I will need to pull all the point masses out proportionatly, as well as change their masses // break; default: throw new ApplicationException("Unknown AddingMode: " + _mode.ToString()); } }
private void PropsChangedSprtExisting() { switch (_type) { case ShipTypeQual.None: break; case ShipTypeQual.Ball: _ship.Ball.Radius = _shipSize; _ship.Ball.Mass = UtilityCore.GetMassForRadius(_shipSize, 1d); _thrustForce = GetThrustForce(_ship.Ball.Mass); _torqueballLeftRightThrusterForce = _thrustForce; break; case ShipTypeQual.SolidBall: _ship.Ball.Radius = _shipSize; _ship.Ball.Mass = UtilityCore.GetMassForRadius(_shipSize, 1d); _thrustForce = GetThrustForce(_ship.Ball.Mass); _torqueballLeftRightThrusterForce = GetLeftRightThrusterMagnitude(_ship.TorqueBall.InertialTensorBody); break; default: throw new ApplicationException("Unknown ShipTypeQual: " + _type.ToString()); } }
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 static double GetLeftRightThrusterMagnitude(MyMatrix3 inertialTensor) { // Create a standard sized solid ball, and use that as my baseline SolidBall standBall = new SolidBall(new MyVector(), new DoubleVector(1, 0, 0, 0, 1, 0), STANDARDRADIUS, UtilityCore.GetMassForRadius(STANDARDRADIUS, 1d)); double averageStand = GetLeftRightThrusterMagnitudeSprtGetAvg(standBall.InertialTensorBody); double averageShip = GetLeftRightThrusterMagnitudeSprtGetAvg(inertialTensor); return(THRUSTER_FORCE * (Math.Sqrt(averageShip) / Math.Sqrt(averageStand))); // I need sqrt, because the tensor's don't grow linearly }
private static double GetThrustForce(double mass) { return(THRUSTER_FORCE * (mass / UtilityCore.GetMassForRadius(STANDARDRADIUS, 1d))); }
private Ball BuildObject() { double radius; #region Calculate Radius switch (_newBallProps.SizeMode) { case BallProps.SizeModes.Draw: radius = .01d; // this function will only get called during mouse down if it's in draw mode, so I need to start with an arbitrarily small radius break; case BallProps.SizeModes.Fixed: radius = _newBallProps.SizeIfFixed; break; case BallProps.SizeModes.Random: radius = _rand.Next(Convert.ToInt32(_newBallProps.MinRandSize), Convert.ToInt32(_newBallProps.MaxRandSize)); break; default: throw new ApplicationException("Unknown BallProps.SizeModes: " + _newBallProps.SizeMode); } if (radius < MINRADIUS) { radius = MINRADIUS; } #endregion double mass = UtilityCore.GetMassForRadius(radius, 1d); MyVector velocity; #region Calculate Velocity if (_newBallProps.RandomVelocity) { velocity = Utility3D.GetRandomVectorSpherical2D(_newBallProps.MaxVelocity); } else { velocity = _newBallProps.Velocity; // no need to clone it. I won't manipulate it } #endregion //TODO: Listen to global props double elasticity = .75d; double kineticFriction = .75d; double staticFriction = 1d; Ball retVal; #region Build the ball switch (_mode) { case AddingMode.AddBall: #region Create Ball retVal = new Ball(_curMousePoint.Clone(), new DoubleVector(0, 1, 0, 1, 0, 0), radius, mass, elasticity, kineticFriction, staticFriction, _boundryLower, _boundryUpper); retVal.Velocity.Add(velocity); #endregion break; case AddingMode.AddSolidBall: #region Create Solid Ball retVal = new SolidBall(_curMousePoint.Clone(), new DoubleVector(0, 1, 0, 1, 0, 0), radius, mass, elasticity, kineticFriction, staticFriction, _boundryLower, _boundryUpper); retVal.Velocity.Add(velocity); //StoreAngularVelocity(retVal); // no reason to do this here. it will be applied during commit (if I'm in draw mode, the size will change, and the angular velocity will need to be reapplied anyway) #endregion break; default: throw new ApplicationException("Unsupported AddingMode: " + _mode.ToString()); } #endregion // Exit Function return(retVal); }
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); }