private static void AddArc(ScreenSpaceLines3D line, Point3D center, double radius, int segments, double startAngle, double stopAngle, bool closeEnd)
        {
            startAngle = Math1D.DegreesToRadians(startAngle);
            stopAngle = Math1D.DegreesToRadians(stopAngle);

            // swap angles
            if (startAngle > stopAngle)
            {
                double temp = startAngle;
                startAngle = stopAngle;
                stopAngle = temp;
            }

            Point3D[] points = new Point3D[segments + 1];
            double inc = (stopAngle - startAngle) / segments;

            double r = startAngle;
            for (int i = 0; i <= segments; i++, r += inc)
            {
                points[i] = new Point3D(
                    center.X + (Math.Cos(-r) * radius),
                    center.Y + (Math.Sin(-r) * radius),
                    center.Z);
            }

            line.AddPolygon(closeEnd, points);
        }
        public VisualToVisualLine3D()
        {
            _autoUpdate = true;

            _line = new ScreenSpaceLines3D(false);
            _line.RebuildingGeometry += _line_RebuildingGeometry;

            Children.Add(_line);

            if (_autoUpdate)
                CompositionTarget.Rendering += OnRender;
        }
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (_viewport != null && _line != null)
         {
             _viewport.Children.Remove(_line);
             _viewport = null;
             _line = null;
         }
     }
 }
        public MapObject_ChasePoint_Direct(IMapObject item, Vector3D offset, bool shouldMoveWithSpring, bool shouldSpringCauseTorque, bool shouldDampenWhenSpring, Viewport3D viewport, Color? springColor = null)
        {
            this.Item = item;
            this.Offset = item.PhysicsBody.DirectionFromWorld(offset);       // convert to model coords
            _viewport = viewport;

            this.SpringForceMultiplier = 1d;

            // Newton uses zero (or maybe negative?) mass for bodies that ignore physics.  So a spring is only effective on
            // bodies with mass
            //TODO: See if PhysicsBody.IsFrozen will block the spring
            if (shouldMoveWithSpring && item.PhysicsBody.MassMatrix.Mass > 0)
            {
                #region Init spring

                this.IsUsingSpring = true;
                this.ShouldDampenWhenSpring = shouldDampenWhenSpring;
                _shouldSpringCauseTorque = shouldSpringCauseTorque;

                if (springColor != null)
                {
                    _springVisual = new ScreenSpaceLines3D();
                    _springVisual.Thickness = 1d;
                    _springVisual.Color = springColor.Value;
                    _viewport.Children.Add(_springVisual);
                }
                else
                {
                    _springVisual = null;
                }

                _springConstant = item.PhysicsBody.MassMatrix.Mass * 50d;

                this.Item.PhysicsBody.ApplyForceAndTorque += new EventHandler<NewtonDynamics.BodyApplyForceAndTorqueArgs>(PhysicsBody_ApplyForceAndTorque);

                #endregion
            }
            else
            {
                #region Init direct move

                this.IsUsingSpring = false;
                this.ShouldDampenWhenSpring = false;
                _shouldSpringCauseTorque = false;
                _springVisual = null;
                _springConstant = 0d;

                #endregion
            }
        }
            /// <summary>
            /// NOTE:  Keep the model coords along X.  The line will be rotated into world coords
            /// </summary>
            public FluidVisual(Viewport3D viewport, Point3D modelFromPoint, Point3D modelToPoint, Point3D worldStartPoint, Vector3D worldFlow, Color color, double maxDistance)
            {
                _viewport = viewport;
                this.Position = worldStartPoint;
                this.WorldFlow = worldFlow;
                this.MaxDistance = maxDistance;

                _line = new ScreenSpaceLines3D(false);
                _line.Thickness = 1d;
                _line.Color = color;
                _line.AddLine(modelFromPoint, modelToPoint);

                UpdateTransform();

                _viewport.Children.Add(_line);
            }
        public SwarmBotTester()
        {
            InitializeComponent();

            #region Init World

            _world.InitialiseBodies();
            //_world.ShouldForce2D = true;
            //_world.Gravity = -10d;     // -600d;    //this is set by the trackbar
            //_world.Gravity = 0d;

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

            Color lineColor = Color.FromArgb(255, 200, 200, 180);
            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.SimulationSpeed = .1d;      // this was when I had to set change in velocity instead of applying forces
            _world.SimulationSpeed = 8d;
            _world.UnPause();

            #endregion

            _isInitialized = true;

            // Make the form look right
            trkGravity_ValueChanged(this, new RoutedPropertyChangedEventArgs<double>(trkGravity.Value, trkGravity.Value));
            SetActiveBehavior();
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        private void AddLine(Point3D from, Point3D to, Color color, double thickness = 1d)
        {
            ScreenSpaceLines3D lineVisual = new ScreenSpaceLines3D(true);
            lineVisual.Thickness = thickness;
            lineVisual.Color = color;
            lineVisual.AddLine(from, to);

            _viewport.Children.Add(lineVisual);
            _visuals.Add(lineVisual);
        }
Ejemplo n.º 9
0
        private void AddLines(IEnumerable<Tuple<Point3D, Point3D>> lines, Color color, double thickness = 1d)
        {
            // Draw the lines
            ScreenSpaceLines3D lineVisual = new ScreenSpaceLines3D(true);
            lineVisual.Thickness = thickness;
            lineVisual.Color = color;

            foreach (var line in lines)
            {
                lineVisual.AddLine(line.Item1, line.Item2);
            }

            _viewport.Children.Add(lineVisual);
            _visuals.Add(lineVisual);
        }
Ejemplo n.º 10
0
        private void lblLargeMap_MouseUp(object sender, MouseButtonEventArgs e)
        {
            _isLargeMap = !_isLargeMap;

            // Come up with new values (and color the control)
            Point3D cameraPos = new Point3D();
            double mouseCursorScale = 1d;
            if (_isLargeMap)
            {
                lblLargeMap.Background = _toggleBrush;

                _boundryMin = new Vector3D(-WIDTH_LARGE, -WIDTH_LARGE, -DEPTH);
                _boundryMax = new Vector3D(WIDTH_LARGE, WIDTH_LARGE, DEPTH);
                cameraPos = new Point3D(0, 0, CAMERAZ_LARGE);

                mouseCursorScale = MOUSECURSORLARGESCALE;
            }
            else
            {
                lblLargeMap.Background = Brushes.Transparent;

                _boundryMin = new Vector3D(-WIDTH_SMALL, -WIDTH_SMALL, -DEPTH);
                _boundryMax = new Vector3D(WIDTH_SMALL, WIDTH_SMALL, DEPTH);
                cameraPos = new Point3D(0, 0, CAMERAZ_SMALL);
            }

            #region Change Boundry

            foreach (ScreenSpaceLines3D line in _lines)
            {
                _viewport.Children.Remove(line);
            }
            _lines.Clear();

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

            //TODO:  Make a private method that does this
            Color lineColor = Color.FromArgb(255, 200, 200, 180);
            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);
            }

            RecalculateLineGeometries();

            #endregion

            _mouseCursorGeometry.Transform = new ScaleTransform3D(mouseCursorScale, mouseCursorScale, mouseCursorScale);

            _camera.Position = cameraPos;
        }
Ejemplo n.º 11
0
        private Visual3D[] GetHull(ITriangleIndexed[] triangles, bool drawFaces, bool drawLines, bool drawNormals, bool nearlyTransparent, bool softFaces, bool isBrightLines)
        {
            List<Visual3D> retVal = new List<Visual3D>();

            if (drawLines)
            {
                #region Lines

                // Draw the lines
                ScreenSpaceLines3D lineVisual = new ScreenSpaceLines3D(true);

                lineVisual.Thickness = (!drawFaces || nearlyTransparent) ?
                    LINETHICKNESS_SCREENSPACE * .5d :
                    LINETHICKNESS_SCREENSPACE;

                lineVisual.Color = isBrightLines ?
                    _colors.PrimaryLine_Bright :
                    _colors.PrimaryLine_Dark;

                Point3D[] points = triangles[0].AllPoints;

                foreach (var line in TriangleIndexed.GetUniqueLines(triangles))
                {
                    lineVisual.AddLine(points[line.Item1], points[line.Item2]);
                }

                //_viewport.Children.Add(lineVisual);
                //_visuals.Add(lineVisual);

                retVal.Add(lineVisual);

                #endregion
            }

            if (drawNormals)
            {
                #region Normals

                // Draw the lines
                ScreenSpaceLines3D lineVisual = new ScreenSpaceLines3D(true);
                lineVisual.Thickness = (!drawFaces || nearlyTransparent) ?
                    LINETHICKNESS_SCREENSPACE * .5d :
                    LINETHICKNESS_SCREENSPACE;
                lineVisual.Color = _colors.NormalLine;

                foreach (TriangleIndexed triangle in triangles)
                {
                    Point3D centerPoint = triangle.GetCenterPoint();
                    lineVisual.AddLine(centerPoint, centerPoint + triangle.Normal);
                }

                //_viewport.Children.Add(lineVisual);
                //_visuals.Add(lineVisual);

                retVal.Add(lineVisual);

                #endregion
            }

            if (drawFaces)
            {
                #region Faces

                // Material
                MaterialGroup materials = new MaterialGroup();
                materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(nearlyTransparent ? _colors.HullFaceTransparent : _colors.HullFace)));

                if (nearlyTransparent)
                {
                    materials.Children.Add(_colors.HullFaceSpecularTransparent);
                }
                else
                {
                    if (softFaces)
                    {
                        materials.Children.Add(_colors.HullFaceSpecularSoft);
                    }
                    else
                    {
                        materials.Children.Add(_colors.HullFaceSpecular);
                    }
                }

                // Geometry Mesh
                MeshGeometry3D mesh = null;

                if (softFaces)
                {
                    mesh = UtilityWPF.GetMeshFromTriangles(TriangleIndexed.Clone_CondensePoints(triangles));
                }
                else
                {
                    mesh = UtilityWPF.GetMeshFromTriangles_IndependentFaces(triangles);
                }

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

                // Model Visual
                ModelVisual3D visual = new ModelVisual3D();
                visual.Content = geometry;

                //_viewport.Children.Add(visual);
                //_visuals.Add(visual);

                retVal.Add(visual);

                #endregion
            }

            return retVal.ToArray();
        }
        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 btnStaticSphere3_Click(object sender, RoutedEventArgs e)
        {
            RemoveCurrentBody();

            #region WPF Model

            // Material
            MaterialGroup materials = new MaterialGroup();
            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(_colors.HullFace)));
            materials.Children.Add(_colors.HullFaceSpecular);

            // Geometry Mesh
            MeshGeometry3D mesh = UtilityWPF.GetSphere_LatLon(4, 1d);

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

            // Transform
            //transform = new Transform3DGroup();		// rotate needs to be added before translate
            //rotation = _defaultDirectionFacing.GetAngleAroundAxis(directionFacing);
            //transform.Children.Add(new RotateTransform3D(new QuaternionRotation3D(rotation)));
            //transform.Children.Add(new TranslateTransform3D(position.ToVector()));

            // Model Visual
            _model = new ModelVisual3D();
            _model.Content = geometry;
            _model.Transform = _modelOrientationTrackball.Transform;

            #endregion

            // Hull
            _fluidHull = new FluidHull();
            _fluidHull.Triangles = FluidHull.FluidTriangle.GetTrianglesFromMesh(mesh);
            _fluidHull.IsClosedConvexInUniformField = chkClosedHulls.IsChecked.Value;
            _fluidHull.Field = _field;

            // Wireframe
            _modelWireframe = GetModelWireframe(_fluidHull);
            _modelWireframe.Transform = _modelOrientationTrackball.Transform;
            _viewport.Children.Add(_modelWireframe);

            // Add to the viewport
            _viewport.Children.Add(_model);
        }
Ejemplo n.º 14
0
        private Visual3D GetStrokeVisual_PATH(Tuple<Point3D, Vector3D>[] points)
        {

            //TODO: Draw the first points larger, then taper off.  May want a bezier with the velocities as control points

            ScreenSpaceLines3D retVal = new ScreenSpaceLines3D();
            retVal.Color = UtilityWPF.ColorFromHex("CCC");
            retVal.Thickness = 2;

            if (points.Length == 1)
            {
                #region single point

                Point3D secondPoint = points[0].Item1;
                if (points[0].Item2.IsNearZero())
                {
                    secondPoint += Math3D.GetRandomVector_Spherical(.02);
                }
                else
                {
                    secondPoint += points[0].Item2;
                }

                retVal.AddLine(points[0].Item1, secondPoint);

                #endregion
            }
            else
            {
                for (int cntr = 0; cntr < points.Length - 1; cntr++)
                {
                    retVal.AddLine(points[cntr].Item1, points[cntr + 1].Item1);
                }
            }

            return retVal;
        }
        private void RemoveCurrentBody()
        {
            _forceLines.Clear();

            #region Rope Joints

            foreach (JointBase joint in _ropeJoints)
            {
                joint.Dispose();
            }

            _ropeJoints.Clear();

            #endregion

            #region Anchor Bodies

            foreach (Body body in _anchorBodies)
            {
                if (body.Visuals != null)
                {
                    foreach (Visual3D visual in body.Visuals)		// visuals may be stored here, or in _model/_modelWireframe.  Putting if statements all over to be safe
                    {
                        if (_viewport.Children.Contains(visual))
                        {
                            _viewport.Children.Remove(visual);
                        }
                    }
                }

                body.Dispose();
            }

            _anchorBodies.Clear();

            #endregion
            #region Rope Bodies

            foreach (Body body in _ropeBodies)
            {
                if (body.Visuals != null)
                {
                    foreach (Visual3D visual in body.Visuals)		// visuals may be stored here, or in _model/_modelWireframe.  Putting if statements all over to be safe
                    {
                        if (_viewport.Children.Contains(visual))
                        {
                            _viewport.Children.Remove(visual);
                        }
                    }
                }
            }

            _ropeBodies.Clear();

            #endregion
            #region Main Body

            if (_body != null)
            {
                if (_body.Visuals != null)
                {
                    foreach (Visual3D visual in _body.Visuals)		// visuals may be stored here, or in _model/_modelWireframe.  Putting if statements all over to be safe
                    {
                        if (_viewport.Children.Contains(visual))
                        {
                            _viewport.Children.Remove(visual);
                        }
                    }
                }

                _body.BodyMoved -= new EventHandler(Body_BodyMoved);
                _body.ApplyForceAndTorque -= new EventHandler<BodyApplyForceAndTorqueArgs>(Body_ApplyForceAndTorque);
                _body.Dispose();
                _body = null;
            }

            #endregion

            #region Model

            if (_model != null)
            {
                _viewport.Children.Remove(_model);
                _model = null;
            }

            #endregion
            #region Model Wireframe

            if (_modelWireframe != null)
            {
                _viewport.Children.Remove(_modelWireframe);
                _modelWireframe = null;
            }

            #endregion

            _fluidHull = null;
        }
Ejemplo n.º 16
0
        private void ShowLine(Point3D point1, Point3D point2, Color color)
        {
            ScreenSpaceLines3D line = new ScreenSpaceLines3D();
            line.Color = color;
            line.Thickness = 1;
            line.AddLine(point1, point2);

            _debugVisuals.Add(line);
            _viewport.Children.Add(line);
        }
Ejemplo n.º 17
0
        private void ShowLine(IEnumerable<Tuple<Point3D, Point3D>> lines, Color color)
        {
            ScreenSpaceLines3D line = new ScreenSpaceLines3D();
            line.Color = color;
            line.Thickness = 1;

            foreach (var segment in lines)
            {
                line.AddLine(segment.Item1, segment.Item2);
            }

            _debugVisuals.Add(line);
            _viewport.Children.Add(line);
        }
        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);
            }
        }
        private void DrawLines(Tuple<Point3D, Vector3D>[] lines, Vector3D offset, Color color)
        {
            ScreenSpaceLines3D lineVisual = new ScreenSpaceLines3D(true);
            lineVisual.Color = color;
            lineVisual.Thickness = 2d;

            foreach (var line in lines)
            {
                lineVisual.AddLine(line.Item1 + offset, line.Item1 + line.Item2 + offset);
            }

            _debugVisuals.Add(lineVisual);
            _viewport.Children.Add(lineVisual);
        }
        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);
            }
        }
Ejemplo n.º 21
0
        private void AddLines(Point3D[] points, Color color, double thickness = 1d)
        {
            ScreenSpaceLines3D lineVisual = new ScreenSpaceLines3D(true);
            lineVisual.Thickness = thickness;
            lineVisual.Color = color;

            for (int cntr = 0; cntr < points.Length - 1; cntr++)
            {
                lineVisual.AddLine(points[cntr], points[cntr + 1]);
            }

            _viewport.Children.Add(lineVisual);
            _visuals.Add(lineVisual);
        }
Ejemplo n.º 22
0
        private ScreenSpaceLines3D BuildLinksSprtLine(Point3D from, Point3D to, double weight)
        {
            ScreenSpaceLines3D retVal = new ScreenSpaceLines3D();
            if (weight > 0)
            {
                retVal.Color = UtilityWPF.ColorFromHex(COLOR_POSITIVE);
            }
            else
            {
                retVal.Color = UtilityWPF.ColorFromHex(COLOR_NEGATIVE);
            }
            retVal.Thickness = Math.Abs(weight) * 2d;
            retVal.AddLine(from, to);

            return retVal;
        }
        private static Visual3D GetHoverVisual(Axis3DProps axis, Bar3DProps bar, bool isHover)
        {
            //TODO:
            //  probably a flattened semitransparent dome over top and bottom of bar
            //  or maybe a semitransparent plate that hovers over top and bottom of bar

            double halfBarSize = axis.BarSize / 2d;

            double x = -axis.HalfX + (bar.X * axis.BarSize) + halfBarSize;
            double y = axis.HalfY - (bar.Y * axis.BarSize) - halfBarSize;

            double zPos = axis.AxisOffset + (axis.ZHeight * 1.5);
            double zNeg;
            if (axis.AxisOffset.IsNearZero())
            {
                zNeg = -zPos;
            }
            else
            {
                zNeg = axis.AxisOffset - (axis.ZHeight * .1);
            }

            ScreenSpaceLines3D retVal = new ScreenSpaceLines3D();

            if (isHover)
            {
                retVal.Color = UtilityWPF.AlphaBlend(Colors.LimeGreen, Colors.Gray, .33);
                retVal.Thickness = 1.5;
            }
            else
            {
                retVal.Color = Colors.LimeGreen;
                retVal.Thickness = 4;
            }

            retVal.AddLine(new Point3D(x, y, zNeg), new Point3D(x, y, zPos));

            return retVal;
        }
Ejemplo n.º 24
0
        private Visual3D[] GetStrokeVisual(Tuple<Point3D, Vector3D>[] points)
        {
            Model3DGroup models = new Model3DGroup();

            MaterialGroup materials = new MaterialGroup();
            materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("EEE"))));
            materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.ColorFromHex("FFF")), 4));

            ScreenSpaceLines3D lines = new ScreenSpaceLines3D();
            lines.Color = UtilityWPF.ColorFromHex("EEE");
            lines.Thickness = 2;

            for (int cntr = 0; cntr < points.Length - 1; cntr++)
            {
                #region velocity line

                Point3D secondPoint = points[cntr].Item1;
                if (points[cntr].Item2.IsNearZero())
                {
                    secondPoint += Math3D.GetRandomVector_Spherical(.02);
                }
                else
                {
                    secondPoint += points[cntr].Item2 * .75;
                }

                lines.AddLine(points[cntr].Item1, secondPoint);

                #endregion
                #region dot

                GeometryModel3D geometry = new GeometryModel3D();
                geometry.Material = materials;
                geometry.BackMaterial = materials;
                geometry.Geometry = UtilityWPF.GetSphere_Ico(.15, 1, true);

                geometry.Transform = new TranslateTransform3D(points[cntr].Item1.ToVector());

                models.Children.Add(geometry);

                #endregion
            }

            ModelVisual3D dotVisual = new ModelVisual3D();
            dotVisual.Content = models;

            return new Visual3D[] { lines, dotVisual };
        }
        private ScreenSpaceLines3D GetModelWireframe(FluidHull hull)
        {
            ScreenSpaceLines3D retVal = new ScreenSpaceLines3D();
            retVal.Thickness = 1d;
            retVal.Color = _colors.HullWireFrame;

            FluidHull.FluidTriangle[] triangles = hull.Triangles;

            if (triangles.Length > 0)
            {
                Point3D[] allPoints = triangles[0].AllPoints;

                foreach (Tuple<int, int> line in TriangleIndexed.GetUniqueLines(triangles))
                {
                    retVal.AddLine(allPoints[line.Item1], allPoints[line.Item2]);
                }
            }

            return retVal;
        }
Ejemplo n.º 26
0
        private void AddLines_ScreenSpace(IEnumerable<Tuple<int, int>> lines, Point3D[] points, double thickness, Color color)
        {
            // Draw the lines
            ScreenSpaceLines3D lineVisual = new ScreenSpaceLines3D(true);
            lineVisual.Thickness = thickness;
            lineVisual.Color = color;

            foreach (var line in lines)
            {
                lineVisual.AddLine(points[line.Item1], points[line.Item2]);
            }

            _viewport.Children.Add(lineVisual);
            _visuals.Add(lineVisual);
        }
Ejemplo n.º 27
0
 public NeuronLink(bool from_IsInput, int from_Index, bool to_IsOutput, int to_Index, double weight, ScreenSpaceLines3D visual)
 {
     this.From_IsInput = from_IsInput;
     this.From_Index = from_Index;
     this.To_IsOutput = to_IsOutput;
     this.To_Index = to_Index;
     this.Weight = weight;
     this.Visual = visual;
     this.Value = 0d;
 }
Ejemplo n.º 28
0
        private void AddLines_ScreenSpace(IEnumerable<Point3D> line, double thickness, Color color)
        {
            ScreenSpaceLines3D lineVisual = new ScreenSpaceLines3D(true);
            lineVisual.Thickness = thickness;
            lineVisual.Color = color;

            Point3D? prev = null;

            foreach (var point in line)
            {
                if (prev == null)
                {
                    prev = point;
                    continue;
                }

                lineVisual.AddLine(prev.Value, point);

                prev = point;
            }

            _viewport.Children.Add(lineVisual);
            _visuals.Add(lineVisual);
        }
Ejemplo n.º 29
0
        private Visual3D[] GetStrokeVisual_VELOCITIES(Tuple<Point3D, Vector3D>[] points)
        {
            ScreenSpaceLines3D retVal = new ScreenSpaceLines3D();
            retVal.Color = UtilityWPF.ColorFromHex("EEE");
            retVal.Thickness = 2;

            for (int cntr = 0; cntr < points.Length - 1; cntr++)
            {
                Point3D secondPoint = points[cntr].Item1;
                if (points[cntr].Item2.IsNearZero())
                {
                    secondPoint += Math3D.GetRandomVector_Spherical(.02);
                }
                else
                {
                    secondPoint += points[cntr].Item2;
                }

                retVal.AddLine(points[cntr].Item1, secondPoint);
            }

            return new Visual3D[] { retVal };
        }
Ejemplo n.º 30
0
        private ModelVisual3D GetShipCompassBlip(Ship ship)
        {
            ScreenSpaceLines3D retVal = new ScreenSpaceLines3D(true);
            retVal.Thickness = 2d;
            retVal.Color = Colors.DodgerBlue;
            retVal.AddLine(new Point3D(0, 170, 20), new Point3D(0, 1000, 20));

            retVal.Transform = new TranslateTransform3D(ship.PositionWorld.ToVector());

            // Exit Function
            return retVal;
        }