private void ResetFieldSprtSwirl(bool goLeft) { // Init the grid _grid = new MyVector[_squaresPerSideX * _squaresPerSideY]; // I'm going to rotate everything 90 degrees MyVector rotateAxis = new MyVector(0, 0, 1); double radians = Math.PI / 2d; if (goLeft) { radians *= -1d; } foreach (MyVector center in GetGridCenters()) { // Get the local position MyVector localPosition = center - _position; // Turn that into a constant length, pointing in or out MyVector fieldLine = localPosition.Clone(); fieldLine.BecomeUnitVector(); fieldLine.Multiply(_strength); fieldLine.RotateAroundAxis(rotateAxis, radians); // Store it _grid[GetIndexForLocalPosition(localPosition)] = fieldLine; } }
private void PropsChangedSprtThrusters() { if (_type != ShipTypeQual.SolidBall) { return; // the ball just has the thruster in the center } MyVector thrusterSeed = new MyVector(0, _ship.Ball.Radius, 0); MyVector zAxis = new MyVector(0, 0, 1); // Bottom Thrusters _thrusterOffset_BottomRight = thrusterSeed.Clone(); _thrusterOffset_BottomRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(_thrusterAngle * -1)); _thrusterOffset_BottomLeft = thrusterSeed.Clone(); _thrusterOffset_BottomLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(_thrusterAngle)); // Top Thrusters thrusterSeed = new MyVector(0, _ship.Ball.Radius * -1, 0); _thrusterOffset_TopRight = thrusterSeed.Clone(); _thrusterOffset_TopRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(_thrusterAngle)); _thrusterOffset_TopLeft = thrusterSeed.Clone(); _thrusterOffset_TopLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(_thrusterAngle * -1)); }
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 trackBar1_Scroll(object sender, EventArgs e) { _prevRadians = _currentRadians; _currentRadians = Utility3D.GetDegreesToRadians(trackBar1.Value); #region Draw Current Graphics graphics = pictureBox2.CreateGraphics(); graphics.Clear(pictureBox1.BackColor); DrawVector(graphics, _sphere.Position, _sphere.Position + (_sphere.DirectionFacing.Standard * 100d), Color.White); DrawVector(graphics, _sphere.Position, _sphere.Position + (_sphere.DirectionFacing.Orth * 100d), Color.Silver); MyVector rotatedOffset = _sphere.Rotation.GetRotatedVector(_offset, true); DrawVector(graphics, _sphere.Position, _sphere.Position + rotatedOffset, Color.Orange); DrawDot(graphics, _sphere.Position + rotatedOffset, 3, Color.Gold); #endregion double radians = _currentRadians - _prevRadians; if (radOffset.Checked) { // Remember where the offset is in world coords MyVector offsetRotated = _sphere.Rotation.GetRotatedVector(_offset, true); MyVector offsetWorld = _sphere.Position + offsetRotated; DrawDot(graphics, offsetWorld, 5, Color.DodgerBlue); // Get the opposite of the local offset MyVector posRelativeToOffset = offsetRotated.Clone(); posRelativeToOffset.Multiply(-1d); // Rotate the center of position around the center of mass posRelativeToOffset.RotateAroundAxis(_rotationAxis, radians); // Now figure out the new center of position _sphere.Position.X = offsetWorld.X + posRelativeToOffset.X; _sphere.Position.Y = offsetWorld.Y + posRelativeToOffset.Y; _sphere.Position.Z = offsetWorld.Z + posRelativeToOffset.Z; } _sphere.RotateAroundAxis(_rotationAxis, radians); }
private void trackBar_Scroll(object sender, EventArgs e) { // Figure out the vector to rotate around MyVector rotateAround = new MyVector(trkXAxis.Value, trkYAxis.Value, trkZAxis.Value); if (rotateAround.X == 0 && rotateAround.Y == 0 && rotateAround.Z == 0) { pictureBox1.CreateGraphics().Clear(Color.Tomato); return; } // Rotate a vector MyVector rotatedVector = new MyVector(9, 0, 0); rotatedVector.RotateAroundAxis(rotateAround, Utility3D.GetDegreesToRadians(trackBar1.Value)); // Draw it ClearPictureBox(); DrawVector(rotateAround, Color.LightSteelBlue); DrawVector(rotatedVector, Color.GhostWhite); }
private void trackBar1_Scroll(object sender, EventArgs e) { MyVector thrusterSeed = new MyVector(0, _ship.Radius, 0); MyVector zAxis = new MyVector(0, 0, 1); double angle = trackBar1.Value; // Bottom Thrusters _shipThrusterOffset_BottomRight = thrusterSeed.Clone(); _shipThrusterOffset_BottomRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(angle * -1)); _shipThrusterOffset_BottomLeft = thrusterSeed.Clone(); _shipThrusterOffset_BottomLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(angle)); // Top Thrusters thrusterSeed = new MyVector(0, _ship.Radius * -1, 0); _shipThrusterOffset_TopRight = thrusterSeed.Clone(); _shipThrusterOffset_TopRight.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(angle)); _shipThrusterOffset_TopLeft = thrusterSeed.Clone(); _shipThrusterOffset_TopLeft.RotateAroundAxis(zAxis, Utility3D.GetDegreesToRadians(angle * -1)); }
private void DrawVelocity(PieMenuDrawButtonArgs e) { const double MINLENGTHPERCENT = 0d; const double MAXLENGTHPERCENT = 1d; const double MINTARGET = 10d; const double MAXTARGET = 250d; #region Figure out the length // Figure out how long the real velocity will be double realVelocity = 0d; if (this.ExposedProps.RandomVelocity) { realVelocity = this.ExposedProps.MaxVelocity * .75d; } else { if (this.ExposedProps.Velocity != null && !this.ExposedProps.Velocity.IsZero) { realVelocity = this.ExposedProps.Velocity.GetMagnitude(); } } // Figure out the velocity to draw double velocityPercent = 0d; if (realVelocity >= MINLENGTHPERCENT) { velocityPercent = UtilityCore.GetScaledValue_Capped(MINLENGTHPERCENT, MAXLENGTHPERCENT, MINTARGET, MAXTARGET, realVelocity); } #endregion // Figure out the color Color velocityColor = GetGreenRedColor(MINTARGET, MAXTARGET, realVelocity, velocityPercent); float halfSize = e.ButtonSize * .5f; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; if (velocityPercent > 0d) { #region Draw Vector double drawLength = (e.ButtonSize / 2d) * velocityPercent; // Draw Vector using (Pen vectorPen = new Pen(velocityColor, 2f)) { vectorPen.StartCap = LineCap.Round; // LineCap.RoundAnchor; vectorPen.EndCap = LineCap.ArrowAnchor; MyVector vectorLine; if (this.ExposedProps.RandomVelocity) { // Draw a circle underneath using (Pen circlePen = new Pen(SystemColors.ControlDark, 1f)) { e.Graphics.DrawEllipse(circlePen, Convert.ToSingle(halfSize - drawLength), Convert.ToSingle(halfSize - drawLength), Convert.ToSingle(drawLength * 2d), Convert.ToSingle(drawLength * 2d)); } vectorLine = new MyVector(drawLength, 0, 0); vectorLine.RotateAroundAxis(new MyVector(0, 0, 1), Utility3D.GetDegreesToRadians(-60d)); e.Graphics.DrawLine(vectorPen, halfSize, halfSize, Convert.ToSingle(halfSize + vectorLine.X), Convert.ToSingle(halfSize + vectorLine.Y)); vectorLine.RotateAroundAxis(new MyVector(0, 0, 1), Utility3D.GetDegreesToRadians(-85d)); e.Graphics.DrawLine(vectorPen, halfSize, halfSize, Convert.ToSingle(halfSize + vectorLine.X), Convert.ToSingle(halfSize + vectorLine.Y)); vectorLine.RotateAroundAxis(new MyVector(0, 0, 1), Utility3D.GetDegreesToRadians(-150d)); e.Graphics.DrawLine(vectorPen, halfSize, halfSize, Convert.ToSingle(halfSize + vectorLine.X), Convert.ToSingle(halfSize + vectorLine.Y)); } else { vectorLine = this.ExposedProps.Velocity.Clone(); vectorLine.BecomeUnitVector(); vectorLine.Multiply(drawLength); e.Graphics.DrawLine(vectorPen, halfSize, halfSize, Convert.ToSingle(halfSize + vectorLine.X), Convert.ToSingle(halfSize + vectorLine.Y)); } } #endregion } else { e.Graphics.DrawString("Velocity", new Font("Arial", 8), Brushes.Black, 0, e.ButtonSize - 13); } }
private void DrawSize(PieMenuDrawButtonArgs e) { const double MINRADIUSPERCENT = .15d; const double MAXRADIUSPERCENT = 1d; const double MINTARGET = 20d; const double MAXTARGET = 1000d; #region Figure out the radius // Figure out how big the real ball will be double ballRadius = 0; switch (this.ExposedProps.SizeMode) { case BallProps.SizeModes.Draw: //TODO: Use a different line color ballRadius = UtilityCore.GetScaledValue(MINTARGET, MAXTARGET, 0d, 1d, .75d); break; case BallProps.SizeModes.Fixed: ballRadius = this.ExposedProps.SizeIfFixed; break; case BallProps.SizeModes.Random: ballRadius = (this.ExposedProps.MinRandSize + this.ExposedProps.MaxRandSize) / 2d; break; default: throw new ApplicationException("Unknown BallProps.SizeModes: " + this.ExposedProps.SizeMode.ToString()); } // Figure out the radius to draw double radiusPercent = UtilityCore.GetScaledValue_Capped(MINRADIUSPERCENT, MAXRADIUSPERCENT, MINTARGET, MAXTARGET, ballRadius); #endregion // Figure out the color Color radiusColor = GetGreenRedColor(MINTARGET, MAXTARGET, ballRadius, radiusPercent); float drawWidth = Convert.ToSingle((e.ButtonSize - 2) * radiusPercent); float halfDrawWidth = drawWidth * .5f; float halfSize = (e.ButtonSize - 2) * .5f; e.Graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; // Draw Radius using (Pen radiusPen = new Pen(radiusColor, 2f)) { MyVector radiusLine = new MyVector(halfDrawWidth, 0, 0); radiusLine.RotateAroundAxis(new MyVector(0, 0, 1), Utility3D.GetDegreesToRadians(-30d)); e.Graphics.DrawLine(radiusPen, halfSize, halfSize, Convert.ToSingle(halfSize + radiusLine.X), Convert.ToSingle(halfSize + radiusLine.Y)); } // Draw Circle Color circleColor = Color.Black; if (this.ExposedProps.SizeMode == BallProps.SizeModes.Draw) { circleColor = SystemColors.ControlDark; } using (Pen circlePen = new Pen(circleColor, 2f)) { e.Graphics.DrawEllipse(circlePen, halfSize - halfDrawWidth, halfSize - halfDrawWidth, drawWidth, drawWidth); } }
private Bitmap DrawVelocity() { const double MINLENGTHPERCENT = 0d; const double MAXLENGTHPERCENT = 1d; const double MINTARGET = 10d; const double MAXTARGET = 250d; #region Figure out the length // Figure out how long the real velocity will be double realVelocity = 0d; if (_exposedProps.RandomVelocity) { realVelocity = _exposedProps.MaxVelocity * .75d; } else { if (_exposedProps.Velocity != null && !_exposedProps.Velocity.IsZero) { realVelocity = _exposedProps.Velocity.GetMagnitude(); } } // Figure out the velocity to draw double velocityPercent = 0d; if (realVelocity >= MINLENGTHPERCENT) { velocityPercent = UtilityCore.GetScaledValue_Capped(MINLENGTHPERCENT, MAXLENGTHPERCENT, MINTARGET, MAXTARGET, realVelocity); } #endregion // Figure out the color Color velocityColor = GetGreenRedColor(MINTARGET, MAXTARGET, realVelocity, velocityPercent); float halfSize = _buttonSize * .5f; Bitmap retVal = new Bitmap(_buttonSize + 1, _buttonSize + 1); using (Graphics graphics = Graphics.FromImage(retVal)) { graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality; if (velocityPercent > 0d) { double drawLength = (_buttonSize / 2d) * velocityPercent; // Draw Vector using (Pen vectorPen = new Pen(velocityColor, 2f)) { vectorPen.StartCap = LineCap.Round; // LineCap.RoundAnchor; vectorPen.EndCap = LineCap.ArrowAnchor; MyVector vectorLine; if (_exposedProps.RandomVelocity) { // Draw a circle underneath using (Pen circlePen = new Pen(SystemColors.ControlDark, 1f)) { graphics.DrawEllipse(circlePen, Convert.ToSingle(halfSize - drawLength), Convert.ToSingle(halfSize - drawLength), Convert.ToSingle(drawLength * 2d), Convert.ToSingle(drawLength * 2d)); } vectorLine = new MyVector(drawLength, 0, 0); vectorLine.RotateAroundAxis(new MyVector(0, 0, 1), Utility3D.GetDegreesToRadians(-60d)); graphics.DrawLine(vectorPen, halfSize, halfSize, Convert.ToSingle(halfSize + vectorLine.X), Convert.ToSingle(halfSize + vectorLine.Y)); vectorLine.RotateAroundAxis(new MyVector(0, 0, 1), Utility3D.GetDegreesToRadians(-85d)); graphics.DrawLine(vectorPen, halfSize, halfSize, Convert.ToSingle(halfSize + vectorLine.X), Convert.ToSingle(halfSize + vectorLine.Y)); vectorLine.RotateAroundAxis(new MyVector(0, 0, 1), Utility3D.GetDegreesToRadians(-150d)); graphics.DrawLine(vectorPen, halfSize, halfSize, Convert.ToSingle(halfSize + vectorLine.X), Convert.ToSingle(halfSize + vectorLine.Y)); } else { vectorLine = _exposedProps.Velocity.Clone(); vectorLine.BecomeUnitVector(); vectorLine.Multiply(drawLength); graphics.DrawLine(vectorPen, halfSize, halfSize, Convert.ToSingle(halfSize + vectorLine.X), Convert.ToSingle(halfSize + vectorLine.Y)); } } } } // Exit Function return(retVal); }