Beispiel #1
0
        public static MyVector GetRandomVectorSpherical2D(double maxRadius)
        {
            MyVector retVal = new MyVector(GetNearZeroValue(maxRadius), 0, 0);

            MyVector rotateAxis = new MyVector(0, 0, 1);
            double   radians    = GetNearZeroValue(2d * Math.PI);

            retVal.RotateAroundAxis(rotateAxis, radians);

            return(retVal);
        }
Beispiel #2
0
        public override void TimerTestPosition(double elapsedTime)
        {
            base.TimerTestPosition(elapsedTime);

            // Either remember the orig rotation, or restore to that orig rotation (as of PrepareForNew)
            if (_savedRotation == null)
            {
                _savedRotation = this.Rotation.Clone();
            }
            else
            {
                this.Rotation.StoreNewValues(_savedRotation);
            }

            // Remember the elapsed time that was passed in
            _elapsedTime = elapsedTime;

            // Figure out the new rotation (the body has been rotating at some velocity during the previous tick)
            if (!_angularVelocity.IsZero)
            {
                // Figure out what the angle will be
                double timedAngle = _angularVelocity.GetMagnitude();
                timedAngle *= elapsedTime;

                if (!_centerOfMass.IsZero)
                {
                    #region Rotate around center of mass

                    // Remember where the center of mass is in world coords
                    MyVector cmRotated = this.Rotation.GetRotatedVector(_centerOfMass, true);
                    MyVector cmWorld   = this.Position + cmRotated;

                    // Get the opposite of the cm
                    MyVector posRelativeToCM = cmRotated.Clone();
                    posRelativeToCM.Multiply(-1d);

                    // Rotate the center of position around the center of mass
                    posRelativeToCM.RotateAroundAxis(_angularVelocity, timedAngle);

                    // Now figure out the new center of position
                    this.Position.X = cmWorld.X + posRelativeToCM.X;
                    this.Position.Y = cmWorld.Y + posRelativeToCM.Y;
                    this.Position.Z = cmWorld.Z + posRelativeToCM.Z;

                    #endregion
                }

                // Rotate myself
                this.RotateAroundAxis(_angularVelocity, timedAngle);
            }
        }
Beispiel #3
0
        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 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);
        }
Beispiel #5
0
        public static MyVector GetRandomVectorSpherical2D(double maxRadius)
        {
            MyVector retVal = new MyVector(GetNearZeroValue(maxRadius), 0, 0);

            MyVector rotateAxis = new MyVector(0, 0, 1);
            double radians = GetNearZeroValue(2d * Math.PI);

            retVal.RotateAroundAxis(rotateAxis, radians);

            return retVal;
        }
        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;
        }
        private Bitmap DrawSize()
        {
            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 (_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 = _exposedProps.SizeIfFixed;
                    break;

                case BallProps.SizeModes.Random:
                    ballRadius = (_exposedProps.MinRandSize + _exposedProps.MaxRandSize) / 2d;
                    break;

                default:
                    throw new ApplicationException("Unknown BallProps.SizeModes: " + _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((_buttonSize - 2) * radiusPercent);
            float halfDrawWidth = drawWidth * .5f;
            float halfSize = (_buttonSize - 2) * .5f;

            Bitmap retVal = new Bitmap(_buttonSize, _buttonSize);
            using (Graphics graphics = Graphics.FromImage(retVal))
            {
                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));

                    graphics.DrawLine(radiusPen, halfSize, halfSize, Convert.ToSingle(halfSize + radiusLine.X), Convert.ToSingle(halfSize + radiusLine.Y));
                }

                // Draw Circle
                Color circleColor = Color.Black;
                if (_exposedProps.SizeMode == BallProps.SizeModes.Draw)
                {
                    circleColor = SystemColors.ControlDark;
                }

                using (Pen circlePen = new Pen(circleColor, 2f))
                {
                    graphics.DrawEllipse(circlePen, halfSize - halfDrawWidth, halfSize - halfDrawWidth, drawWidth, drawWidth);
                }
            }

            // Exit Function
            return retVal;
        }
        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 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 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);
            }

        }