Beispiel #1
0
        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;
        }
Beispiel #2
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.ShouldHitTestOnOrbit  = true;
                _trackball.InertiaPercentRetainPerSecond_Angular = .95;
                _trackball.Mappings.AddRange(TrackBallMapping.GetPrebuilt(TrackBallMapping.PrebuiltMapping.MouseComplete));
                //_trackball.GetOrbitRadius += new GetOrbitRadiusHandler(Trackball_GetOrbitRadius);

                SetCollisionBoundry();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        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));
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // 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
                SetupFromTrackball();
                SetupToTrackball();

                // Add the 3 axiis to the main viewport
                _lineFrom = AddLines(_orientationTrackballFrom.Transform, true);
                _lineTo   = AddLines(_orientationTrackballTo.Transform, false);

                _isInitialized = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Beispiel #5
0
        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));
        }
Beispiel #6
0
        public PAN_ScatterPlot3D()
        {
            InitializeComponent();

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

            _viewportOffset_Init   = _viewport.Children.Count;
            _viewportOffset_Labels = _viewportOffset_Init;
        }
Beispiel #7
0
 private void Window_Loaded(object sender, RoutedEventArgs e)
 {
     try
     {
         // 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);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Beispiel #8
0
        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());
        }
Beispiel #9
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
        }
        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);
            }
        }
Beispiel #11
0
        public OCRTestDataVisualizer_ORIG()
        {
            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();
        }
Beispiel #12
0
        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();
        }
Beispiel #13
0
        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));
        }
Beispiel #14
0
        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);
        }
Beispiel #15
0
        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);

                var boundryLines = _world.SetCollisionBoundry(_boundryMin, _boundryMax);

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

                foreach (var line in boundryLines.innerLines)
                {
                    _boundryLines.AddLine(line.from, line.to);
                }

                #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);
            }
        }
Beispiel #16
0
        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);

                _world.SetCollisionBoundry(_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);
            }
        }
Beispiel #17
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);
            }
        }
Beispiel #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;
            }
        }
Beispiel #19
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);

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