private void button1_Click(object sender, EventArgs e) { _poolBall = new SolidBall(GetMiddlePoint(), new DoubleVector(1, 0, 0, 0, 1, 0), 80, 100, _boundryLower, _boundryUpper); chkPoolRunning.Enabled = true; chkPoolRunning.Checked = true; }
private void DrawThruster(SolidBall ship, MyVector thruster) { MyVector worldThruster = _ship.Rotation.GetRotatedVector(thruster, true); worldThruster.Add(_ship.Position); DrawDot(worldThruster, 3f, Color.Silver); }
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 void DrawBall(SolidBall ball, Color ballColor) { // Turn it into ints MyVector topLeft = ball.Position.Clone(); topLeft.X -= ball.Radius; topLeft.Y -= ball.Radius; Point topLeftInt = topLeft.ToPoint(); int size = Convert.ToInt32(ball.Radius * 2); // Draw the ball _graphics.DrawEllipse(new Pen(ballColor, 3), topLeftInt.X, topLeftInt.Y, size, size); }
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 btnResetShip_Click(object sender, EventArgs e) { // Set up the ship double radius = 60; MyVector radiusBoundry = new MyVector(radius, radius, 0); MyVector boundryLower = _boundryLower + radiusBoundry; MyVector boundryUpper = _boundryUpper - radiusBoundry; _ship = new SolidBall(GetMiddlePoint(), new DoubleVector(0, -1, 0, -1, 0, 0), radius, 100, boundryLower, boundryUpper); // Set up the thrusters trackBar1_Scroll(this, new EventArgs()); chkShipRunning.Enabled = true; chkShipRunning.Checked = true; }
private void DrawBall(SolidBall ball, Color ballColor, Color dirFacingStandColor, Color dirFacingOrthColor) { // Standard Facing MyVector workingVect = ball.DirectionFacing.Standard.Clone(); workingVect.BecomeUnitVector(); workingVect.Multiply(ball.Radius); workingVect.Add(ball.Position); DrawVector(ball.Position, workingVect, dirFacingStandColor); // Orthogonal Facing workingVect = ball.DirectionFacing.Orth.Clone(); workingVect.BecomeUnitVector(); workingVect.Multiply(ball.Radius); workingVect.Add(ball.Position); DrawVector(ball.Position, workingVect, dirFacingOrthColor); // Ball DrawBall(ball, ballColor); }
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 }
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); }
/// <summary> /// The opacity passed in will be applied after figuring out the opacity of mode (if mode says 128, and opacity is .5, then /// the final opacity is 64) /// </summary> public void DrawSolidBall(SolidBall ball, DrawMode mode, CollisionStyle collisionStyle, bool drawRed, double opacity) { Color color; #region Figure out the color if (drawRed) { color = REDCOLOR; } else { color = Color.RoyalBlue; } #endregion int finalOpacity; #region Figure out the opacity switch (mode) { case DrawMode.Building: finalOpacity = BUILDINGBALLFILLOPACTIY; break; case DrawMode.Selected: case DrawMode.Standard: finalOpacity = STANDARDBALLFILLOPACTIY; break; default: throw new ApplicationException("Unknown DrawMode: " + mode.ToString()); } finalOpacity = Convert.ToInt32(finalOpacity * opacity); if (finalOpacity < 0) { finalOpacity = 0; } else if (finalOpacity > 255) { finalOpacity = 255; } #endregion MyVector dirFacing; #region Figure out direction facing dirFacing = ball.DirectionFacing.Standard.Clone(); dirFacing.BecomeUnitVector(); dirFacing.Multiply(ball.Radius); dirFacing.Add(ball.Position); #endregion // Collision Style DrawCollisionStyle(ball.Position, ball.Radius, collisionStyle); // Fill the circle using (Brush brush = new SolidBrush(Color.FromArgb(finalOpacity, color))) { _viewer.FillCircle(brush, ball.Position, ball.Radius); } // Draw direction facing _viewer.DrawLine(Color.FromArgb(finalOpacity, Color.White), 2d, ball.Position, dirFacing); #region Draw the edge switch (mode) { case DrawMode.Building: _viewer.DrawCircle(Color.FromArgb(finalOpacity, _buildingPenColor), STANDARDOUTLINEWIDTH, ball.Position, ball.Radius); break; case DrawMode.Standard: _viewer.DrawCircle(Color.FromArgb(finalOpacity, _standardPenColor), STANDARDOUTLINEWIDTH, ball.Position, ball.Radius); break; case DrawMode.Selected: _viewer.DrawCircle_Selected(ball.Position, ball.Radius); break; } #endregion //TODO: Show Stats }
public void DrawSolidBall(SolidBall ball, DrawMode mode, CollisionStyle collisionStyle, bool drawRed) { DrawSolidBall(ball, mode, collisionStyle, drawRed, 1d); }