private void BuildGrid() { grid = LineGrid <SpriteCell> .BeginShape() .Segment(300) .EndShape(); map2D = new ArchimedeanSpiralMap(CellDimensions, grid) .AnchorCellMiddleCenter() .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(grid); map = map2D .To3DXY(); foreach (var point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = map[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.2f; cell.name = point.ToString(); grid[point] = cell; } voronoiMap = new VoronoiMap <LinePoint>(grid, map2D); ExampleUtils.PaintScreenTexture(plane, voronoiMap, ColorFunction); }
private void BuildGrid() { var pointList = PoissonDisk.GeneratePoisson(ExampleUtils.ScreenRect, cellDimensions.magnitude, 10); grid = LineGrid<SpriteCell>.BeginShape().Segment(pointList.Count).EndShape(); var map2D = VoronoiMap<LinePoint>.MakeMap(pointList); voronoiMap = map2D.To3DXY(); foreach (var point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = voronoiMap[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.1f; cell.name = point.ToString(); grid[point] = cell; } ExampleUtils.PaintScreenTexture(plane, voronoiMap.To2D(), ColorFunction); }
private void BuildGrid() { var pointList = PoissonDisk.GeneratePoisson(ExampleUtils.ScreenRect, cellDimensions.magnitude, 10); grid = LineGrid <SpriteCell> .BeginShape().Segment(pointList.Count).EndShape(); var map2D = VoronoiMap <LinePoint> .MakeMap(pointList); voronoiMap = map2D.To3DXY(); foreach (var point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = voronoiMap[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.1f; cell.name = point.ToString(); grid[point] = cell; } ExampleUtils.PaintScreenTexture(plane, voronoiMap.To2D(), ColorFunction); }
private void BuildGrid() { grid = LineGrid<SpriteCell> .BeginShape() .Segment(300) .EndShape(); map2D = new ArchimedeanSpiralMap(CellDimensions, grid) .AnchorCellMiddleCenter() .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(grid); map = map2D .To3DXY(); foreach (var point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = map[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; cell.Color = ExampleUtils.Colors[ColorFunction(point)] + Color.white * 0.2f; cell.name = point.ToString(); grid[point] = cell; } voronoiMap = new VoronoiMap<LinePoint>(grid, map2D); ExampleUtils.PaintScreenTexture(plane, voronoiMap, ColorFunction); }
public Direction(LineGrid grid, Tuple <int, int> currentPosition) { UpChar = GetUp(grid, currentPosition); DownChar = GetDown(grid, currentPosition); RightChar = GetRight(grid, currentPosition); LeftChar = GetLeft(grid, currentPosition); }
public static bool __CompilerHint__Line__TileCell() { var grid = new LineGrid<TileCell[]>(1, 1); foreach(var point in grid) { grid[point] = new TileCell[1]; } var shapeStorageInfo = new ShapeStorageInfo<LinePoint>(new IntRect(), p => true); var shapeInfo = new LineShapeInfo<TileCell>(shapeStorageInfo); return grid[grid.First()][0] == null || shapeInfo.Translate(LinePoint.Zero) != null; }
//pathfind to connect individual Line private static void PathFindLine(LineGrid grid, Line line, Line target) { //target position var targetpos = target.GetNode(0); //list of nodes opened List <Vector2Int> open = new List <Vector2Int> { line.GetNode(0) }; //list of nodes closed List <Vector2Int> closed = new List <Vector2Int>(); //pathfind do { var currentpos = grid.GetBest(open, targetpos); if (!grid.IsFree(currentpos)) { //ahh too bad... (uncomplete path) grid.TraceBackwards(line, currentpos); return; } if (currentpos == targetpos) { //found a full path! grid.TraceBackwards(line, targetpos); return; } var allpossible = grid.GetAllAdjacentFree(currentpos, targetpos); foreach (var pos in allpossible) { if (!open.Contains(pos) && !closed.Contains(pos)) { open.Add(pos); grid.SetParent(pos, currentpos); } } open.Remove(currentpos); closed.Add(currentpos); }while (open.Count != 0); if (closed.Count >= 3 && Random.Range(0, 5) == 1) { grid.TraceBackwards(line, closed[Random.Range(closed.Count / 2, closed.Count)]); } return; }
public EditorProperties() { mPositionsRelativeToCamera = false; mSnapToGrid = false; mConstrainDimensions = false; mPixelSize = 0; mLineGrid = new LineGrid(); mLineGrid.Visible = false; }
public void ToLineGrid(LineGrid lineGridToModify) { lineGridToModify.NumberOfHorizontalLines = NumberOfHorizontalLines; lineGridToModify.NumberOfVerticalLines = NumberOfVerticalLines; lineGridToModify.X = X; lineGridToModify.Y = Y; lineGridToModify.DistanceBetweenLines = DistanceBetweenLines; lineGridToModify.Visible = Visible; }
public void ToLineGrid(LineGrid lineGridToModify) { lineGridToModify.NumberOfHorizontalLines = NumberOfHorizontalLines; lineGridToModify.NumberOfVerticalLines = NumberOfVerticalLines; lineGridToModify.X = X; lineGridToModify.Y = Y; lineGridToModify.DistanceBetweenLines = DistanceBetweenLines; lineGridToModify.Visible = Visible; }
public void Start() { var grid = LineGrid <int> .BeginShape() .Segment(10) .EndShape(); var map = new ArchimedeanSpiralMap(CellDimensions, grid); var voronoiMap = new VoronoiMap <LinePoint>(grid, map); ExampleUtils.PaintScreenTexture(plane, voronoiMap, n => GLMathf.FloorMod(n, 12)); }
public void Initialize(ImageRegionSelectionControl control, SystemManagers managers, WireframeEditControls wireframeControl, WireframeEditControlsViewModel wireframeEditControlsViewModel) { addCursor = new System.Windows.Forms.Cursor(this.GetType(), "Content.AddCursor.cur"); mManagers = managers; mManagers.Renderer.SamplerState = SamplerState.PointClamp; mControl = control; keyboard = new Keyboard(); keyboard.Initialize(control); mManagers.Renderer.Camera.CameraCenterOnScreen = CameraCenterOnScreen.TopLeft; mWireframeControl = wireframeControl; mControl.RegionChanged += new EventHandler(HandleRegionChanged); mControl.MouseWheelZoom += new EventHandler(HandleMouseWheelZoom); mControl.AvailableZoomLevels = mWireframeControl.AvailableZoomLevels; mControl.XnaUpdate += new Action(HandleXnaUpdate); mControl.Panning += HandlePanning; mSpriteOutline = new LineRectangle(managers); managers.ShapeManager.Add(mSpriteOutline); mSpriteOutline.Visible = false; mSpriteOutline.Color = OutlineColor; selectionPreviewRectangle = new LineRectangle(managers); managers.ShapeManager.Add(selectionPreviewRectangle); selectionPreviewRectangle.Visible = false; selectionPreviewRectangle.Color = MagicWandPreviewColor; // Move them up one Z to put them above the sprites: selectionPreviewRectangle.Z = 1; mLineGrid = new LineGrid(managers); managers.ShapeManager.Add(mLineGrid); mLineGrid.Visible = false; mLineGrid.Color = OutlineColor; mControl.Click += new EventHandler(HandleClick); mStatusText = new StatusTextController(managers); mControl_XnaInitialize(); WireframeEditControlsViewModel = wireframeEditControlsViewModel; WireframeEditControlsViewModel.PropertyChanged += HandleWireframePropertyChanged; }
public static LineGridSave FromLineGrid(LineGrid lineGrid) { LineGridSave lineGridSave = new LineGridSave(); lineGridSave.NumberOfHorizontalLines = lineGrid.NumberOfHorizontalLines; lineGridSave.NumberOfVerticalLines = lineGrid.NumberOfVerticalLines; lineGridSave.X = lineGrid.X; lineGridSave.Y = lineGrid.Y; lineGridSave.DistanceBetweenLines = lineGrid.DistanceBetweenLines; lineGridSave.Visible = lineGrid.Visible; return lineGridSave; }
public static LineGridSave FromLineGrid(LineGrid lineGrid) { LineGridSave lineGridSave = new LineGridSave(); lineGridSave.NumberOfHorizontalLines = lineGrid.NumberOfHorizontalLines; lineGridSave.NumberOfVerticalLines = lineGrid.NumberOfVerticalLines; lineGridSave.X = lineGrid.X; lineGridSave.Y = lineGrid.Y; lineGridSave.DistanceBetweenLines = lineGrid.DistanceBetweenLines; lineGridSave.Visible = lineGrid.Visible; return(lineGridSave); }
private void RefreshGrid() { if (ShowGrid && lineGrid == null) { lineGrid = new LineGrid(); } if (lineGrid != null) { lineGrid.Visible = ShowGrid; } if (lineGrid?.Visible == true) { lineGrid.DistanceBetweenLines = cellSize; lineGrid.NumberOfHorizontalLines = 41; lineGrid.NumberOfVerticalLines = 41; } }
//pathfind to connect the lines private static void PathFindLines(LineGrid grid) { foreach (var line in grid.Lines) { //if line desnt exist ignore if (!grid.IsFree(line.GetNode(0))) { continue; } //chose target and if none can be chosen ignore var target = grid.ChooseTarget(line); if (target == null) { continue; } PathFindLine(grid, line, target); //grid.Print(); } }
public void Initialize(ImageRegionSelectionControl control, SystemManagers managers, WireframeEditControls wireframeControl) { mManagers = managers; mManagers.Renderer.SamplerState = SamplerState.PointClamp; mControl = control; keyboard = new Keyboard(); keyboard.Initialize(control); mManagers.Renderer.Camera.CameraCenterOnScreen = CameraCenterOnScreen.TopLeft; mWireframeControl = wireframeControl; mWireframeControl.WandSelectionChanged += ReactToMagicWandChange; mControl.RegionChanged += new EventHandler(HandleRegionChanged); mControl.MouseWheelZoom += new EventHandler(HandleMouseWheelZoom); mControl.AvailableZoomLevels = mWireframeControl.AvailableZoomLevels; mControl.XnaUpdate += new Action(HandleXnaUpdate); mControl.Panning += HandlePanning; mSpriteOutline = new LineRectangle(managers); managers.ShapeManager.Add(mSpriteOutline); mSpriteOutline.Visible = false; mSpriteOutline.Color = OutlineColor; mLineGrid = new LineGrid(managers); managers.ShapeManager.Add(mLineGrid); mLineGrid.Visible = false; mLineGrid.Color = OutlineColor; mControl.Click += new EventHandler(HandleClick); mStatusText = new StatusTextController(managers); mControl_XnaInitialize(); }
private static ValidMoves CheckValidMoves(LineGrid grid, Tuple <int, int> currentPosition, char currentPosChar, Dictionary <Tuple <int, int>, int> positionDict, ValidMoves lastMove) { var dir = new Direction(grid, currentPosition); switch (currentPosChar) { case '-': dir.IsLeft = !OnList(positionDict, currentPosition, 0, -1) && new char[] { '+', '-', 'X' }.Contains(dir.LeftChar); dir.IsRight = !OnList(positionDict, currentPosition, 0, 1) && new char[] { '+', '-', 'X' }.Contains(dir.RightChar); return(dir.GetMove()); case '|': dir.IsUp = !OnList(positionDict, currentPosition, -1, 0) && new char[] { '+', 'X', '|' }.Contains(dir.UpChar); dir.IsDown = !OnList(positionDict, currentPosition, 1, 0) && new char[] { '+', 'X', '|' }.Contains(dir.DownChar); return(dir.GetMove()); case '+': dir.IsUp = (!OnList(positionDict, currentPosition, -1, 0)) && (lastMove != ValidMoves.Down && lastMove != ValidMoves.Up && new char[] { '+', '|', 'X' }.Contains(dir.UpChar)); dir.IsDown = (!OnList(positionDict, currentPosition, 1, 0)) && (lastMove != ValidMoves.Down && lastMove != ValidMoves.Up && new char[] { '+', '|', 'X' }.Contains(dir.DownChar)); dir.IsLeft = !OnList(positionDict, currentPosition, 0, -1) && (lastMove != ValidMoves.Left && lastMove != ValidMoves.Right && new char[] { '+', '-', 'X' }.Contains(dir.LeftChar)); dir.IsRight = !OnList(positionDict, currentPosition, 0, 1) && (lastMove != ValidMoves.Left && lastMove != ValidMoves.Right && new char[] { '+', '-', 'X' }.Contains(dir.RightChar)); return(dir.GetMove()); case 'X': dir.IsUp = !OnList(positionDict, currentPosition, -1, 0) && new char[] { '+', 'X', '|' }.Contains(dir.UpChar); dir.IsDown = !OnList(positionDict, currentPosition, 1, 0) && new char[] { '+', 'X', '|' }.Contains(dir.DownChar); dir.IsLeft = !OnList(positionDict, currentPosition, 0, -1) && new char[] { '+', '-', 'X' }.Contains(dir.LeftChar); dir.IsRight = !OnList(positionDict, currentPosition, 0, 1) && new char[] { '+', '-', 'X' }.Contains(dir.RightChar); return(dir.GetMove()); default: throw new ArgumentException($"Invalid Current Position Character - '{currentPosChar}'", nameof(currentPosChar)); } }
private static char GetDown(LineGrid grid, Tuple <int, int> currentPosition) => currentPosition.Item1 >= grid.RowCount - 1 ? ' ' : grid.Grid[currentPosition.Item1 + 1][currentPosition.Item2];
private static char GetUp(LineGrid grid, Tuple <int, int> currentPosition) => currentPosition.Item1 <= 0 ? ' ' : grid.Grid[currentPosition.Item1 - 1][currentPosition.Item2];
private static char GetRight(LineGrid grid, Tuple <int, int> currentPosition) => currentPosition.Item2 >= grid.ColumnCount - 1 ? ' ' : grid.Grid[currentPosition.Item1][currentPosition.Item2 + 1];
//Populate the line grid with line points from the ports private static void PopulatePorts(LineGrid grid, int subspaces, List <int>[] allPorts, int numLines) { var id = 1; //LEFT var target = 0; var ports = allPorts[0]; foreach (var i in ports) { for (var j = subspaces - 1; j >= 0; j--) { var line = new Line(new Vector2Int(0, i * subspaces + j), id++, target); grid.AddLine(line); target = (target + 1) % numLines; } } //TOP target = 0; ports = allPorts[1]; foreach (var i in ports) { for (var j = 0; j < subspaces; j++) { var line = new Line(new Vector2Int(i * subspaces + j, grid.h - 1), id++, target); grid.AddLine(line); target = (target + 1) % numLines; } } //RIGHT target = 0; ports = allPorts[2]; foreach (var i in ports) { for (var j = subspaces - 1; j >= 0; j--) { var line = new Line(new Vector2Int(grid.w - 1, i * subspaces + j), id++, target); grid.AddLine(line); target = (target + 1) % numLines; } } //BOTTOM target = 0; ports = allPorts[3]; foreach (var i in ports) { for (var j = 0; j < subspaces; j++) { var line = new Line(new Vector2Int(i * subspaces + j, 0), id++, target); grid.AddLine(line); target = (target + 1) % numLines; } } }
private static char GetLeft(LineGrid grid, Tuple <int, int> currentPosition) => currentPosition.Item2 <= 0 ? ' ' : grid.Grid[currentPosition.Item1][currentPosition.Item2 - 1];
public static bool Line(char[][] grid) { var newGrid = new LineGrid(grid); Console.WriteLine($"newGrid.startX1 = {newGrid.StartX1}"); Console.WriteLine($"newGrid.startX2 = {newGrid.StartX2}"); var start = newGrid.StartX1; var currentPosition = start; var currentPosChar = 'X'; var end = newGrid.StartX2; var positionDict = new Dictionary <Tuple <int, int>, int> { { currentPosition, 0 } }; var lastMove = ValidMoves.Empty; while (true) { var result = CheckValidMoves(newGrid, currentPosition, currentPosChar, positionDict, lastMove); if (result == ValidMoves.NoValid) { if (start.Equals(newGrid.StartX2)) { return(false); } start = newGrid.StartX2; end = newGrid.StartX1; currentPosition = start; currentPosChar = 'X'; positionDict.Clear(); positionDict.Add(start, 0); continue; } //Move switch (result) { case ValidMoves.Up: currentPosition = new Tuple <int, int>(currentPosition.Item1 - 1, currentPosition.Item2); lastMove = ValidMoves.Up; break; case ValidMoves.Down: currentPosition = new Tuple <int, int>(currentPosition.Item1 + 1, currentPosition.Item2); lastMove = ValidMoves.Down; break; case ValidMoves.Right: currentPosition = new Tuple <int, int>(currentPosition.Item1, currentPosition.Item2 + 1); lastMove = ValidMoves.Right; break; case ValidMoves.Left: currentPosition = new Tuple <int, int>(currentPosition.Item1, currentPosition.Item2 - 1); lastMove = ValidMoves.Left; break; default: throw new ArgumentException($"No valid move given - '{result}'", nameof(result)); } currentPosChar = newGrid.Grid[currentPosition.Item1][currentPosition.Item2]; positionDict.Add(currentPosition, 0); if (!currentPosition.Equals(end)) { continue; } var expectedBlanks = newGrid.Spaces - positionDict.Count; if (expectedBlanks != newGrid.Blanks) { continue; } return(true); } }
//Build All public static void Build(GameObject boardObj, int height, int width, float unitSize) { //parent transf var parent = boardObj.transform; var parentRenderer = parent.GetComponent <MeshRenderer>(); parentRenderer.enabled = false; //Create the gameobject GameObject gameObject = new GameObject("BoardMesh", typeof(MeshFilter), typeof(MeshRenderer)); gameObject.transform.parent = parent; //Get Materials from parent var mats = new List <Material>(); parentRenderer.GetMaterials(mats); var mainMaterial = mats[0]; var lineMaterial = mats[1]; var allPorts = new List <int> [4]; allPorts[0] = new List <int>(); allPorts[1] = new List <int>(); allPorts[2] = new List <int>(); allPorts[3] = new List <int>(); // ==== LINES ==== if (height >= 3 && width >= 3) { //board ports allPorts = GeneratePorts(width, height); //grid var gridw = width * Subspaces; var gridh = height * Subspaces; LineGrid grid = new LineGrid(gridw, gridh, width * unitSize, height * unitSize); //populate grid with port points var numLines = (int)((allPorts[0].Count + allPorts[1].Count + allPorts[2].Count + allPorts[3].Count) * Subspaces) / 4; PopulatePorts(grid, Subspaces, allPorts, numLines); //create lines from ports to other ports PathFindLines(grid); //build lines grid.BuildLines(gameObject, lineMaterial); } // ==== BOARD MESH ==== Mesh mesh = CreateBoardBaseMesh(width, height, unitSize, allPorts); //Set mesh gameObject.GetComponent <MeshFilter>().mesh = mesh; gameObject.GetComponent <MeshRenderer>().material = mainMaterial; //add outline to board var outln = gameObject.AddComponent <QuickOutline>(); outln.OutlineMode = QuickOutline.Mode.OutlineVisible; outln.OutlineColor = new Color32(7, 80, 73, 255); outln.OutlineWidth = 5; // ==== PORTS MESHES ==== CreatePorts(width, height, unitSize, allPorts, parent); return; }
public PolygonEditorSettings(LineGrid lineGrid) { }
public PolygonEditorSettings(LineGrid lineGrid) { }