Пример #1
0
        public ConverterRadiationToEnergy(EditorOptions options, ItemOptions itemOptions, ConverterRadiationToEnergyDNA dna, IContainer energyTanks, RadiationField radiationField)
            : base(options, dna, itemOptions.SolarPanel_Damage.HitpointMin, itemOptions.SolarPanel_Damage.HitpointSlope, itemOptions.SolarPanel_Damage.Damage)
        {
            _itemOptions    = itemOptions;
            _energyTanks    = energyTanks;
            _radiationField = radiationField;

            this.Design = new ConverterRadiationToEnergyDesign(options, true, dna.Shape);
            this.Design.SetDNA(dna);

            this.ClarityPercent_Front = 1d;
            this.ClarityPercent_Back  = 1d;

            Point3D  center;
            Vector3D normal;

            GetStats(out _mass, out center, out normal, out _scaleActual);

            // Store the center and normals
            Transform3DGroup transform = new Transform3DGroup();

            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(dna.Orientation)));
            transform.Children.Add(new TranslateTransform3D(dna.Position.ToVector()));

            _centerPoint = transform.Transform(center);
            _normalFront = transform.Transform(normal);
            _normalBack  = transform.Transform(normal * -1d);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                _itemOptions = new ItemOptions();

                #region Init World

                _boundryMin = new Point3D(-BOUNDRYSIZEHALF, -BOUNDRYSIZEHALF, -BOUNDRYSIZEHALF);
                _boundryMax = new Point3D(BOUNDRYSIZEHALF, BOUNDRYSIZEHALF, BOUNDRYSIZEHALF);

                _world = new World();
                _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating);

                List<Point3D[]> innerLines, outerLines;
                _world.SetCollisionBoundry(out innerLines, out outerLines, _boundryMin, _boundryMax);

                //TODO: Only draw the boundry lines if options say to

                #endregion
                #region Materials

                _materialManager = new MaterialManager(_world);

                // Wall
                Game.Newt.v2.NewtonDynamics.Material material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .1d;
                _material_Wall = _materialManager.AddMaterial(material);

                // Bot
                material = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Bot = _materialManager.AddMaterial(material);

                // Exploding Bot
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.IsCollidable = false;
                _material_ExplodingBot = _materialManager.AddMaterial(material);

                // Food
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .1d;
                _material_Food = _materialManager.AddMaterial(material);

                // Egg
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .5d;
                _material_Egg = _materialManager.AddMaterial(material);

                // Projectile
                material = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Projectile = _materialManager.AddMaterial(material);

                // Collisions
                _materialManager.RegisterCollisionEvent(_material_Bot, _material_Bot, Collision_BotBot);
                _materialManager.RegisterCollisionEvent(_material_Bot, _material_Food, Collision_BotFood);
                //TODO: May want to listen to projectile collisions

                #endregion
                #region Trackball

                // Trackball
                _trackball = new TrackBallRoam(_camera);
                _trackball.KeyPanScale = 15d;
                _trackball.EventSource = grdViewPort;		//NOTE:  If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null)
                _trackball.AllowZoomOnMouseWheel = true;
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete_NoLeft));
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.Keyboard_ASDW_In));
                _trackball.ShouldHitTestOnOrbit = true;
                //_trackball.UserMovedCamera += new EventHandler<UserMovedCameraArgs>(Trackball_UserMovedCamera);
                //_trackball.GetOrbitRadius += new EventHandler<GetOrbitRadiusArgs>(Trackball_GetOrbitRadius);

                #endregion
                #region Camera Pool

                //TODO: Make the number of threads more configurable, look at how many processors there are
                //_cameraPool = new CameraPool(2, Colors.Black);
                _cameraPool = new CameraPool(1, Colors.Black);

                #endregion
                #region Map

                _map = new Map(_viewport, _cameraPool, _world)
                {
                    SnapshotFequency_Milliseconds = 250,        // 125
                    SnapshotMaxItemsPerNode = 10,
                    ShouldBuildSnapshots = true,
                    ShouldShowSnapshotLines = false,
                    ShouldSnapshotCentersDrift = true,
                };

                _updateManager = new UpdateManager(
                    new Type[] { typeof(Swimbot) },
                    new Type[] { typeof(Swimbot) },
                    _map);

                #endregion
                #region Fields

                _radiation = new RadiationField()
                {
                    AmbientRadiation = 0d,
                };

                //_gravity = new GravityFieldUniform()
                //{
                //    Gravity = new Vector3D(0, 0, 0),
                //};

                //TODO: Support a uniform fluid
                //FluidField

                #endregion
                #region ItemSelectDragLogic

                _selectionLogic = new ItemSelectDragLogic(_map, _camera, _viewport, grdViewPort)
                {
                    ShouldMoveItemWithSpring = true,
                    ShouldSpringCauseTorque = false,
                    SpringColor = null,     // Colors.Chartreuse
                    ShowDebugVisuals = false,       // true
                };

                _selectionLogic.SelectableTypes.Add(typeof(Bot));
                _selectionLogic.SelectableTypes.Add(typeof(Mineral));
                _selectionLogic.SelectableTypes.Add(typeof(Egg));

                _selectionLogic.ItemSelected += new EventHandler<ItemSelectedArgs>(SelectionLogic_ItemSelected);

                #endregion

                _world.UnPause();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #3
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                #region Init World

                _boundryMin = new Point3D(-100, -100, -100);
                _boundryMax = new Point3D(100, 100, 100);

                _world = new World();
                _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating);

                List<Point3D[]> innerLines, outerLines;
                _world.SetCollisionBoundry(out innerLines, out outerLines, _boundryMin, _boundryMax);

                // Don't bother with the boundry lines.  It looks funny with a partial viewport
                //// Draw the lines
                //_boundryLines = new ScreenSpaceLines3D(true);
                //_boundryLines.Thickness = 1d;
                //_boundryLines.Color = _colors.BoundryLines;
                //_viewport.Children.Add(_boundryLines);

                //foreach (Point3D[] line in innerLines)
                //{
                //    _boundryLines.AddLine(line[0], line[1]);
                //}

                #endregion
                #region Materials

                _materialManager = new MaterialManager(_world);

                // Ship
                var material = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Ship = _materialManager.AddMaterial(material);

                //_materialManager.RegisterCollisionEvent(_material_Terrain, _material_Bean, Collision_BeanTerrain);

                #endregion
                #region Trackball

                // Trackball
                _trackball = new TrackBallRoam(_camera);
                //_trackball.KeyPanScale = 15d;
                _trackball.EventSource = pnlViewport;		//NOTE:  If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null)
                _trackball.AllowZoomOnMouseWheel = true;
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));
                //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
                _trackball.ShouldHitTestOnOrbit = false;

                // Trackball
                _trackballNeural = new TrackBallRoam(_cameraNeural);
                //_trackballNeural.KeyPanScale = 15d;
                _trackballNeural.EventSource = pnlViewportNeural;		//NOTE:  If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null)
                _trackballNeural.AllowZoomOnMouseWheel = true;
                _trackballNeural.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));
                //_trackballNeural.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
                _trackballNeural.ShouldHitTestOnOrbit = false;

                #endregion
                #region Map

                //_map = new Map(_viewport, null, _world);
                //_map.SnapshotFequency_Milliseconds = 125;
                //_map.SnapshotMaxItemsPerNode = 10;
                //_map.ShouldBuildSnapshots = false;// true;
                //_map.ShouldShowSnapshotLines = false;
                //_map.ShouldSnapshotCentersDrift = true;

                #endregion
                #region Fields

                _radiation = new RadiationField()
                {
                    AmbientRadiation = 0d,
                };

                _gravityField = new GravityFieldUniform();

                #endregion

                // Trackball Controls
                SetupGravityTrackball();

                UpdateGravity();

                _world.UnPause();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                double terrainHeight = TERRAINRADIUS / 20d;

                #region Load last save

                _session = new FlyingBeanSession();
                _options = new FlyingBeanOptions();
                _itemOptions = new ItemOptions();

                _panelFile = new PanelFile(null, _session, _options, _itemOptions, GetDefaultBeans());
                _panelFile.SessionChanged += new EventHandler(PanelFile_SessionChanged);
                if (!_panelFile.TryLoadLastSave(false))
                {
                    _panelFile.New(false, false);		// by calling new, all of the options initialization is done by the file panel instead of doing it here
                }

                #endregion

                #region Winners

                _winnerManager = new WinnerManager(_options.WinnersLive, _options.WinnerCandidates, _options.WinnersFinal, _options.FinalistCount);

                #endregion
                #region Init World

                double boundryXY = TERRAINRADIUS * 1.25d;

                _boundryMin = new Point3D(-boundryXY, -boundryXY, terrainHeight * -2d);
                _boundryMax = new Point3D(boundryXY, boundryXY, TERRAINRADIUS * 25d);

                _world = new World();
                _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating);

                List<Point3D[]> innerLines, outerLines;
                _world.SetCollisionBoundry(out innerLines, out outerLines, _boundryMin, _boundryMax);

                // Draw the lines
                _boundryLines = new ScreenSpaceLines3D(true)
                {
                    Thickness = 1d,
                    Color = _colors.BoundryLines,
                };
                _viewport.Children.Add(_boundryLines);

                foreach (Point3D[] line in innerLines)
                {
                    _boundryLines.AddLine(line[0], line[1]);
                }

                #endregion
                #region Materials

                _materialManager = new MaterialManager(_world);

                // Terrain
                Game.Newt.v2.NewtonDynamics.Material material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .1d;
                _material_Terrain = _materialManager.AddMaterial(material);

                // Bean
                material = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Bean = _materialManager.AddMaterial(material);

                // Exploding Bean
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.IsCollidable = false;
                _material_ExplodingBean = _materialManager.AddMaterial(material);

                // Projectile
                material = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Projectile = _materialManager.AddMaterial(material);

                _materialManager.RegisterCollisionEvent(0, _material_Bean, Collision_BeanTerrain);		// zero should be the boundry (it should be the default material if no other is applied)
                _materialManager.RegisterCollisionEvent(_material_Terrain, _material_Bean, Collision_BeanTerrain);
                _materialManager.RegisterCollisionEvent(_material_Bean, _material_Bean, Collision_BeanBean);

                #endregion
                #region Trackball

                // Trackball
                _trackball = new TrackBallRoam(_camera);
                _trackball.KeyPanScale = 15d;
                _trackball.EventSource = grdViewPort;		//NOTE:  If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null)
                _trackball.AllowZoomOnMouseWheel = true;
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete_NoLeft));
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.Keyboard_ASDW_In));
                _trackball.ShouldHitTestOnOrbit = true;
                _trackball.UserMovedCamera += new EventHandler<UserMovedCameraArgs>(Trackball_UserMovedCamera);
                _trackball.GetOrbitRadius += new EventHandler<GetOrbitRadiusArgs>(Trackball_GetOrbitRadius);

                #endregion
                #region Map

                _map = new Map(_viewport, null, _world)
                {
                    SnapshotFequency_Milliseconds = 125,
                    SnapshotMaxItemsPerNode = 10,
                    ShouldBuildSnapshots = false,
                    ShouldShowSnapshotLines = false,
                    ShouldSnapshotCentersDrift = true,
                };

                _updateManager = new UpdateManager(
                    new Type[] { typeof(Bean) },
                    new Type[] { typeof(Bean) },
                    _map);

                #endregion
                #region Terrain

                //TODO: Texture map this so it's not so boring
                #region WPF Model (plus collision hull)

                // Material
                MaterialGroup materials = new MaterialGroup();
                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(_colors.Terrain)));
                materials.Children.Add(_colors.TerrainSpecular);

                // Geometry Model
                GeometryModel3D geometry = new GeometryModel3D();
                geometry.Material = materials;
                geometry.BackMaterial = materials;

                geometry.Geometry = UtilityWPF.GetCylinder_AlongX(100, TERRAINRADIUS, terrainHeight);
                CollisionHull hull = CollisionHull.CreateCylinder(_world, 0, TERRAINRADIUS, terrainHeight, null);

                // Transform
                Transform3DGroup transform = new Transform3DGroup();		// rotate needs to be added before translate
                transform.Children.Add(new RotateTransform3D(new AxisAngleRotation3D(new Vector3D(0, 1, 0), -90)));
                transform.Children.Add(new TranslateTransform3D(new Vector3D(0, 0, terrainHeight / -2d)));		// I want the objects to be able to add to z=0

                // Model Visual
                ModelVisual3D model = new ModelVisual3D();
                model.Content = geometry;
                model.Transform = transform;

                // Add to the viewport
                _viewport.Children.Add(model);

                #endregion

                // Make a physics body that represents this shape
                _terrain = new Body(hull, transform.Value, 0, new Visual3D[] { model });		// using zero mass tells newton it's static scenery (stuff bounces off of it, but it will never move)
                hull.Dispose();
                _terrain.MaterialGroupID = _material_Terrain;

                #endregion
                #region Fields

                // gravity was done by the file panel

                _radiation = new RadiationField()
                {
                    AmbientRadiation = 0d,
                };

                _boundryField = new BoundryField(.5d, 7500d, 2d, _boundryMin, _boundryMax);

                #endregion

                // Doing this so that if they hit the import button, it will call a method in beantypes (not the best design, but it works)
                _panelBeanTypes = new PanelBeanTypes(_options, _world);
                _panelFile.BeanTypesPanel = _panelBeanTypes;

                this.TotalBeansText = _options.TotalBeans.ToString("N0");

                _world.UnPause();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #5
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                _itemOptions = new ItemOptions();

                #region Init World

                _boundryMin = new Point3D(-BOUNDRYSIZEHALF, -BOUNDRYSIZEHALF, -BOUNDRYSIZEHALF);
                _boundryMax = new Point3D(BOUNDRYSIZEHALF, BOUNDRYSIZEHALF, BOUNDRYSIZEHALF);

                _world           = new World();
                _world.Updating += new EventHandler <WorldUpdatingArgs>(World_Updating);

                _world.SetCollisionBoundry(_boundryMin, _boundryMax);

                //TODO: Only draw the boundry lines if options say to

                #endregion
                #region Materials

                _materialManager = new MaterialManager(_world);

                // Wall
                Game.Newt.v2.NewtonDynamics.Material material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .1d;
                _material_Wall      = _materialManager.AddMaterial(material);

                // Bot
                material      = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Bot = _materialManager.AddMaterial(material);

                // Exploding Bot
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.IsCollidable  = false;
                _material_ExplodingBot = _materialManager.AddMaterial(material);

                // Food
                material            = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .1d;
                _material_Food      = _materialManager.AddMaterial(material);

                // Egg
                material            = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .5d;
                _material_Egg       = _materialManager.AddMaterial(material);

                // Projectile
                material             = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Projectile = _materialManager.AddMaterial(material);

                // Collisions
                _materialManager.RegisterCollisionEvent(_material_Bot, _material_Bot, Collision_BotBot);
                _materialManager.RegisterCollisionEvent(_material_Bot, _material_Food, Collision_BotFood);
                //TODO: May want to listen to projectile collisions

                #endregion
                #region Trackball

                // Trackball
                _trackball                       = new TrackBallRoam(_camera);
                _trackball.KeyPanScale           = 15d;
                _trackball.EventSource           = grdViewPort; //NOTE:  If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null)
                _trackball.AllowZoomOnMouseWheel = true;
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete_NoLeft));
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.Keyboard_ASDW_In));
                _trackball.ShouldHitTestOnOrbit = true;
                //_trackball.UserMovedCamera += new EventHandler<UserMovedCameraArgs>(Trackball_UserMovedCamera);
                //_trackball.GetOrbitRadius += new EventHandler<GetOrbitRadiusArgs>(Trackball_GetOrbitRadius);

                #endregion
                #region Camera Pool

                //TODO: Make the number of threads more configurable, look at how many processors there are
                //_cameraPool = new CameraPool(2, Colors.Black);
                _cameraPool = new CameraPool(1, Colors.Black);

                #endregion
                #region Map

                _map = new Map(_viewport, _cameraPool, _world)
                {
                    SnapshotFequency_Milliseconds = 250,        // 125
                    SnapshotMaxItemsPerNode       = 10,
                    ShouldBuildSnapshots          = true,
                    ShouldShowSnapshotLines       = false,
                    ShouldSnapshotCentersDrift    = true,
                };

                _updateManager = new UpdateManager(
                    new Type[] { typeof(Swimbot) },
                    new Type[] { typeof(Swimbot) },
                    _map);

                #endregion
                #region Fields

                _radiation = new RadiationField()
                {
                    AmbientRadiation = 0d,
                };

                //_gravity = new GravityFieldUniform()
                //{
                //    Gravity = new Vector3D(0, 0, 0),
                //};

                //TODO: Support a uniform fluid
                //FluidField

                #endregion
                #region ItemSelectDragLogic

                _selectionLogic = new ItemSelectDragLogic(_map, _camera, _viewport, grdViewPort)
                {
                    ShouldMoveItemWithSpring = true,
                    ShouldSpringCauseTorque  = false,
                    SpringColor      = null,  // Colors.Chartreuse
                    ShowDebugVisuals = false, // true
                };

                _selectionLogic.SelectableTypes.Add(typeof(Bot));
                _selectionLogic.SelectableTypes.Add(typeof(Mineral));
                _selectionLogic.SelectableTypes.Add(typeof(Egg <ShipDNA>));

                _selectionLogic.ItemSelected += new EventHandler <ItemSelectedArgs>(SelectionLogic_ItemSelected);

                #endregion

                _world.UnPause();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                #region Trackball

                // Trackball
                _trackball = new TrackBallRoam(_camera);
                _trackball.KeyPanScale = 1d;
                _trackball.EventSource = grdViewPort;		//NOTE:  If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null)
                _trackball.AllowZoomOnMouseWheel = true;

                #region copied from MouseComplete_NoLeft - middle button changed

                TrackBallMapping complexMapping = null;

                // Middle Button
                complexMapping = new TrackBallMapping(CameraMovement.RotateAroundLookDirection_AutoScroll);
                complexMapping.Add(MouseButton.Middle);
                complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
                complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
                _trackball.Mappings.Add(complexMapping);
                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.RotateAroundLookDirection, MouseButton.Middle, new Key[] { Key.LeftCtrl, Key.RightCtrl }));

                complexMapping = new TrackBallMapping(CameraMovement.Zoom_AutoScroll);
                complexMapping.Add(MouseButton.Middle);
                complexMapping.Add(new Key[] { Key.LeftShift, Key.RightShift });
                complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
                _trackball.Mappings.Add(complexMapping);
                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Zoom, MouseButton.Middle, new Key[] { Key.LeftShift, Key.RightShift }));

                //retVal.Add(new TrackBallMapping(CameraMovement.Pan_AutoScroll, MouseButton.Middle));
                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Pan, MouseButton.Middle));

                // Left+Right Buttons (emulate middle)
                complexMapping = new TrackBallMapping(CameraMovement.RotateAroundLookDirection_AutoScroll);
                complexMapping.Add(MouseButton.Left);
                complexMapping.Add(MouseButton.Right);
                complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
                complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
                _trackball.Mappings.Add(complexMapping);

                complexMapping = new TrackBallMapping(CameraMovement.RotateAroundLookDirection);
                complexMapping.Add(MouseButton.Left);
                complexMapping.Add(MouseButton.Right);
                complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
                _trackball.Mappings.Add(complexMapping);

                complexMapping = new TrackBallMapping(CameraMovement.Zoom_AutoScroll);
                complexMapping.Add(MouseButton.Left);
                complexMapping.Add(MouseButton.Right);
                complexMapping.Add(new Key[] { Key.LeftShift, Key.RightShift });
                complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
                _trackball.Mappings.Add(complexMapping);

                complexMapping = new TrackBallMapping(CameraMovement.Zoom);
                complexMapping.Add(MouseButton.Left);
                complexMapping.Add(MouseButton.Right);
                complexMapping.Add(new Key[] { Key.LeftShift, Key.RightShift });
                _trackball.Mappings.Add(complexMapping);

                //complexMapping = new TrackBallMapping(CameraMovement.Pan_AutoScroll);
                complexMapping = new TrackBallMapping(CameraMovement.Pan);
                complexMapping.Add(MouseButton.Left);
                complexMapping.Add(MouseButton.Right);
                _trackball.Mappings.Add(complexMapping);

                // Right Button
                complexMapping = new TrackBallMapping(CameraMovement.RotateInPlace_AutoScroll);
                complexMapping.Add(MouseButton.Right);
                complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
                complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
                _trackball.Mappings.Add(complexMapping);
                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.RotateInPlace, MouseButton.Right, new Key[] { Key.LeftCtrl, Key.RightCtrl }));

                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Orbit_AutoScroll, MouseButton.Right, new Key[] { Key.LeftAlt, Key.RightAlt }));
                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Orbit, MouseButton.Right));

                #endregion

                //_trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.Keyboard_ASDW_In));		// let the ship get asdw instead of the camera
                //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
                _trackball.ShouldHitTestOnOrbit = true;

                #endregion

                #region Init World

                // Set the size of the world to something a bit random (gets boring when it's always the same size)
                double halfSize = 50d;
                _boundryMin = new Point3D(-halfSize, -halfSize, -halfSize);
                _boundryMax = new Point3D(halfSize, halfSize, halfSize);

                _world = new World();
                _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating);

                List<Point3D[]> innerLines, outerLines;
                _world.SetCollisionBoundry(out innerLines, out outerLines, _boundryMin, _boundryMax);

                // Draw the lines
                _boundryLines = new ScreenSpaceLines3D(true);
                _boundryLines.Thickness = 1d;
                _boundryLines.Color = _colors.BoundryLines;
                _viewport.Children.Add(_boundryLines);

                foreach (Point3D[] line in innerLines)
                {
                    _boundryLines.AddLine(line[0], line[1]);
                }

                #endregion
                #region Materials

                _materialManager = new MaterialManager(_world);

                // Part
                Game.Newt.v2.NewtonDynamics.Material material = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Part = _materialManager.AddMaterial(material);

                // Ship
                material = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Ship = _materialManager.AddMaterial(material);

                //_materialManager.RegisterCollisionEvent(_material_Ship, _material_Asteroid, Collision_Ship);

                #endregion
                #region Map

                _map = new Map(_viewport, null, _world);
                //_map.SnapshotFequency_Milliseconds = 125;
                //_map.SnapshotMaxItemsPerNode = 10;
                _map.ShouldBuildSnapshots = false;
                //_map.ShouldShowSnapshotLines = true;
                //_map.ShouldSnapshotCentersDrift = false;

                #endregion
                #region Fields

                _radiation = new RadiationField();
                _radiation.AmbientRadiation = 1d;

                _gravity = new GravityFieldUniform();

                #endregion

                _world.UnPause();

                #region Solver Timer

                _solverTimer = new DispatcherTimer();
                _solverTimer.Interval = TimeSpan.FromMilliseconds(trkSimSpeed.Value);
                _solverTimer.Tick += new EventHandler(SolverTimer_Tick);
                _solverTimer.IsEnabled = true;

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public ConverterRadiationToEnergy(EditorOptions options, ItemOptions itemOptions, ConverterRadiationToEnergyDNA dna, IContainer energyTanks, RadiationField radiationField)
            : base(options, dna, itemOptions.SolarPanel_Damage.HitpointMin, itemOptions.SolarPanel_Damage.HitpointSlope, itemOptions.SolarPanel_Damage.Damage)
        {
            _itemOptions = itemOptions;
            _energyTanks = energyTanks;
            _radiationField = radiationField;

            this.Design = new ConverterRadiationToEnergyDesign(options, true, dna.Shape);
            this.Design.SetDNA(dna);

            this.ClarityPercent_Front = 1d;
            this.ClarityPercent_Back = 1d;

            Point3D center;
            Vector3D normal;
            GetStats(out _mass, out center, out normal, out _scaleActual);

            // Store the center and normals
            Transform3DGroup transform = new Transform3DGroup();
            transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(dna.Orientation)));
            transform.Children.Add(new TranslateTransform3D(dna.Position.ToVector()));

            _centerPoint = transform.Transform(center);
            _normalFront = transform.Transform(normal);
            _normalBack = transform.Transform(normal * -1d);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                #region Trackball

                // Trackball
                _trackball = new TrackBallRoam(_camera);
                _trackball.KeyPanScale = 1d;
                _trackball.EventSource = grdViewPort;		//NOTE:  If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null)
                _trackball.AllowZoomOnMouseWheel = true;

                #region copied from MouseComplete_NoLeft - middle button changed

                TrackBallMapping complexMapping = null;

                // Middle Button
                complexMapping = new TrackBallMapping(CameraMovement.RotateAroundLookDirection_AutoScroll);
                complexMapping.Add(MouseButton.Middle);
                complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
                complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
                _trackball.Mappings.Add(complexMapping);
                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.RotateAroundLookDirection, MouseButton.Middle, new Key[] { Key.LeftCtrl, Key.RightCtrl }));

                complexMapping = new TrackBallMapping(CameraMovement.Zoom_AutoScroll);
                complexMapping.Add(MouseButton.Middle);
                complexMapping.Add(new Key[] { Key.LeftShift, Key.RightShift });
                complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
                _trackball.Mappings.Add(complexMapping);
                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Zoom, MouseButton.Middle, new Key[] { Key.LeftShift, Key.RightShift }));

                //retVal.Add(new TrackBallMapping(CameraMovement.Pan_AutoScroll, MouseButton.Middle));
                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Pan, MouseButton.Middle));

                // Left+Right Buttons (emulate middle)
                complexMapping = new TrackBallMapping(CameraMovement.RotateAroundLookDirection_AutoScroll);
                complexMapping.Add(MouseButton.Left);
                complexMapping.Add(MouseButton.Right);
                complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
                complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
                _trackball.Mappings.Add(complexMapping);

                complexMapping = new TrackBallMapping(CameraMovement.RotateAroundLookDirection);
                complexMapping.Add(MouseButton.Left);
                complexMapping.Add(MouseButton.Right);
                complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
                _trackball.Mappings.Add(complexMapping);

                complexMapping = new TrackBallMapping(CameraMovement.Zoom_AutoScroll);
                complexMapping.Add(MouseButton.Left);
                complexMapping.Add(MouseButton.Right);
                complexMapping.Add(new Key[] { Key.LeftShift, Key.RightShift });
                complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
                _trackball.Mappings.Add(complexMapping);

                complexMapping = new TrackBallMapping(CameraMovement.Zoom);
                complexMapping.Add(MouseButton.Left);
                complexMapping.Add(MouseButton.Right);
                complexMapping.Add(new Key[] { Key.LeftShift, Key.RightShift });
                _trackball.Mappings.Add(complexMapping);

                //complexMapping = new TrackBallMapping(CameraMovement.Pan_AutoScroll);
                complexMapping = new TrackBallMapping(CameraMovement.Pan);
                complexMapping.Add(MouseButton.Left);
                complexMapping.Add(MouseButton.Right);
                _trackball.Mappings.Add(complexMapping);

                // Right Button
                complexMapping = new TrackBallMapping(CameraMovement.RotateInPlace_AutoScroll);
                complexMapping.Add(MouseButton.Right);
                complexMapping.Add(new Key[] { Key.LeftCtrl, Key.RightCtrl });
                complexMapping.Add(new Key[] { Key.LeftAlt, Key.RightAlt });
                _trackball.Mappings.Add(complexMapping);
                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.RotateInPlace, MouseButton.Right, new Key[] { Key.LeftCtrl, Key.RightCtrl }));

                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Orbit_AutoScroll, MouseButton.Right, new Key[] { Key.LeftAlt, Key.RightAlt }));
                _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Orbit, MouseButton.Right));

                #endregion

                //_trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.Keyboard_ASDW_In));		// let the ship get asdw instead of the camera
                //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
                _trackball.ShouldHitTestOnOrbit = true;

                #endregion

                #region Init World

                _world = new World();

                double halfSize = 200d;
                List<Point3D[]> innerLines, outerLines;
                _world.SetCollisionBoundry(out innerLines, out outerLines, new Point3D(-halfSize, -halfSize, -halfSize), new Point3D(halfSize, halfSize, halfSize));

                #endregion
                #region Fields

                _radiation = new RadiationField();
                _radiation.AmbientRadiation = 1d;

                _gravity = new GravityFieldUniform();

                #endregion
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #9
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                _itemOptions = new ItemOptions();
                _itemOptions.Thruster_StrengthRatio *= 4.5;
                _itemOptions.FuelToThrustRatio *= .03;
                _itemOptions.Projectile_Color = UtilityWPF.ColorFromHex("FFE330");        // using bee/wasp colors, because white looks too much like the stars

                _progressBars = new ShipProgressBarManager(pnlProgressBars);
                _progressBars.Foreground = new SolidColorBrush(UtilityWPF.ColorFromHex("BBB"));

                #region Init World

                // Set the size of the world to something a bit random (gets boring when it's always the same size)
                double halfSize = 325 + StaticRandom.Next(500);
                //halfSize *= 2;
                _boundryMin = new Point3D(-halfSize, -halfSize, -35);
                _boundryMax = new Point3D(halfSize, halfSize, 35);

                _world = new World();
                _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating);

                List<Point3D[]> innerLines, outerLines;
                _world.SetCollisionBoundry(out innerLines, out outerLines, _boundryMin, _boundryMax);

                // Draw the lines
                _boundryLines = new ScreenSpaceLines3D(true);
                _boundryLines.Thickness = 1d;
                _boundryLines.Color = WorldColors.BoundryLines;
                _viewport.Children.Add(_boundryLines);

                foreach (Point3D[] line in innerLines)
                {
                    _boundryLines.AddLine(line[0], line[1]);
                }

                #endregion
                #region Materials

                _materialManager = new MaterialManager(_world);

                // Ship
                Game.Newt.v2.NewtonDynamics.Material material = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Ship = _materialManager.AddMaterial(material);

                // Exploding Ship
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.IsCollidable = false;
                _material_ExplodingShip = _materialManager.AddMaterial(material);

                // Space Station (force field)
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.IsCollidable = false;
                //material.Elasticity = .99d;       // uncomment these if it should be collidable (it's an ellipse, and briefly shows a force field)
                //material.StaticFriction = .02d;
                //material.KineticFriction = .01d;
                _material_SpaceStation = _materialManager.AddMaterial(material);

                //_materialManager.RegisterCollisionEvent(_material_SpaceStation, _material_Asteroid, Collision_SpaceStation);
                //_materialManager.RegisterCollisionEvent(_material_SpaceStation, _material_Mineral, Collision_SpaceStation);

                // Mineral
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .5d;
                material.StaticFriction = .9d;
                material.KineticFriction = .4d;
                _material_Mineral = _materialManager.AddMaterial(material);

                // Asteroid
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .25d;
                material.StaticFriction = .9d;
                material.KineticFriction = .75d;
                _material_Asteroid = _materialManager.AddMaterial(material);

                // Projectile
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .95d;
                _material_Projectile = _materialManager.AddMaterial(material);

                // Swarmbot
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .95d;
                _material_SwarmBot = _materialManager.AddMaterial(material);

                // Collisions
                _materialManager.RegisterCollisionEvent(_material_Ship, _material_Mineral, Collision_ShipMineral);
                _materialManager.RegisterCollisionEvent(_material_Ship, _material_Asteroid, Collision_ShipAsteroid);
                _materialManager.RegisterCollisionEvent(_material_Ship, _material_Projectile, Collision_ShipProjectile);

                _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_Projectile, Collision_AsteroidProjectile);
                _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_SwarmBot, Collision_AsteroidSwarmBot);
                _materialManager.RegisterCollisionEvent(_material_Asteroid, _material_Asteroid, Collision_AsteroidAsteroid);

                #endregion
                #region Trackball

                //TODO: Only use this when debugging the scene

                //// Trackball
                //_trackball = new TrackBallRoam(_camera);
                //_trackball.KeyPanScale = 15d;
                //_trackball.EventSource = grdViewPort;		//NOTE:  If this control doesn't have a background color set, the trackball won't see events (I think transparent is ok, just not null)
                //_trackball.AllowZoomOnMouseWheel = true;
                //_trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete_NoLeft));
                ////_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
                //_trackball.ShouldHitTestOnOrbit = true;

                #endregion
                #region Map

                _map = new Map(_viewport, null, _world);
                //_map.SnapshotFequency_Milliseconds = 250;     // just use the map's default values
                //_map.SnapshotMaxItemsPerNode = 13;
                _map.ShouldBuildSnapshots = true;
                _map.ShouldShowSnapshotLines = false;
                _map.ShouldSnapshotCentersDrift = true;

                _map.ItemRemoved += new EventHandler<MapItemArgs>(Map_ItemRemoved);

                #endregion
                #region Radiation

                //TODO: Make radiation sources instead of a constant ambient -- sort of mini stars, or something manmade looking
                _radiation = new RadiationField()
                {
                    AmbientRadiation = 1,
                };

                #endregion
                #region UpdateManager

                //TODO: UpdateManager needs to inspect types as they are added to the map (map's ItemAdded event)
                _updateManager = new UpdateManager(
                    new Type[] { typeof(ShipPlayer), typeof(SpaceStation2D), typeof(Projectile), typeof(Asteroid), typeof(SwarmBot1b) },
                    new Type[] { typeof(ShipPlayer), typeof(SwarmBot1b) },
                    _map);

                #endregion
                #region Brush Strokes

                _brushStrokes = new SwarmObjectiveStrokes(_world.WorldClock, _itemOptions.SwarmBay_BirthSize * 4, 6);

                // This would be for drawing the strokes
                //_brushStrokes.PointsChanged += BrushStrokes_PointsChanged;

                #endregion
                #region Player

                _player = new Player();
                _player.Credits = 10;

                _player.ShipChanged += new EventHandler<ShipChangedArgs>(Player_ShipChanged);

                #endregion
                #region Minimap

                _miniMap = new MinimapHelper(_map, _viewportMap);

                #endregion
                #region Camera Helper

                _cameraHelper = new CameraHelper(_player, _camera, _cameraMap, _miniMap);

                #endregion
                #region MapPopulationManager

                _mapPopulationManager = new MapPopulationManager(_map, _world, new Point3D(_boundryMin.X, _boundryMin.Y, 0), new Point3D(_boundryMax.X, _boundryMax.Y, 0), _material_Asteroid, _material_Mineral, GetAsteroidMassByRadius, GetMineralsFromDestroyedAsteroid, ItemOptionsAstMin2D.MINASTEROIDRADIUS);
                _updateManager.AddNonMapItem(_mapPopulationManager, TokenGenerator.NextToken());

                #endregion
                #region MapForcesManager

                _mapForcesManager = new MapForcesManager(_map, _boundryMin, _boundryMax);
                _updateManager.AddNonMapItem(_mapForcesManager, TokenGenerator.NextToken());

                #endregion
                #region BackImageManager

                _backImageManager = new BackImageManager(backgroundCanvas, _player);

                #endregion

                #region Ship Extra

                _shipExtra = new ShipExtraArgs()
                {
                    Options = _editorOptions,
                    ItemOptions = _itemOptions,
                    Material_Projectile = _material_Projectile,
                    Material_SwarmBot = _material_SwarmBot,
                    SwarmObjectiveStrokes = _brushStrokes,
                    RunNeural = false,
                    Radiation = _radiation,
                };

                #endregion

                CreateStars3D();      //TODO: Move this to BackImageManager
                                      //CreateStars3DGrid();
                                      //CreateShip(UtilityCore.GetRandomEnum<DefaultShipType>());

                if (!LoadLatestSession())
                {
                    CreateNewSession();
                }

                CreateAsteroids();
                CreateMinerals();
                //CreateProjectile();

                _world.UnPause();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #10
0
        public Bot(BotConstruction_Result construction)
        {
            _options = construction.ArgsExtra.Options;
            _itemOptions = construction.ArgsExtra.ItemOptions;

            _radiation = construction.ArgsExtra.Radiation;
            _gravity = construction.ArgsExtra.Gravity;
            _cameraPool = construction.ArgsExtra.CameraPool;

            _parts = construction.PartConstruction;
            _thrusters = construction.PartConstruction.GetStandardParts<Thruster>(Thruster.PARTTYPE).ToArray();
            _projectileGuns = construction.PartConstruction.GetStandardParts<ProjectileGun>(ProjectileGun.PARTTYPE).ToArray();
            _updatableParts_MainThread = construction.UpdatableParts_MainThread;
            _updatableParts_AnyThread = construction.UpdatableParts_AnyThread;
            _dna = construction.DNA;
            _dnaParts = construction.DNAParts;

            this.Model = construction.Model;
            _visualEffects = construction.VisualEffects;

            _isPhysicsStatic = construction.ArgsExtra.IsPhysicsStatic;
            this.PhysicsBody = construction.PhysicsBody;

            this.Radius = construction.Radius;

            _partTransformToModel = _parts.AllPartsArray.
                Select(o =>
                {
                    Transform3DGroup transform = new Transform3DGroup();
                    transform.Children.Add(new TranslateTransform3D(-o.Position.ToVector()));
                    transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(o.Orientation.ToReverse())));
                    return transform;
                }).
                ToArray();

            // Hook up events
            if (!_isPhysicsStatic)
            {
                this.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(PhysicsBody_ApplyForceAndTorque);
            }

            foreach (var part in _parts.AllPartsArray)
            {
                part.RequestWorldLocation += new EventHandler<PartRequestWorldLocationArgs>(Part_RequestWorldLocation);
                part.RequestWorldSpeed += new EventHandler<PartRequestWorldSpeedArgs>(Part_RequestWorldSpeed);
                part.RequestParent += new EventHandler<PartRequestParentArgs>(Part_RequestParent);

                part.Resurrected += Part_Resurrected;
                part.Destroyed += Part_Destroyed;
            }

            // See if there are parts that can gradually change the ship's mass
            if ((_parts.Containers.Fuels.Count > 0 && _parts.StandardParts.ContainsKey(Thruster.PARTTYPE)) ||
                (_parts.Containers.CargoBays.Count > 0 && (_parts.StandardParts.ContainsKey(ConverterMatterToEnergy.PARTTYPE) || _parts.StandardParts.ContainsKey(ConverterMatterToFuel.PARTTYPE))) ||
                (_parts.Containers.Energies.Count > 0 && _parts.Containers.Fuels.Count > 0 && (_parts.StandardParts.ContainsKey(ConverterEnergyToFuel.PARTTYPE) || _parts.StandardParts.ContainsKey(ConverterFuelToEnergy.PARTTYPE)))
                )
            {
                _hasMassChangingUpdatables_Small = true;
            }
            else
            {
                _hasMassChangingUpdatables_Small = false;
            }

            if (_parts.Containers.Ammos.Count > 0 && _parts.StandardParts.ContainsKey(ProjectileGun.PARTTYPE))
            {
                _hasMassChangingUpdatables_Medium = true;
            }
            else
            {
                _hasMassChangingUpdatables_Medium = false;
            }

            // Set up a neural processor on its own thread/task
            _neuronLinks = construction.Links;
            if (_neuronLinks != null)
            {
                var bucketTask = AddToNeuralPool(_neuronLinks);
                _neuralPoolAddTask = bucketTask.Item1;
                _linkBucket = bucketTask.Item2;
            }

            _lifeEvents = construction.PartConstruction.LifeEventWatcher;

            this.ShouldRecalcMass_Large = false;
            this.ShouldRecalcMass_Small = false;

            this.CreationTime = DateTime.UtcNow;
        }
        private void EnsureWorldStarted()
        {
            if (_world != null)
            {
                return;
            }

            #region Init World

            // Set the size of the world to something a bit random (gets boring when it's always the same size)
            double halfSize = 50d;
            _boundryMin = new Point3D(-halfSize, -halfSize, -halfSize);
            _boundryMax = new Point3D(halfSize, halfSize, halfSize);

            _world = new World();
            _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating);

            List<Point3D[]> innerLines, outerLines;
            _world.SetCollisionBoundry(out innerLines, out outerLines, _boundryMin, _boundryMax);

            // Draw the lines
            _boundryLines = new ScreenSpaceLines3D(true);
            _boundryLines.Thickness = 1d;
            _boundryLines.Color = _colors.BoundryLines;
            _viewport.Children.Add(_boundryLines);

            foreach (Point3D[] line in innerLines)
            {
                _boundryLines.AddLine(line[0], line[1]);
            }

            #endregion
            #region Materials

            _materialManager = new MaterialManager(_world);

            // Asteroid
            Game.Newt.v2.NewtonDynamics.Material material = new Game.Newt.v2.NewtonDynamics.Material();
            material.Elasticity = .25d;
            material.StaticFriction = .9d;
            material.KineticFriction = .75d;
            _material_Asteroid = _materialManager.AddMaterial(material);

            // Ship
            material = new Game.Newt.v2.NewtonDynamics.Material();
            material.Elasticity = .75d;
            material.StaticFriction = .5d;
            material.KineticFriction = .2d;
            _material_Bot = _materialManager.AddMaterial(material);

            // Sand
            material = new Game.Newt.v2.NewtonDynamics.Material();
            material.Elasticity = .5d;
            material.StaticFriction = .5d;
            material.KineticFriction = .33d;
            _material_Sand = _materialManager.AddMaterial(material);

            _materialManager.RegisterCollisionEvent(_material_Bot, _material_Asteroid, Collision_Ship);
            _materialManager.RegisterCollisionEvent(_material_Bot, _material_Sand, Collision_Sand);

            #endregion

            _map = new Map(_viewport, null, _world);
            //_map.SnapshotFequency_Milliseconds = 125;
            //_map.SnapshotMaxItemsPerNode = 10;
            _map.ShouldBuildSnapshots = false;
            //_map.ShouldShowSnapshotLines = true;
            //_map.ShouldSnapshotCentersDrift = false;

            _radiation = new RadiationField();
            _radiation.AmbientRadiation = 1d;

            _gravity = new GravityFieldUniform();

            _world.UnPause();
        }
        private void btnStandaloneSolarPanel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                RadiationField radiation = new RadiationField();
                radiation.AmbientRadiation = 1d;

                ConverterRadiationToEnergyDNA dna = new ConverterRadiationToEnergyDNA()
                {
                    PartType = ConverterRadiationToEnergy.PARTTYPE,
                    Shape = UtilityCore.GetRandomEnum<SolarPanelShape>(),
                    Position = new Point3D(0, 0, 0),
                    Orientation = Quaternion.Identity,
                    Scale = new Vector3D(1, 1, 1)
                };
                ModifyDNA(dna, chkStandaloneRandSize.IsChecked.Value, chkStandaloneRandOrientation.IsChecked.Value);

                ConverterRadiationToEnergy solar = new ConverterRadiationToEnergy(_editorOptions, _itemOptions, dna, null, radiation);

                BuildStandalonePart(solar);

                if (chkStandaloneShowMassBreakdown.IsChecked.Value)
                {
                    double cellSize = Math1D.Max(dna.Scale.X, dna.Scale.Y, dna.Scale.Z) * UtilityCore.GetScaledValue_Capped(.1d, .3d, 0d, 1d, _rand.NextDouble());
                    DrawMassBreakdown(solar.GetMassBreakdown(cellSize), cellSize);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void btnSolarPanel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ShipPartDNA dna = GetDefaultDNA(EnergyTank.PARTTYPE);
                EnergyTank energyTank = new EnergyTank(_editorOptions, _itemOptions, dna);

                RadiationField radiation = new RadiationField();
                radiation.AmbientRadiation = 1d;

                ConverterRadiationToEnergyDNA dna2 = new ConverterRadiationToEnergyDNA()
                {
                    PartType = ConverterRadiationToEnergy.PARTTYPE,
                    Shape = UtilityCore.GetRandomEnum<SolarPanelShape>(),
                    Position = new Point3D(0, 0, 0),
                    Orientation = Quaternion.Identity,
                    Scale = new Vector3D(1, 1, 1)
                };
                ConverterRadiationToEnergy solar = new ConverterRadiationToEnergy(_editorOptions, _itemOptions, dna2, energyTank, radiation);

                solar.Transfer(1d, Transform3D.Identity);
                solar.Transfer(1d, Transform3D.Identity);
                solar.Transfer(1d, Transform3D.Identity);
                solar.Transfer(1d, Transform3D.Identity);
                solar.Transfer(1d, Transform3D.Identity);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }