/// <summary> /// Returns the center pixel of a hexagon /// </summary> public PointF HexToPixel() { HexAxial axial = ToAxial(); PointF pixel = axial.HexToPixel(); return(pixel); }
public void SetCell(Point mousePosition, int layerId, int paletteId, int terrainId) { HexAxial axial = DetermineHexAtMousePointer(mousePosition); _grid.SetCell(axial, layerId, paletteId, terrainId); IsDirty = true; }
public void RemoveImageFromCell(Point mousePosition, int layerId) { HexAxial axial = DetermineHexAtMousePointer(mousePosition); _grid.RemoveImageFromCell(axial, layerId); IsDirty = true; }
public HexAxial ToAxial() { float q = X; float r = Z; var axial = new HexAxial(q, r); return(axial); }
public HexAxial DetermineHexAtMousePointer(Point mousePosition) { var mousePositionRelativeToCenter = new PointF { X = mousePosition.X - Center.X, Y = mousePosition.Y - Center.Y }; HexAxial axial = mousePositionRelativeToCenter.PixelToHex(); return(axial); }
private HexAxial GetHexagon(string coordsString) { string[] coords = coordsString.Split(';'); float q = Convert.ToSingle(coords[0]); float r = Convert.ToSingle(coords[1]); var axial = new HexAxial(q, r); return(axial); }
public static HexAxial PixelToHex(this PointF pixel) { float q = pixel.X * Constants.TWO_THIRDS / Constants.HALF_HEX_WIDTH; //double r = (-pixel.X / 3.0f + (Math.Sqrt(3)/3.0f) * pixel.Y) / Constants.HALF_HEX_HEIGHT; double r = (-pixel.X / 3.0f + Constants.HALF * pixel.Y) / Constants.HALF_HEX_HEIGHT; var axial = new HexAxial(q, (float)r); axial = axial.Round(); return(axial); }
private Cell GetCell(HexAxial axial) { HexCube cube = axial.ToCube(); Cell cell = GetCell(cube); if (cell == null) { cell = new Cell(); _cells[(int)cube.Z + _size, (int)cube.Y + _size, (int)cube.X + _size] = cell; } return(cell); }
public List <string> GetAllCells() { var cells = new List <string>(); CellHandler handler = delegate(HexCube cube, Cell cell) { if (!cell.IsEmpty()) { HexAxial axial = cube.ToAxial(); cells.Add(string.Format(@"{0};{1}:{2}", axial.Q, axial.R, cell)); } }; IterateCells(handler); return(cells); }
private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { statusStrip1.Items[0].Text = string.Format("Mouse Position: [X: {0} Y:{1}]", e.X, e.Y); PointF offset = DetermineOffset(e.X, e.Y); statusStrip1.Items[1].Text = string.Format("Offset From Center: [X: {0} Y:{1}]", offset.X, offset.Y); HexAxial axial = _map.DetermineHexAtMousePointer(new Point(e.X, e.Y)); statusStrip1.Items[2].Text = string.Format("Selected Hex: [X: {0} Y:{1}]", axial.Q, axial.R); if (e.Button == MouseButtons.Left) { int deltaX = _panStartPoint.X - e.X; int deltaY = _panStartPoint.Y - e.Y; panel1.AutoScrollPosition = new Point(deltaX - panel1.AutoScrollPosition.X, deltaY - panel1.AutoScrollPosition.Y); } }
public void RemoveImageFromCell(HexAxial axial, int layerId) { Cell cell = GetCell(axial); cell.RemoveTerrain(layerId); }
public void SetCell(HexAxial axial, int layerId, int paletteId, int terrainId) { Cell cell = GetCell(axial); cell.AddCellData(layerId, paletteId, terrainId); }