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

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

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

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

                _viewport.Children.Add(_fluidHullForceLines);

                // Field - may want to only add this when a body is added
                _field = new FluidField3D(20);
                _field.Diffusion = 0;
                _field.Damping = 0; //GetFluidViscocity();        // this stays zero (see comments in VelocityViscocityChanged)

                _field.BoundryType = FluidFieldBoundryType3D.Open_Slaved;
                _fieldUniform = new FluidFieldUniform();
                _field.OpenBoundryParent = _fieldUniform;
                _field.SizeWorld = 10d;     // This changes whenever a body is swapped out

                _fieldCells = _field.GetCells();

                _fieldField = new FluidFieldField(_field);
                _fieldField.Viscosity = GetFluidViscocity();

                _isInitialized = true;

                ShowHideFluidBoundry();
                ShowHideBlockedCells();

                VelocityViscocityChanged();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        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);
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Init World
                _world = new World();
                //_world.SetSolverModel(SolverModel.ExactMode);		// all of them are slower than adaptive
                _world.Updating += new EventHandler<WorldUpdatingArgs>(World_Updating);
                _world.SetWorldSize(new Point3D(-1000, -1000, -1000), new Point3D(1000, 1000, 1000));
                _world.UnPause();

                #region Materials

                _materialManager = new MaterialManager(_world);

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

                // Brick
                material = new Game.Newt.v2.NewtonDynamics.Material();
                _material_Brick = _materialManager.AddMaterial(material);

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

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

                _materialManager.RegisterCollisionEvent(_material_Projectile, _material_Brick, Collision_ProjectileBrick);
                _materialManager.RegisterCollisionEvent(_material_Brick, _material_Brick, Collision_BrickBrick);

                #endregion

                #region Terrain

                #region WPF Model (plus collision hull)

                // Material
                MaterialGroup materials = new MaterialGroup();
                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(Color.FromArgb(255, 110, 96, 72))));
                materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(Colors.Ivory, Colors.Transparent, .15d)), 25d));

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

                double terrainHeight = TERRAINRADIUS / 10d;

                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;



                //AddDebugDot(new Point3D(0, 0, 0), 5, Colors.Yellow);
                //AddDebugDot(new Point3D(0, 0, 8), 3, Colors.Yellow);
                //AddDebugDot(new Point3D(0, 0, 12), 1, Colors.Yellow);


                #endregion

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

                RadioLeftClick_Checked(this, new RoutedEventArgs());
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }