Ejemplo n.º 1
0
        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;

        }
Ejemplo n.º 2
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;
                }
            }
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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);

        }
Ejemplo n.º 5
0
        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);

        }
Ejemplo n.º 6
0
        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;
        }
Ejemplo n.º 7
0
        private void DrawThruster(SolidBall ship, MyVector thruster)
        {
            MyVector worldThruster = _ship.Rotation.GetRotatedVector(thruster, true);
            worldThruster.Add(_ship.Position);

            DrawDot(worldThruster, 3f, Color.Silver);
        }
Ejemplo n.º 8
0
 public void DrawSolidBall(SolidBall ball, DrawMode mode, CollisionStyle collisionStyle, bool drawRed)
 {
     DrawSolidBall(ball, mode, collisionStyle, drawRed, 1d);
 }
Ejemplo n.º 9
0
        /// <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
        }
        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
        }
Ejemplo n.º 11
0
        private void radBallType_CheckedChanged(object sender, EventArgs e)
        {
            grpTriangleZ.Visible = false;
            grpTriangleZ2.Visible = false;
            _triangle1 = null;
            _triangle2 = null;
            _polygon1 = null;
            _polygon2 = null;

            if (radBallBall.Checked || radSolidBallSolidBall.Checked)
            {
                #region Balls

                Ball newBall1, newBall2;

                if (radBallBall.Checked)
                {
                    // Switch them out with a standard ball
                    newBall1 = new Ball(_ball1.Position.Clone(), new DoubleVector(0, 1, 0, 1, 0, 0), _ball1.Radius, _ball1.Mass, _ball1.Elasticity, _ball1.KineticFriction, _ball1.StaticFriction, _boundryLower, _boundryUpper);
                    newBall1.Velocity.StoreNewValues(_ball1.Velocity.Clone());

                    newBall2 = new Ball(_ball2.Position.Clone(), new DoubleVector(0, 1, 0, 1, 0, 0), _ball2.Radius, _ball2.Mass, _ball2.Elasticity, _ball2.KineticFriction, _ball2.StaticFriction, _boundryLower, _boundryUpper);
                    newBall2.Velocity.StoreNewValues(_ball2.Velocity.Clone());
                }
                else if (radSolidBallSolidBall.Checked)
                {
                    // Switch them out with solidballs
                    newBall1 = new SolidBall(_ball1.Position.Clone(), new DoubleVector(0, 1, 0, 1, 0, 0), _ball1.Radius, _ball1.Mass, _ball1.Elasticity, _ball1.KineticFriction, _ball1.StaticFriction, _boundryLower, _boundryUpper);
                    newBall1.Velocity.StoreNewValues(_ball1.Velocity.Clone());
                    ((SolidBall)newBall1).AngularVelocity.StoreNewValues(new MyVector(0, 0, 200));

                    newBall2 = new SolidBall(_ball2.Position.Clone(), new DoubleVector(0, 1, 0, 1, 0, 0), _ball2.Radius, _ball2.Mass, _ball2.Elasticity, _ball2.KineticFriction, _ball2.StaticFriction, _boundryLower, _boundryUpper);
                    newBall2.Velocity.StoreNewValues(_ball2.Velocity.Clone());
                    ((SolidBall)newBall2).AngularVelocity.StoreNewValues(new MyVector(0, 0, 200));
                }
                else
                {
                    MessageBox.Show("Unknown radio button", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                _ball1 = newBall1;
                _ball2 = newBall2;

                #endregion
            }
            else if (radSphereSphere.Checked)
            {
                #region Spheres

                // leave the balls alone?

                #endregion
            }
            else if (radLineTriangle.Checked || radSphereTriangle.Checked || radTriangleTriangle.Checked)
            {
                #region Triangles

                if (radLineTriangle.Checked)
                {
                    #region Line Triangle

                    // I will leave ball1 alone.  I will use that one's velocity as the line

                    grpTriangleZ.Visible = true;

                    // Make the the triangle
                    if (chkTrianglePerpendicular.Checked)
                    {
                        _triangle1 = new TriangleTest(_ball2.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), new Triangle(0, 0, -100, 0, 100, 0, 0, -100, 100));

                        radPoint1Neg.Enabled = radPoint1Pos.Enabled = radPoint1Zero.Enabled = false;
                        radPoint2Neg.Enabled = radPoint2Pos.Enabled = radPoint2Zero.Enabled = false;
                        radPoint3Neg.Enabled = radPoint3Pos.Enabled = radPoint3Zero.Enabled = false;
                    }
                    else
                    {
                        _triangle1 = new TriangleTest(_ball2.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), new Triangle(-150, -150, 0, 150, -150, 0, 0, 150, 0));

                        radPoint1Neg.Enabled = radPoint1Pos.Enabled = radPoint1Zero.Enabled = true;
                        radPoint2Neg.Enabled = radPoint2Pos.Enabled = radPoint2Zero.Enabled = true;
                        radPoint3Neg.Enabled = radPoint3Pos.Enabled = radPoint3Zero.Enabled = true;

                        radPoint1_CheckedChanged(this, new EventArgs());
                        radPoint2_CheckedChanged(this, new EventArgs());
                        radPoint3_CheckedChanged(this, new EventArgs());
                    }

                    #endregion
                }
                else if (radSphereTriangle.Checked)
                {
                    #region Sphere Triangle

                    // I will leave ball1 alone.  I won't use its velocity, just radius

                    grpTriangleZ.Visible = true;

                    // Make the the triangle
                    if (chkTrianglePerpendicular.Checked)
                    {
                        _triangle1 = new TriangleTest(_ball2.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), new Triangle(0, 0, -100, 0, 100, 0, 0, -100, 100));

                        radPoint1Neg.Enabled = radPoint1Pos.Enabled = radPoint1Zero.Enabled = false;
                        radPoint2Neg.Enabled = radPoint2Pos.Enabled = radPoint2Zero.Enabled = false;
                        radPoint3Neg.Enabled = radPoint3Pos.Enabled = radPoint3Zero.Enabled = false;
                    }
                    else
                    {
                        _triangle1 = new TriangleTest(_ball2.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), new Triangle(-150, -150, 0, 150, -150, 0, 0, 150, 0));

                        radPoint1Neg.Enabled = radPoint1Pos.Enabled = radPoint1Zero.Enabled = true;
                        radPoint2Neg.Enabled = radPoint2Pos.Enabled = radPoint2Zero.Enabled = true;
                        radPoint3Neg.Enabled = radPoint3Pos.Enabled = radPoint3Zero.Enabled = true;

                        radPoint1_CheckedChanged(this, new EventArgs());
                        radPoint2_CheckedChanged(this, new EventArgs());
                        radPoint3_CheckedChanged(this, new EventArgs());
                    }

                    #endregion
                }
                else if (radTriangleTriangle.Checked)
                {
                    #region Triangle Triangle

                    grpTriangleZ.Visible = true;
                    grpTriangleZ2.Visible = true;

                    #region Triangle1 (right side)

                    // Make the the triangle
                    if (chkTrianglePerpendicular.Checked)
                    {
                        _triangle1 = new TriangleTest(_ball2.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), new Triangle(0, 0, -100, 0, 100, 0, 0, -100, 100));

                        radPoint1Neg.Enabled = radPoint1Pos.Enabled = radPoint1Zero.Enabled = false;
                        radPoint2Neg.Enabled = radPoint2Pos.Enabled = radPoint2Zero.Enabled = false;
                        radPoint3Neg.Enabled = radPoint3Pos.Enabled = radPoint3Zero.Enabled = false;
                    }
                    else
                    {
                        _triangle1 = new TriangleTest(_ball2.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), new Triangle(-150, -150, 0, 150, -150, 0, 0, 150, 0));

                        radPoint1Neg.Enabled = radPoint1Pos.Enabled = radPoint1Zero.Enabled = true;
                        radPoint2Neg.Enabled = radPoint2Pos.Enabled = radPoint2Zero.Enabled = true;
                        radPoint3Neg.Enabled = radPoint3Pos.Enabled = radPoint3Zero.Enabled = true;

                        radPoint1_CheckedChanged(this, new EventArgs());
                        radPoint2_CheckedChanged(this, new EventArgs());
                        radPoint3_CheckedChanged(this, new EventArgs());
                    }

                    #endregion
                    #region Triangle2 (left side)

                    // Make the the triangle
                    if (chkTrianglePerpendicular2.Checked)
                    {
                        _triangle2 = new TriangleTest(_ball1.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), new Triangle(0, 0, -100, 0, 100, 0, 0, -100, 100));

                        radPoint1Neg2.Enabled = radPoint1Pos2.Enabled = radPoint1Zero2.Enabled = false;
                        radPoint2Neg2.Enabled = radPoint2Pos2.Enabled = radPoint2Zero2.Enabled = false;
                        radPoint3Neg2.Enabled = radPoint3Pos2.Enabled = radPoint3Zero2.Enabled = false;
                    }
                    else
                    {
                        _triangle2 = new TriangleTest(_ball1.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), new Triangle(-150, -150, 0, 150, -150, 0, 0, 150, 0));

                        radPoint1Neg2.Enabled = radPoint1Pos2.Enabled = radPoint1Zero2.Enabled = true;
                        radPoint2Neg2.Enabled = radPoint2Pos2.Enabled = radPoint2Zero2.Enabled = true;
                        radPoint3Neg2.Enabled = radPoint3Pos2.Enabled = radPoint3Zero2.Enabled = true;

                        radPoint1Changed2_CheckedChanged(this, new EventArgs());
                        radPoint2Changed2_CheckedChanged(this, new EventArgs());
                        radPoint3Changed2_CheckedChanged(this, new EventArgs());
                    }

                    #endregion

                    #endregion
                }
                else
                {
                    MessageBox.Show("Unknown radio button", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                #endregion
            }
            else
            {
                #region Polygons

                if (radSpherePolygon.Checked)
                {
                    #region Sphere Polygon

                    // I will leave ball1 alone.  I won't use its velocity, just radius

                    // Make the the polygon
                    //_polygon1 = new PolygonTest(_ball2.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), Polygon.CreateTetrahedron(_ball2.Radius * 2, true), _ball2.Radius * 2);
                    _polygon1 = new PolygonTest(_ball2.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), MyPolygon.CreateCube(_ball2.Radius * 5, true), _ball2.Radius * 4);

                    #endregion
                }
                else if (radPolygonPolygon.Checked)
                {
                    #region Polygon Polygon

                    // Polygon1 is on the right (so it uses ball2 as its source)
                    _polygon1 = new PolygonTest(_ball2.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), MyPolygon.CreateTetrahedron(_ball2.Radius * 2, true), _ball2.Radius * 2);
                    _polygon2 = new PolygonTest(_ball1.Position.Clone(), new DoubleVector(1, 0, 0, 0, 1, 0), MyPolygon.CreateCube(_ball1.Radius * 2, true), _ball2.Radius * 2);

                    #endregion
                }
                else
                {
                    MessageBox.Show("Unknown radio button", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                #endregion
            }
        }
Ejemplo n.º 12
0
        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;
        }
Ejemplo n.º 13
0
        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
        }
Ejemplo n.º 14
0
        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
        }