/// <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(); }
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)); }
private void btnPolyIntersect_Click(object sender, RoutedEventArgs e) { try { const double MAX = 8d; ClearScene(); // Random Point[] poly1 = new Point[] { new Point(Math1D.GetNearZeroValue(MAX), Math1D.GetNearZeroValue(MAX)), new Point(Math1D.GetNearZeroValue(MAX), Math1D.GetNearZeroValue(MAX)), new Point(Math1D.GetNearZeroValue(MAX), Math1D.GetNearZeroValue(MAX)) }; Rect rect = new Rect( new Point(Math1D.GetNearZeroValue(MAX), Math1D.GetNearZeroValue(MAX)), new Size(StaticRandom.NextDouble() * MAX, StaticRandom.NextDouble() * MAX)); // Fixed //Point[] poly1 = new Point[] { new Point(-1.2, -1.2), new Point(-1.2, 0), new Point(0, -1.2) }; //Rect rect = new Rect(new Point(-1d, -1d), new Size(2d, 2d)); Point[] poly2 = new Point[] { rect.TopLeft, rect.TopRight, rect.BottomRight, rect.BottomLeft }; // With convex //Point[] poly1 = new Point[] { new Point(5, 15), new Point(20, 5), new Point(35, 15), new Point(35, 30), new Point(25, 30), new Point(20, 25), new Point(15, 35), new Point(10, 25), new Point(10, 20) }; //Point[] poly2 = new Point[] { new Point(10, 10), new Point(30, 10), new Point(30, 30), new Point(10, 30) }; #region Draw poly1 ScreenSpaceLines3D lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("808080"); lines.Thickness = 1d; for (int cntr = 0; cntr < poly1.Length - 1; cntr++) { lines.AddLine(poly1[cntr].ToPoint3D(), poly1[cntr + 1].ToPoint3D()); } lines.AddLine(poly1[poly1.Length - 1].ToPoint3D(), poly1[0].ToPoint3D()); _visuals.Add(lines); _viewport.Children.Add(lines); #endregion #region Draw poly2 lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("808080"); lines.Thickness = 1d; for (int cntr = 0; cntr < poly2.Length - 1; cntr++) { lines.AddLine(poly2[cntr].ToPoint3D(), poly2[cntr + 1].ToPoint3D()); } lines.AddLine(poly2[poly2.Length - 1].ToPoint3D(), poly2[0].ToPoint3D()); _visuals.Add(lines); _viewport.Children.Add(lines); #endregion // doing this after in case there's an exception Point[] intersect = Math2D.GetIntersection_Polygon_Polygon(poly1, poly2); #region Draw intersect if (intersect != null && intersect.Length > 0) { if (intersect.Length == 1) { Color color = UtilityWPF.ColorFromHex("202020"); // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color))); materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 100d)); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetSphere_LatLon(4, .05d); geometry.Transform = new TranslateTransform3D(intersect[0].ToVector3D()); ModelVisual3D visual = new ModelVisual3D(); visual.Content = geometry; _visuals.Add(visual); _viewport.Children.Add(visual); } else { lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("202020"); lines.Thickness = 3d; for (int cntr = 0; cntr < intersect.Length - 1; cntr++) { lines.AddLine(intersect[cntr].ToPoint3D(), intersect[cntr + 1].ToPoint3D()); } lines.AddLine(intersect[intersect.Length - 1].ToPoint3D(), intersect[0].ToPoint3D()); _visuals.Add(lines); _viewport.Children.Add(lines); } } #endregion } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
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 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); }
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; }
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); }
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); }
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 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 void ShowVoronoi(Vector3D[] after) { Point[] points2D = after.Select(o => new Point(o.X, o.Y)).ToArray(); var result = Math2D.GetVoronoi(points2D, true); if (chkCapVoronoi.IsChecked.Value) { //result = CapVoronoi.CapCircle(result); result = Math2D.CapVoronoiCircle(result); } #region Edges ScreenSpaceLines3D lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("808080"); lines.Thickness = 1d; foreach (var edge in result.Edges) { switch (edge.EdgeType) { case EdgeType.Segment: lines.AddLine(edge.Point0.ToPoint3D(), edge.Point1.Value.ToPoint3D()); break; case EdgeType.Ray: lines.AddLine(edge.Point0.ToPoint3D(), edge.Point0.ToPoint3D() + (edge.Direction.Value.ToVector3D().ToUnit() * 100)); break; case EdgeType.Line: Point3D point3D = edge.Point0.ToPoint3D(); Vector3D dir3D = edge.Direction.Value.ToVector3D().ToUnit() * 100; lines.AddLine(point3D - dir3D, point3D + dir3D); break; default: throw new ApplicationException("Unknown EdgeType: " + edge.EdgeType.ToString()); } } _visuals.Add(lines); _viewport.Children.Add(lines); #endregion #region Polygons #endregion }
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 void ShowReconstructTriangles(Point3D[] points) { //NOTE: This thinking is flawed (trying to reconstruct the triangle definitions based on the centers of the triangles) - I need this when instantiating a //camera from dna, the original control points are lost (vertices of the triangles) // //Instead, I'll go with Voronoi around the original even dist points, which is a much cleaner design all around Point3D[] points3D = points;//.Select(o => o.ToPoint()).ToArray(); Point[] points2D = points3D.Select(o => new Point(o.X, o.Y)).ToArray(); TriangleIndexed[] triangles = Math2D.GetDelaunayTriangulation(points2D, points3D); var quickHull = Math2D.GetConvexHull(points); bool[] isPerimiter = Enumerable.Range(0, points.Length).Select(o => quickHull.PerimiterLines.Contains(o)).ToArray(); var remaining = TriangleIndexed.GetUniqueLines(triangles).ToList(); #region First Pass List<Tuple<int, int>> first = new List<Tuple<int, int>>(); for (int cntr = 0; cntr < points.Length; cntr++) { // Get the lines connected to this point var connected = remaining.Where(o => o.Item1 == cntr || o.Item2 == cntr). OrderBy(o => (points[o.Item2] - points[o.Item1]).LengthSquared). ToArray(); if (connected.Length == 0) { continue; } // Of these, choose the shortest first.Add(connected[0]); } first = first.Distinct().ToList(); foreach (var shrt in first) { remaining.Remove(shrt); } #endregion #region Second Pass List<Tuple<int, int>> second = new List<Tuple<int, int>>(); for (int cntr = 0; cntr < points.Length; cntr++) { int numConnected = first.Count(o => o.Item1 == cntr || o.Item2 == cntr); if (numConnected > 3) { int seven = 8; } if (numConnected == 3) { continue; } if (isPerimiter[cntr] && numConnected == 2) { continue; } // This still needs connections var connected = remaining.Where(o => o.Item1 == cntr || o.Item2 == cntr). OrderBy(o => (points[o.Item2] - points[o.Item1]).LengthSquared). ToArray(); if (connected.Length == 0) { continue; } // Of these, choose the shortest second.Add(connected[0]); } second = second.Distinct().ToList(); foreach (var shrt in second) { remaining.Remove(shrt); } #endregion #region Third Pass List<Tuple<int, int>> third = new List<Tuple<int, int>>(); for (int cntr = 0; cntr < points.Length; cntr++) { int numConnected = first.Count(o => o.Item1 == cntr || o.Item2 == cntr); numConnected += second.Count(o => o.Item1 == cntr || o.Item2 == cntr); if (numConnected > 3) { int seven = 8; } if (numConnected == 3) { continue; } if (isPerimiter[cntr] && numConnected == 2) { continue; } // This still needs connections var connected = remaining.Where(o => o.Item1 == cntr || o.Item2 == cntr). OrderBy(o => (points[o.Item2] - points[o.Item1]).LengthSquared). ToArray(); if (connected.Length == 0) { continue; } // Of these, choose the shortest third.Add(connected[0]); } third = third.Distinct().ToList(); foreach (var shrt in third) { remaining.Remove(shrt); } #endregion #region First Lines ScreenSpaceLines3D lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("50F050"); lines.Thickness = 5d; foreach (var line in first) { lines.AddLine(points3D[line.Item1], points3D[line.Item2]); } _visuals.Add(lines); _viewport.Children.Add(lines); #endregion #region Second Lines lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("70E070"); lines.Thickness = 2d; foreach (var line in second) { lines.AddLine(points3D[line.Item1], points3D[line.Item2]); } _visuals.Add(lines); _viewport.Children.Add(lines); #endregion #region Third Lines lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("90D090"); lines.Thickness = 1d; foreach (var line in third) { lines.AddLine(points3D[line.Item1], points3D[line.Item2]); } _visuals.Add(lines); _viewport.Children.Add(lines); #endregion #region Longest Lines lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("D09090"); lines.Thickness = 1d; foreach (var line in remaining) { lines.AddLine(points3D[line.Item1], points3D[line.Item2]); } _visuals.Add(lines); _viewport.Children.Add(lines); #endregion }
private void ShowDelaunay(Vector3D[] points, bool showLines, bool showCenters, bool reconstructTriangles) { if (!showLines && !showCenters && !reconstructTriangles) { return; } Point3D[] points3D = points.Select(o => o.ToPoint()).ToArray(); Point[] points2D = points3D.Select(o => new Point(o.X, o.Y)).ToArray(); TriangleIndexed[] triangles = Math2D.GetDelaunayTriangulation(points2D, points3D); if (showLines) { #region Lines ScreenSpaceLines3D lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("709070"); lines.Thickness = 1d; foreach (var line in TriangleIndexed.GetUniqueLines(triangles)) { lines.AddLine(points3D[line.Item1], points3D[line.Item2]); } _visuals.Add(lines); _viewport.Children.Add(lines); #endregion } if (showCenters) { #region Centers Color color = Colors.Red; // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color))); materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 100d)); Model3DGroup geometries = new Model3DGroup(); for (int cntr = 0; cntr < triangles.Length; cntr++) { // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetSphere_LatLon(2, .04d); geometry.Transform = new TranslateTransform3D(triangles[cntr].GetCenterPoint().ToVector()); geometries.Children.Add(geometry); } // Add it AddVisual(geometries); #endregion } if (reconstructTriangles) { ShowReconstructTriangles(triangles.Select(o => o.GetCenterPoint()).ToArray()); } }
private void btnTestTileOverlap_Click(object sender, RoutedEventArgs e) { const double RECTZ = 0d; const double INTERSECTZ = -8d; try { if (_evenDistPoints == null) { MessageBox.Show("Create some points first", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } Match match = Regex.Match(txtPixels.Text, @"^\s*(?<x>\d+)\s*,\s*(?<y>\d+)\s*$"); if (!match.Success) { MessageBox.Show("Pixels are in the wrong format (\\d+, \\d+)", this.Title, MessageBoxButton.OK, MessageBoxImage.Warning); return; } int pixelsX = int.Parse(match.Groups["x"].Value); int pixelsY = int.Parse(match.Groups["y"].Value); Point[] points2D = _evenDistPoints.Select(o => new Point(o.X, o.Y)).ToArray(); #region Figure out the extremes Point min = new Point(points2D.Min(o => o.X), points2D.Min(o => o.Y)); Point max = new Point(points2D.Max(o => o.X), points2D.Max(o => o.Y)); double width = max.X - min.X; double height = max.Y - min.Y; // Enlarge a bit min.X -= width * .05d; min.Y -= height * .05d; max.X += width * .05d; max.Y += height * .05d; width = max.X - min.X; height = max.Y - min.Y; //Vector3D offset = new Vector3D(width * .5d, height * .5d, 0d); // can't assume half Vector3D offset = new Vector3D(-min.X, -min.Y, 0d); #endregion // Make the 3D points shifted over so that min is at 0,0 Point3D[] points3D = points2D.Select(o => new Point3D(o.X + offset.X, o.Y + offset.Y, 0d)).ToArray(); TriangleIndexed[] triangles = Math2D.GetDelaunayTriangulation(points2D, points3D); Rect[] pixelRects; var overlay = TriangleTileOverlay.GetIntersections(out pixelRects, new Size(width, height), pixelsX, pixelsY, triangles); double minPercent = overlay.SelectMany(o => o).Min(o => o.Percent); double maxPercent = overlay.SelectMany(o => o).Max(o => o.Percent); #region Tiles (lines) List<Tuple<Point3D, Point3D>> pairs = new List<Tuple<Point3D, Point3D>>(); foreach (Rect pixel in pixelRects) { pairs.Add(Tuple.Create(pixel.TopLeft.ToPoint3D(RECTZ), pixel.TopRight.ToPoint3D(RECTZ))); pairs.Add(Tuple.Create(pixel.TopRight.ToPoint3D(RECTZ), pixel.BottomRight.ToPoint3D(RECTZ))); pairs.Add(Tuple.Create(pixel.BottomRight.ToPoint3D(RECTZ), pixel.BottomLeft.ToPoint3D(RECTZ))); pairs.Add(Tuple.Create(pixel.BottomLeft.ToPoint3D(RECTZ), pixel.TopLeft.ToPoint3D(RECTZ))); } ScreenSpaceLines3D lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("505050"); lines.Thickness = 1d; foreach (var line in GetUniqueLines(pairs)) { lines.AddLine(line.Item1 - offset, line.Item2 - offset); } _viewport.Children.Add(lines); _visuals.Add(lines); #endregion if (chkTestLines.IsChecked.Value) { #region Intersections (lines) pairs.Clear(); foreach (Point[] poly in overlay.SelectMany(o => o).Select(o => o.Intersection)) { for (int cntr = 0; cntr < poly.Length - 1; cntr++) { pairs.Add(Tuple.Create(poly[cntr].ToPoint3D(INTERSECTZ), poly[cntr + 1].ToPoint3D(INTERSECTZ))); } pairs.Add(Tuple.Create(poly[poly.Length - 1].ToPoint3D(INTERSECTZ), poly[0].ToPoint3D(INTERSECTZ))); } lines = new ScreenSpaceLines3D(); lines.Color = UtilityWPF.ColorFromHex("0000FF"); lines.Thickness = 1d; foreach (var line in GetUniqueLines(pairs)) { lines.AddLine(line.Item1 - offset, line.Item2 - offset); } _viewport.Children.Add(lines); _visuals.Add(lines); #endregion } else { Model3DGroup geometries = new Model3DGroup(); Color[] triangleColors = triangles.Select(o => UtilityWPF.GetRandomColor(100, 192)).ToArray(); #region Intersections (plates) for (int triCntr = 0; triCntr < triangles.Length; triCntr++) { foreach (var poly in overlay[triCntr]) { int offsetColor = 7; Color color = UtilityWPF.GetRandomColor(192, GetOffsetCapped(triangleColors[triCntr].R, -offsetColor), GetOffsetCapped(triangleColors[triCntr].R, offsetColor), GetOffsetCapped(triangleColors[triCntr].G, -offsetColor), GetOffsetCapped(triangleColors[triCntr].G, offsetColor), GetOffsetCapped(triangleColors[triCntr].B, -offsetColor), GetOffsetCapped(triangleColors[triCntr].B, offsetColor)); // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color))); materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 100d)); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetMeshFromTriangles(Math2D.GetTrianglesFromConvexPoly(poly.Intersection, INTERSECTZ)); geometry.Transform = new TranslateTransform3D(-offset); geometries.Children.Add(geometry); } } #endregion #region Triangles (plates) for (int cntr = 0; cntr < triangles.Length; cntr++) { Color color = Color.FromArgb(96, triangleColors[cntr].R, triangleColors[cntr].G, triangleColors[cntr].B); // Material MaterialGroup materials = new MaterialGroup(); materials.Children.Add(new DiffuseMaterial(new SolidColorBrush(color))); materials.Children.Add(new SpecularMaterial(new SolidColorBrush(UtilityWPF.AlphaBlend(color, Colors.White, .5d)), 100d)); // Geometry Model GeometryModel3D geometry = new GeometryModel3D(); geometry.Material = materials; geometry.BackMaterial = materials; geometry.Geometry = UtilityWPF.GetMeshFromTriangles(new TriangleIndexed[] { triangles[cntr] }); geometry.Transform = new TranslateTransform3D(-offset); geometries.Children.Add(geometry); } #endregion ModelVisual3D visual = new ModelVisual3D(); visual.Content = geometries; _visuals.Add(visual); _viewport.Children.Add(visual); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), this.Title, MessageBoxButton.OK, MessageBoxImage.Error); } }
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 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); } }
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 }; }
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; }
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); }
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; }
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 ResetField() { _sceneRemaining = DateTime.MinValue; if (_border != null) { _viewport.Children.Remove(_border); } if (_marker2D != null) { _viewport.Children.Remove(_marker2D); } _velocityLines.Clear(); _sizeMult = 1d / _field.Size; _velocityMult = 4d; // Border Lines _border = new ScreenSpaceLines3D(); _border.Color = Colors.DimGray; _border.Thickness = 1d; double l = (_field.Size * _sizeMult) / 2d; // using lower case l to represent half (just because it looks a lot like 1) _border.AddLine(new Point3D(-l, -l, -l), new Point3D(l, -l, -l)); _border.AddLine(new Point3D(l, -l, -l), new Point3D(l, l, -l)); _border.AddLine(new Point3D(l, l, -l), new Point3D(-l, l, -l)); _border.AddLine(new Point3D(-l, l, -l), new Point3D(-l, -l, -l)); _border.AddLine(new Point3D(-l, -l, l), new Point3D(l, -l, l)); _border.AddLine(new Point3D(l, -l, l), new Point3D(l, l, l)); _border.AddLine(new Point3D(l, l, l), new Point3D(-l, l, l)); _border.AddLine(new Point3D(-l, l, l), new Point3D(-l, -l, l)); _border.AddLine(new Point3D(-l, -l, -l), new Point3D(-l, -l, l)); _border.AddLine(new Point3D(l, -l, -l), new Point3D(l, -l, l)); _border.AddLine(new Point3D(l, l, -l), new Point3D(l, l, l)); _border.AddLine(new Point3D(-l, l, -l), new Point3D(-l, l, l)); _viewport.Children.Add(_border); ShowHideBlockedCells(); // this will update _blockedCellsWireframe if (_lookDirection != null) { ViewChanged(_lookDirection.Value); // this will update _marker2D } }
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); }
private static Visual3D GetVisual_Line(Point3D from, Point3D to, Color color, double thickness) { ScreenSpaceLines3D retVal = new ScreenSpaceLines3D(); retVal.Color = color; retVal.Thickness = thickness; 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; }
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); }
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 ShowHideBlockedCells() { _isBlockedCellDirty = false; // Wipe out the old one if (_blockedCellsWireframe != null) { _viewport.Children.Remove(_blockedCellsWireframe); _blockedCellsWireframe = null; } // See if a new one needs to be created if (!chkShowBlockedCells.IsChecked.Value || _field == null) { return; } int[] blockedCellIndices = Enumerable.Range(0, _field.Size1D).Where(o => _field.Blocked[o]).ToArray(); if (blockedCellIndices.Length == 0) { return; } Rectangle3DIndexedMapped[] cells = _field.GetCells(_sizeMult * _field.Size); // Get a deduped list of blocked cell's edge lines var lines = Rectangle3DIndexed.GetEdgeLinesDeduped(blockedCellIndices.Select(o => cells[o])); // Create the visual _blockedCellsWireframe = new ScreenSpaceLines3D(); _blockedCellsWireframe.Color = UtilityWPF.ColorFromHex("60FFFFFF"); _blockedCellsWireframe.Thickness = 1; Point3D[] allPoints = cells[0].AllPoints; foreach (var line in lines) { _blockedCellsWireframe.AddLine(allPoints[line.Item1], allPoints[line.Item2]); } _viewport.Children.Add(_blockedCellsWireframe); }