예제 #1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            double radius     = _rand.Next(Convert.ToInt32(MINRADIUSMASS), Convert.ToInt32(MAXRADIUSMASS));
            double mass       = GetMass(radius);
            double elasticity = GetElasticity();

            Ball ball = new Ball(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.BallUserDefined00, TokenGenerator.NextToken());

            _map.Add(blip);
        }
예제 #2
0
        private void btnLoad_Click(object sender, EventArgs e)
        {
            if (_map == null)
            {
                MessageBox.Show("Control hasn't been set up yet", "Load Scene", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            ListViewItem selectedItem = GetSelectedItem();

            if (selectedItem == null)
            {
                MessageBox.Show("Nothing Selected", "Load Scene", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (selectedItem.Index < 0 || selectedItem.Index >= _sceneBlips.Count)
            {
                MessageBox.Show("Lists out of sync", "Load Scene", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            _map.Clear(_ignoreTokens);

            foreach (RadarBlip blip in _sceneBlips[selectedItem.Index])
            {
                // If I don't clone them, then when the balls move, those new positions will be stored in my list
                _map.Add(CloneBlip(blip, _map));
            }
        }
예제 #3
0
        public void CanAddAndRemove()
        {
            var sourceNode = new Node(Utils.Id("foo"));
            var simpleMap  = new SimpleMap <NodeID, NodeID>();

            simpleMap.Init(sourceNode, db);
            for (int i = 0; i < 100; i++)
            {
                simpleMap.Add(Utils.Id($"foo/{i}"), Utils.Id("bar"));
            }
            for (int i = 0; i < 100; i += 2)
            {
                simpleMap.Remove(Utils.Id($"foo/{i}"));
            }
            for (int i = 0; i < 100; i++)
            {
                if (i % 2 == 1)
                {
                    Assert.Contains(Utils.Id($"foo/{i}"), simpleMap);
                }
                else
                {
                    Assert.DoesNotContain(Utils.Id($"foo/{i}"), simpleMap);
                }
            }
        }
예제 #4
0
        private void AddMultiBall(double radius, double mass)
        {
            // Physical Ball
            MyVector     pos       = Utility3D.GetRandomVector(BOUNDRY);
            DoubleVector dirFacing = new DoubleVector(1, 0, 0, 0, 1, 0);

            Ball ball = new Ball(pos, dirFacing, radius, mass, ELASTICITY, KINETICFRICTION, STATICFRICTION, _boundryLower, _boundryUpper);

            BallBlip blip = new BallBlip(ball, CollisionStyle.Standard, RadarBlipQual.BallUserDefined00, TokenGenerator.NextToken());

            _map.Add(blip);

            // WPF Rendering
            Geometry3D      geometry      = UtilityWPF.GetSphere(5, radius);
            Material        material      = new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(255, Convert.ToByte(_rand.Next(256)), Convert.ToByte(_rand.Next(256)), Convert.ToByte(_rand.Next(256)))));
            GeometryModel3D geometryModel = new GeometryModel3D(geometry, material);

            geometryModel.Transform = new Transform3DGroup();

            //TODO:  Tie this transform directly to the ball's velocity (the shpere class should take the transform group)
            Transform3DGroup group = geometryModel.Transform as Transform3DGroup;

            group.Children.Clear();
            group.Children.Add(new TranslateTransform3D(pos.X, pos.Y, pos.Z));

            _geometries.Add(geometryModel);
            _modelGroup.Children.Add(geometryModel);
        }
예제 #5
0
        private void Paste()
        {
            if (_myClipboard.Count == 0)
            {
                return;
            }

            _selectedObjects.Clear();

            foreach (RadarBlip blip in _myClipboard)
            {
                // Clone this object
                RadarBlip tempBlip = Scenes.CloneBlip(blip, _map);

                // Figure out where to place the pasted object
                MyVector newPosition = tempBlip.Sphere.Position - _clipboardPositionCenter;
                newPosition.Add(_curMousePoint);
                tempBlip.Sphere.Position.StoreNewValues(newPosition);

                // Add it
                _selectedObjects.Add(tempBlip.Token);
                _map.Add(tempBlip);
            }

            _mode = SelectionMode.Selected;
        }
예제 #6
0
        private void CommitObject()
        {
            Ball newObject;

            #region Get the base object to add

            if (_drawingBall != null)
            {
                newObject    = _drawingBall;
                _drawingBall = null;
            }
            else
            {
                newObject = BuildObject();
            }

            #endregion

            RadarBlipQual blipQual;
            #region Figure out the blipqual

            //TODO:  Define these as constants somewhere
            switch (_mode)
            {
            case AddingMode.AddBall:
                blipQual = RadarBlipQual.BallUserDefined00;
                break;

            case AddingMode.AddSolidBall:
                blipQual = RadarBlipQual.BallUserDefined01;
                break;

            case AddingMode.AddRigidBody:
                blipQual = RadarBlipQual.BallUserDefined02;
                break;

            default:
                throw new ApplicationException("Unknown AddingMode: " + _mode.ToString());
            }

            #endregion

            // Create a blip to contain this object
            BallBlip blip = new BallBlip(newObject, _newBallProps.CollisionStyle, blipQual, TokenGenerator.NextToken());

            // If this is a torqueball, then it will get the angular velocity.  I have to wait until now, because
            // the size could change during a draw (you don't see it spin during the drag anyway, because I
            // don't call it's timer, so there is no reason to set angular velocity before now.)
            StoreAngularVelocity(blip.Ball);

            // Add it to the map
            _map.Add(blip);

            if (_newBallProps.Temporary)
            {
                _tempObjects.Add(blip.Token);
            }
        }
예제 #7
0
        public void CanAddAndClear()
        {
            var sourceNode = new Node(Utils.Id("foo"));
            var simpleMap  = new SimpleMap <NodeID, NodeID>();

            simpleMap.Init(sourceNode, db);
            for (int i = 0; i < 100; i++)
            {
                simpleMap.Add(Utils.Id($"foo/{i}"), Utils.Id("bar"));
            }
            simpleMap.Clear();
            Assert.Empty(simpleMap);
        }
예제 #8
0
        public void CanAddAndIterate()
        {
            var sourceNode = new Node(Utils.Id("foo"));
            var simpleMap  = new SimpleMap <NodeID, NodeID>();

            simpleMap.Init(sourceNode, db);
            for (int i = 0; i < 100; i++)
            {
                simpleMap.Add(Utils.Id($"foo/{i}"), Utils.Id("bar"));
            }

            for (int i = 0; i < 100; i++)
            {
                simpleMap.Contains(new KeyValuePair <NodeID, NodeID>(Utils.Id($"foo/{i}"), Utils.Id("bar")));
                Assert.Contains(Utils.Id($"foo/{i}"), simpleMap.Keys);
            }
        }
예제 #9
0
        private void InsureBlipAddedRemoved(bool added)
        {
            if (added)// && !_cursorInMap)			// I can't trust that (they may have cleared all blips outside of this class
            {
                foreach (RadarBlip blip in _map.GetAllBlips())
                {
                    if (blip.Token == _cursorBlip.Token)
                    {
                        return;
                    }
                }

                // It's not in
                _map.Add(_cursorBlip);
                _cursorInMap = true;
            }
            else if (!added && _cursorInMap)
            {
                // Take it out
                _map.Remove(_cursorBlip.Token);
                _cursorInMap = false;
            }
        }
예제 #10
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
        }
예제 #11
0
        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
        }
예제 #12
0
        private bool Fire()
        {
            // Before I begin, try to grab some ammo
            //if(_useAmmoClip && _ammoClip.RemoveQuantity(_amtAmmoToPull, true) > 0)
            //{
            //    return false;
            //}

            // The ammo has been grabbed, bump the elapsed time structure
            _elapsedTime.InnerFiringRate = _firingModes[_activeFiringMode].InnerFiringRate;
            _elapsedTime.NumRoundsPerOuter++;

            // Fire each barrel
            foreach (Barrel barrel in _barrels)
            {
                #region Fire New Projectile

                // Create the position
                MyVector position = _ship.Ball.Position.Clone();
                if (barrel.Offset != null)
                {
                    position = _ship.Ball.Rotation.GetRotatedVector(barrel.Offset, true) + position;
                }

                // Create the direction facing
                DoubleVector dirFacing = _ship.Ball.DirectionFacing.Clone();
                if (barrel.Rotation != null)
                {
                    dirFacing = barrel.Rotation.GetRotatedVector(dirFacing, true);
                }

                // Make a ball
                Ball ball = null;
                if (_useBoundry)
                {
                    ball = new Ball(position, dirFacing, _projectileSettings.Radius, _projectileSettings.Mass, _boundryLower, _boundryUpper);
                }
                else
                {
                    ball = new Ball(position, dirFacing, _projectileSettings.Radius, _projectileSettings.Mass);
                }

                MyVector dirFacingUnit = dirFacing.Standard;
                dirFacingUnit.BecomeUnitVector();

                // Set the velocity
                ball.Velocity.StoreNewValues(dirFacingUnit * _projectileSettings.Speed);
                ball.Velocity.Add(_ship.Ball.Velocity);

                // Make a projectile
                Projectile projectile = new Projectile(ball, _ship.Token, _projectileSettings.IgnoreOtherProjectiles, _projectileSettings.Pain, _map, _projectileSettings.Qual, TokenGenerator.NextToken());

                // Set up explosion and fuse settings
                if (_projectileSettings.Explosion != null)
                {
                    projectile.SetExplosion(_projectileSettings.Explosion.Radius, _projectileSettings.Explosion.Duration, _projectileSettings.Explosion.Force);
                }
                if (_projectileSettings.Fuse != null)
                {
                    projectile.SetFuse(_projectileSettings.Fuse.Duration);
                }

                // Generate the kick
                if (_produceKick)
                {
                    #region Kick

                    MyVector kick = dirFacingUnit * _projectileSettings.Speed * (ball.Mass * -1d);

                    if (_ship.TorqueBall != null)
                    {
                        _ship.TorqueBall.ApplyExternalForce(ball.Position - _ship.Ball.Position, kick);
                    }
                    else
                    {
                        _ship.Ball.ExternalForce.Add(kick);
                    }

                    #endregion
                }

                // Hand the projectile to the map
                _map.Add(projectile);

                #endregion
            }

            // Exit function
            return(true);
        }