public CollisionShapes()
        {
            InitializeComponent();

            grdPanel.Background = SystemColors.ControlBrush;

            #region Init World

            _world.InitialiseBodies();
            //_world.ShouldForce2D = true;       // the checkbox is defaulted to unchecked
            _world.Gravity = 0d;

            _world.UnPause();

            #endregion

            // Trackball
            _trackball = new TrackBallRoam(_camera);
            _trackball.EventSource = grdViewPort;
            _trackball.AllowZoomOnMouseWheel = true;
            _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));
            //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
            _trackball.GetOrbitRadius += new EventHandler<GetOrbitRadiusArgs>(Trackball_GetOrbitRadius);

            // Make the form look right
            trkSimulationSpeed_ValueChanged(this, new RoutedPropertyChangedEventArgs<double>(trkSimulationSpeed.Value, trkSimulationSpeed.Value));
            trkMapSize_ValueChanged(this, new RoutedPropertyChangedEventArgs<double>(trkMapSize.Value, trkMapSize.Value));
        }
        public GravityCubes1()
        {
            InitializeComponent();

            grdPanel.Background = SystemColors.ControlBrush;

            // Trackball
            _trackball = new TrackBallRoam(_camera);
            _trackball.EventSource = grdViewPort;
            _trackball.AllowZoomOnMouseWheel = true;
            _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));
        }
        public TubeMeshTester()
        {
            InitializeComponent();

            // Camera Trackball
            _trackball = new TrackBallRoam(_camera);
            _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));
            //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);

            _isInitialized = true;

            // Make the form look right
            radLight_Checked(this, new RoutedEventArgs());
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                #region Trackball

                // Camera Trackball
                _trackball = new TrackBallRoam(_camera);
                //_trackball.ShouldHitTestOnOrbit = true;
                _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));
                //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);

                #endregion

                //Material
                _material = new MaterialGroup();
                RefreshColors();

                // Visuals
                AddVisual(UtilityWPF.GetCylinder_AlongX(60, 1, 2), new Point3D(-2.5, 2.5, 0));
                AddVisual(UtilityWPF.GetCube_IndependentFaces(new Point3D(-1, -1, -1), new Point3D(1, 1, 1)), new Point3D(2.5, 2.5, 0));

                AddVisual(UtilityWPF.GetSphere_LatLon(20, 1), new Point3D(-2.5, -2.5, 0));

                var hull = Math3D.GetConvexHull(Enumerable.Range(0, 40).Select(o => Math3D.GetRandomVector_Spherical(1.1, 1.3).ToPoint()).ToArray());
                AddVisual(UtilityWPF.GetMeshFromTriangles(hull), new Point3D(2.5, -2.5, 0));
                AddVisual(UtilityWPF.GetMeshFromTriangles_IndependentFaces(hull), new Point3D(2.5, -6, 0));

                // Timer
                _timer = new DispatcherTimer();
                _timer.Interval = TimeSpan.FromMilliseconds(20);
                _timer.Tick += Timer_Tick;
                _timer.Start();

                _isInitialized = true;

                RefreshColors();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public VelocityVisualizer3DWindow()
        {
            InitializeComponent();

            // Camera Trackball
            _trackball = new TrackBallRoam(_camera);
            _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.MouseWheelScale *= .1d;
            _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));
            //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);

            // Velocity line visual
            _velocityLines = new BillboardLine3DSet();
            _velocityLines.Color = Colors.GhostWhite;
            _velocityLines.IsReflectiveColor = true;
            _viewport.Children.Add(_velocityLines);

            UpdateLinePlacement();

            ShowHideBlockedCells();
        }
        public GravityCubes2()
        {
            InitializeComponent();

            grdPanel.Background = SystemColors.ControlBrush;
            chkAttractedToOrigin.Content = "Attracted to\r\nOrigin";

            #region Init World

            _world.InitialiseBodies();
            _world.Gravity = 0d;

            List<Point3D[]> innerLines, outerLines;
            _world.SetCollisionBoundry(out innerLines, out outerLines, _viewport, new Vector3D(-15, -15, -15), new Vector3D(15, 15, 15));

            Color lineColor = UtilityWPF.AlphaBlend(Colors.White, Colors.Gray, .1d);
            foreach (Point3D[] line in innerLines)
            {
                // Need to wait until the window is loaded to call lineModel.CalculateGeometry
                ScreenSpaceLines3D lineModel = new ScreenSpaceLines3D(false);
                lineModel.Thickness = 1d;
                lineModel.Color = lineColor;
                lineModel.AddLine(line[0], line[1]);

                _viewport.Children.Add(lineModel);
                _lines.Add(lineModel);
            }

            _world.UnPause();

            #endregion

            _trackball = new TrackBallRoam(_camera);
            _trackball.EventSource = grdViewPort;
            _trackball.AllowZoomOnMouseWheel = true;
            _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));
        }
        public CharacterStatsPanel()
        {
            InitializeComponent();

            // SpikeBall
            foreach (string name in Enum.GetNames(typeof(WeaponSpikeBallMaterial)))
            {
                cboMaterial.Items.Add(name);
            }

            cboMaterial.SelectedIndex = 0;

            // Axe Head
            foreach (string name in Enum.GetNames(typeof(WeaponAxeType)))
            {
                cboAxeType.Items.Add(name);
            }

            cboAxeType.SelectedIndex = 0;

            // 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.Add(new TrackBallMapping(CameraMovement.Orbit, MouseButton.Left));
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Orbit, MouseButton.Right));
            _trackball.ShouldHitTestOnOrbit = false;

            // Timer
            //_timer = new DispatcherTimer();
            //_timer.Interval = TimeSpan.FromMilliseconds(100);
            //_timer.Tick += Timer_Tick;
            //_timer.IsEnabled = true;

            _isInitialized = true;
        }
        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);

                #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);

                // Ball
                material = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Ball = _materialManager.AddMaterial(material);

                #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 Chased Ball

                _chasedBall = new ChasedBall();

                _chasedBall.MotionType_Position = MotionType_Position.Stop;
                _chasedBall.MotionType_Orientation = MotionType_Orientation.Stop;

                _chasedBall.BoundrySizeChanged += new EventHandler(ChasedBall_BoundrySizeChanged);

                // Ball visual
                _chasedBallVisual = GetChaseBallVisual_Position();
                _chasedBallTransform = new TranslateTransform3D();
                _chasedBallVisual.Transform = _chasedBallTransform;
                _viewport.Children.Add(_chasedBallVisual);

                // Direction Visual
                var directionVisual = GetChaseBallVisual_Orientation();
                _chasedDirectionModel = directionVisual.Item1;
                _chasedDirectionVisual = directionVisual.Item2;
                _viewport.Children.Add(_chasedDirectionVisual);

                // Panels (the act of instantiating them will update the ball's properties)
                pnlChasePosition.Content = new ChasedPosition(_chasedBall)
                {
                    Foreground = Brushes.White,
                };

                pnlChaseOrientation.Content = new ChasedOrientation(_chasedBall)
                {
                    Foreground = Brushes.White,
                };

                #endregion
                #region Debug Visuals

                // Put these on the viewport before the ball so that it is propertly semitransparent

                //TODO: Draw the bounding box.  Use XYZ colors.  This will help the user stay oriented

                #endregion
                #region Body Ball

                _bodyBall = new BodyBall(_world);

                //_bodyBall.PhysicsBody.AngularDamping = new Vector3D(.0001, .0001, .0001);
                //_bodyBall.PhysicsBody.AngularVelocity = new Vector3D(0, 0, 4 * Math.PI);

                _viewport.Children.AddRange(_bodyBall.Visuals3D);

                #endregion

                RedrawBoundry();

                _world.UnPause();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                //_backgroundTiles = new BackgoundTiles(_sceneCanvas, _camera, (Brush)this.FindResource("color_SceneBackAlt"));

                #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);

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

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

                // Collisions
                _materialManager.RegisterCollisionEvent(_material_Bot, _material_Bot, Collision_BotBot);
                _materialManager.RegisterCollisionEvent(_material_Bot, _material_Asteroid, Collision_BotAsteroid);

                #endregion
                #region Trackball

                // Camera Trackball
                _trackball = new TrackBallRoam(_camera);
                _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.ShouldHitTestOnOrbit = true;
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete_NoLeft));
                //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);

                #endregion
                #region Map

                _map = new Map(_viewport, null, _world);
                _map.SnapshotFequency_Milliseconds = 250;// 125;
                _map.SnapshotMaxItemsPerNode = 10;
                _map.ShouldBuildSnapshots = true;
                _map.ShouldShowSnapshotLines = false;
                _map.ShouldSnapshotCentersDrift = true;
                _map.ItemAdded += Map_ItemAdded;
                _map.ItemRemoved += Map_ItemRemoved;

                #endregion
                #region Update Manager

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

                #endregion
                #region Strokes

                _strokes = new SwarmObjectiveStrokes(_world.WorldClock, SUBSTROKESIZE, 15);
                _strokes.PointsChanged += Strokes_PointsChanged;

                #endregion
                #region Bot Clusters

                _botClusters = new SwarmClusters(_map);

                _botClusterTimer = new System.Timers.Timer();
                _botClusterTimer.Interval = 1111;
                _botClusterTimer.AutoReset = false;       // makes sure only one tick is firing at a time
                _botClusterTimer.Elapsed += BotClusterTimer_Elapsed;
                _botClusterTimer.Start();

                #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
            {
                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);
            }
        }
        public OCRTestDataVisualizer()
        {
            InitializeComponent();

            // Camera Trackball
            _trackball = new TrackBallRoam(_camera);
            _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.MouseWheelScale *= .1;
            //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);

            // Timer
            _timer = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMilliseconds(25);
            _timer.Tick += Timer_Tick;
            _timer.Start();
        }
Пример #12
0
        public Editor()
        {
            //TODO: Research loading/saving in xaml
            //System.Windows.Markup.XamlReader test2 = new System.Windows.Markup.XamlReader();
            //System.Windows.Markup.XamlWriter test3;
            //MeshGeometry3D test;

            InitializeComponent();

            // Without this, the xaml can't bind to the custom dependency properties
            this.DataContext = this;

            #region Camera Trackball

            _trackball = new TrackBallRoam(_camera);
            _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.ZoomScale *= .25d;
            _trackball.KeyPanScale *= .1d;

            //_trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete_NoLeft));
            #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.Add(new TrackBallMapping(CameraMovement.Pan_Keyboard_In, Key.OemPlus));
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Pan_Keyboard_In, Key.Add));
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Pan_Keyboard_Out, Key.OemMinus));
            _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Pan_Keyboard_Out, Key.Subtract));

            _trackball.ShouldHitTestOnOrbit = true;

            _trackball.UserMovedCamera += new EventHandler<UserMovedCameraArgs>(Trackball_UserMovedCamera);

            #endregion

            _dragHitShape = new DragHitShape();
            //TODO: Add this to the options (the visual should let the user drag a cone)
            //_dragHitShape.ConstrainMinDotProduct = _options.DragHitShape_ConstrainMinDotProduct;
            ChangeDragHitShape();

            // Compass Rose
            _compassRose = GetCompassRose(_options.EditorColors);
            _viewport.Children.Add(_compassRose);

            #region Ship name textbox

            // The textbox's cursor can't be set directly, but is the opposite of background.  If I just use null or transparent, the cursor is still
            // black, so I'm making the background transparent black, which makes the cursor white;
            //txtName.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));
            //txtShipName.Background = new SolidColorBrush(Color.FromArgb(0, _options.EditorColors.Background.R, _options.EditorColors.Background.G, _options.EditorColors.Background.B));
            txtDesignName.Background = new SolidColorBrush(Color.FromArgb(25, _options.EditorColors.Panel_Background.R, _options.EditorColors.Panel_Background.G, _options.EditorColors.Panel_Background.B));

            txtDesignName.Foreground = new SolidColorBrush(_options.EditorColors.PartVisual_TextColor);

            #endregion

            _isInitialized = true;

            btnNewLayer_Click(this, new RoutedEventArgs());		// all layers
            btnNewLayer_Click(this, new RoutedEventArgs());		// first real layer
        }
        public HighDimensionVisualizer(Func<ISOMInput, Tuple<UIElement, VectorInt>> getPreview = null, Func<ISOMInput, Color> getDotColor = null, bool showStaticDots = false, bool is3D = false)
        {
            InitializeComponent();

            _showStaticDots = showStaticDots;

            _getPreview = getPreview;
            _getDotColor = getDotColor;

            chk3D.IsChecked = is3D;

            // Camera Trackball
            _trackball = new TrackBallRoam(_camera);
            _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.MouseWheelScale *= .1;
            //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);

            // Timer
            _timer = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMilliseconds(25);
            _timer.Tick += Timer_Tick;
            _timer.Start();

            // Visual
            _modelGroup = new Model3DGroup();
            _visual = new ModelVisual3D()
            {
                Content = _modelGroup,
            };

            _initialized = true;
        }
Пример #14
0
        public Curves()
        {
            InitializeComponent();

            // Camera Trackball
            _trackball = new TrackBallRoam(_camera);
            _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));
            //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Init World
                _world = new World();
                _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating);
                _world.SetWorldSize(new Point3D(-100, -100, -100), new Point3D(100, 100, 100));
                _world.UnPause();

                // Camera Trackball
                _trackball = new TrackBallRoam(_camera);
                _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));
                //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);

                // Trackball Controls
                SetupModelTrackball();
                SetupFlowTrackball();

                _field = new FluidFieldUniform()
                {
                    Viscosity = trkFlowViscosity.Value,
                    Flow = GetWorldFlow()
                };

                // Fluid lines
                AddFluidVisuals(Convert.ToInt32(NUMFLUIDVISUALS * _flowViscosity));

                // Force lines
                _forceLines = new ScreenSpaceLines3D(true);
                _forceLines.Color = _colors.ForceLine;
                _forceLines.Thickness = 2d;

                _viewport.Children.Add(_forceLines);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #16
0
        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);
            }
        }
        public MineralIdentifier()
        {
            InitializeComponent();

            this.Background = SystemColors.ControlBrush;

            #region Tab: Single Image

            // Camera Trackball
            _trackball = new TrackBallRoam(_camera);
            _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));
            _trackball.MouseWheelScale *= .1;
            //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);

            // Mineral Types
            foreach (MineralType mineral in Enum.GetValues(typeof(MineralType)))
            {
                cboMineral.Items.Add(mineral);
            }
            cboMineral.SelectedIndex = 0;

            #endregion
            #region Tab: Training Data

            #region Mineral Types

            foreach (MineralType mineral in Enum.GetValues(typeof(MineralType)))
            {
                CheckBox mineralCheckbox = new CheckBox()
                {
                    Content = mineral.ToString(),
                    Tag = mineral,
                    Margin = new Thickness(2),
                };

                pnlMineralSelections.Children.Add(mineralCheckbox);
            }

            #endregion
            #region Convolutions

            // Gaussian Subtract
            AddKernel(new ConvolutionSet2D(new[] { Convolutions.GetGaussian(3, 1) }, SetOperationType.Subtract));

            // MaxAbs Sobel
            Convolution2D vert = Convolutions.GetEdge_Sobel(true);
            Convolution2D horz = Convolutions.GetEdge_Sobel(false);
            var singles = new[]
                {
                    new Convolution2D(vert.Values, vert.Width, vert.Height, vert.IsNegPos, 1),
                    new Convolution2D(horz.Values, horz.Width, horz.Height, horz.IsNegPos, 1),
                };

            ConvolutionSet2D set = new ConvolutionSet2D(singles, SetOperationType.MaxOf);
            AddKernel(set);

            #endregion

            #endregion

            _initialized = true;

            cboMineral_SelectionChanged(this, null);
            ResetCamera_Click(this, null);
        }
Пример #18
0
        private void radCamera_Checked(object sender, RoutedEventArgs e)
        {
            if (_camera1 == null || _camera2 == null)
            {
                // This event is getting invoked from InitializeComponent
                return;
            }

            #region Disable Controls

            chkIsActive4.IsEnabled = false;
            button1.IsEnabled = false;

            #endregion

            #region Dispose Current Trackballs

            if (_trackball2 != null)
            {
                _trackball2.EventSource = null;
                _trackball2 = null;
            }

            if (_trackball3 != null)
            {
                _trackball3.EventSource = null;
                _trackball3 = null;
            }

            if (_trackball4 != null)
            {
                _trackball4.EventSource = null;
                _trackball4 = null;
            }

            #endregion

            if (radCamera1.IsChecked.Value)
            {
                #region Camera 1

                _camera1.Position = new Point3D(0, 0, 25);
                _camera1.LookDirection = new Vector3D(0, 0, -10);
                _camera1.UpDirection = new Vector3D(0, 1, 0);
                _camera1.FieldOfView = 45;

                _viewport.Camera = _camera1;

                #endregion
            }
            else if (radCamera2.IsChecked.Value)
            {
                #region Camera 2

                //_camera2.Position = new Point3D(0, 0, 25);
                //_camera2.LookDirection = new Vector3D(0, 0, -10);
                //_camera2.UpDirection = new Vector3D(0, 1, 0);
                //_camera2.FieldOfView = 45;

                _camera2.Position = new Point3D(0, 25, 0);		// this alternate location is to test placing the camera somewhere other than the z axis
                _camera2.LookDirection = new Vector3D(0, -1, 0);
                _camera2.UpDirection = new Vector3D(0, 0, -1);
                _camera2.FieldOfView = 45;

                _trackball2 = new TrackballTransform(_camera2);
                _trackball2.EventSource = grdViewPort;
                _camera2.Transform = _trackball2.Transform;

                _viewport.Camera = _camera2;

                #endregion
            }
            else if (radCamera3.IsChecked.Value)
            {
                #region Camera 3

                //_camera3.Position = new Point3D(0, 0, 25);
                //_camera3.LookDirection = new Vector3D(0, 0, -10);
                //_camera3.UpDirection = new Vector3D(0, 1, 0);
                //_camera3.FieldOfView = 45;

                _camera3.Position = new Point3D(0, 25, 0);		// this alternate location is to test placing the camera somewhere other than the z axis
                _camera3.LookDirection = new Vector3D(0, -1, 0);
                _camera3.UpDirection = new Vector3D(0, 0, -1);
                _camera3.FieldOfView = 45;

                _trackball3 = new TrackBallRoam_local(_camera3);
                _trackball3.EventSource = grdViewPort;

                _viewport.Camera = _camera3;

                #endregion
            }
            else if (radCamera4.IsChecked.Value)
            {
                #region Camera 4

                chkIsActive4.IsEnabled = true;
                button1.IsEnabled = true;

                _camera4.Position = new Point3D(0, 0, 25);
                _camera4.LookDirection = new Vector3D(0, 0, -10);
                _camera4.UpDirection = new Vector3D(0, 1, 0);
                _camera4.FieldOfView = 45;

                //_camera4.Position = new Point3D(0, 25, 0);		// this alternate location is to test placing the camera somewhere other than the z axis
                //_camera4.LookDirection = new Vector3D(0, -1, 0);
                //_camera4.UpDirection = new Vector3D(0, 0, -1);
                //_camera4.FieldOfView = 45;

                _trackball4 = new TrackBallRoam(_camera4);
                _trackball4.EventSource = grdViewPort;

                _trackball4.AllowZoomOnMouseWheel = true;
                _trackball4.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));

                _trackball4.IsActive = chkIsActive4.IsChecked.Value;

                _viewport.Camera = _camera4;

                #endregion
            }
            else
            {
                MessageBox.Show("Unknown camera selected", this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
                _viewport.Camera = null;
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            #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
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                //_camera.Position = new Point3D(0, 0, -1000);
                //_camera.LookDirection = new Vector3D(0, 0, 1);
                //_camera.UpDirection = new Vector3D(0, 1, 0);

                #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 *= 1d + (StaticRandom.NextDouble() * 5d);
                _boundryMin = new Point3D(-halfSize, -halfSize, halfSize * -.25);
                _boundryMax = new Point3D(halfSize, halfSize, halfSize * .25);

                _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);

                // 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);

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

                // Space Station (force field)
                material = new Game.Newt.v2.NewtonDynamics.Material();
                material.Elasticity = .99d;
                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);

                #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_RightRotateInPlace));
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.Keyboard_ASDW_In));
                //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
                _trackball.ShouldHitTestOnOrbit = true;

                #endregion
                #region Map

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

                #endregion
                #region UpdateManager

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

                #endregion
                CreateFields();

                //TODO:  Add these during a timer to minimize the load time
                if (_optionsPanel.ShowStars)
                {
                    CreateStars();
                }
                CreateAsteroids();
                CreateMinerals();
                CreateSpaceStations();		// creating these last so stuff shows up behind them

                #region Start Position

                #region Farthest Station

                //// The center is too chaotic, so choose the farthest out space station
                //Point3D farthestStationPoint = new Point3D(0, 0, 0);
                //double farthestStationDistance = 0d;
                //foreach (Point3D stationPosition in _map.GetAllObjects().Where(o => o is SpaceStation).Select(o => o.PositionWorld))
                //{
                //    double distance = stationPosition.ToVector().LengthSquared;
                //    if (distance > farthestStationDistance)
                //    {
                //        farthestStationPoint = stationPosition;
                //        farthestStationDistance = distance;
                //    }
                //}

                //// Set the camera near there
                //_camera.Position = farthestStationPoint + (farthestStationPoint.ToVector().ToUnit() * 75d) + Math3D.GetRandomVectorSphericalShell(25d);
                //_camera.LookDirection = _camera.Position.ToVector() * -1d;
                //_camera.UpDirection = new Vector3D(0, 0, 1);

                #endregion
                #region Random Station

                List<Point3D> stationPoints = _map.GetAllItems().Where(o => o is SpaceStation).Select(o => o.PositionWorld).ToList();
                Point3D stationPoint = stationPoints[StaticRandom.Next(stationPoints.Count)];

                // Set the camera near there
                _camera.Position = stationPoint + (stationPoint.ToVector().ToUnit() * 75d) + Math3D.GetRandomVector_Spherical_Shell(25d);
                _camera.LookDirection = _camera.Position.ToVector() * -1d;
                _camera.UpDirection = new Vector3D(0, 0, 1);

                #endregion

                #endregion

                //TODO:  kuler for dialogs

                _world.UnPause();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #21
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Init World
                _world = new World();
                _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating);
                _world.UnPause();

                // Trackball
                _trackball = new TrackBallRoam(_camera);
                _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));
                //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
                _trackball.ShouldHitTestOnOrbit = true;

                SetCollisionBoundry();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Пример #22
0
        public MadShatter()
        {
            InitializeComponent();

            // Camera Trackball
            _trackball = new TrackBallRoam(_camera);
            _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);

            _errorEffect = new DropShadowEffect()
            {
                Color = UtilityWPF.ColorFromHex("FF0000"),
                BlurRadius = 4,
                Direction = 0,
                Opacity = .5,
                ShadowDepth = 0,
            };

            _initialized = true;
        }
Пример #23
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);
            }
        }
Пример #24
0
        public NeuralTester()
        {
            InitializeComponent();

            #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;
            _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));
            //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
            _trackball.ShouldHitTestOnOrbit = false;

            #endregion
        }
        public ImageFilterPainter()
        {
            InitializeComponent();

            this.Background = SystemColors.ControlBrush;

            _errorEffect = new DropShadowEffect()
            {
                Color = Colors.Red,
                BlurRadius = 15,
                Direction = 0,
                ShadowDepth = 0,
                Opacity = .8,
            };

            _width = Convert.ToInt32(txtWidth.Text);
            _height = Convert.ToInt32(txtHeight.Text);

            _values = new double[_width * _height];

            // Camera Trackball
            _trackball = new TrackBallRoam(_camera);
            _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.MouseWheelScale *= .1;
            //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);

            _initialized = true;

            RedrawAxis();
            RebuildBars();

            PixelValueChanged();
        }
        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);
            }
        }
Пример #27
0
 private void InitializeTrackball()
 {
     // Trackball
     _trackball = new TrackBallRoam(_camera);
     _trackball.KeyPanScale = 15d;
     _trackball.EventSource = pnlIconBorder;		//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 = false;
     _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Orbit, MouseButton.Left));
     _trackball.Mappings.Add(new TrackBallMapping(CameraMovement.Orbit, MouseButton.Right));
     _trackball.ShouldHitTestOnOrbit = false;
 }
Пример #28
0
        public BrainLinks()
        {
            InitializeComponent();

            // Camera Trackball
            _trackballFull = new TrackBallRoam(_cameraFull);
            _trackballFull.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)
            _trackballFull.AllowZoomOnMouseWheel = true;
            _trackballFull.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));
            //_trackballFull.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);

            #region AddItemLocation

            ComboBox[] combos = new[]
            {
                cbo2DAddInput, cbo2DAddOutput, cbo2DAddBrain,
                cbo3DAddInput, cbo3DAddOutput, cbo3DAddBrain,
            };

            foreach (string option in Enum.GetNames(typeof(AddItemLocation)))
            {
                foreach (ComboBox combo in combos)
                {
                    combo.Items.Add(option);
                }
            }

            foreach (ComboBox combo in combos)
            {
                combo.SelectedIndex = 0;
            }

            #endregion
            #region ClearWhich

            combos = new[]
            {
                cbo2DClear,
                cbo3DClear,
            };

            foreach (string option in Enum.GetNames(typeof(ClearWhich)))
            {
                foreach (ComboBox combo in combos)
                {
                    combo.Items.Add(option);
                }
            }

            foreach (ComboBox combo in combos)
            {
                combo.SelectedIndex = 0;
            }

            #endregion
            #region IOLinkupPriority

            combos = new[]
            {
                cbo2DIOLinkupPriority,
                //cbo3DIOLinkupPriority,
            };

            foreach (string option in Enum.GetNames(typeof(Worker2D_Distance.IOLinkupPriority)))
            {
                foreach (ComboBox combo in combos)
                {
                    combo.Items.Add(option);
                }
            }

            foreach (ComboBox combo in combos)
            {
                combo.SelectedIndex = 0;
            }

            #endregion

            _brainLinkBrush = new SolidColorBrush(_brainLinkColor);
            _brainGroupBrush = new SolidColorBrush(_brainGroupColor);
            _ioLinkBrush = new SolidColorBrush(_ioLinkColor);
        }
        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);
            }
        }
        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;

                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));
                //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);
                _trackball.ShouldHitTestOnOrbit = true;

                #endregion

                _camera.Changed += new EventHandler(Camera_Changed);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }