//public static Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone GetZone(Index3 cellIndex, List<Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone> Zones)//List<Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone> TopZone) //{ // foreach (Slb.Ocean.Petrel.DomainObject.PillarGrid.Zone zone in Zones) // { // if (cellIndex.K > zone.BaseK && cellIndex.K) // { // } // } //} public static Point3[] GetCornerSet(CellSide SideOfCell, Grid gridInContext, Index3 CellIndex) { CellCorner[] CellCorners = new CellCorner[4]; Point3[] CellCornerPoints = new Point3[4]; switch (SideOfCell) { case CellSide.Up: CellCorners[0] = CellCorner.TopNorthWest; CellCorners[1] = CellCorner.TopNorthEast; CellCorners[2] = CellCorner.TopSouthWest; CellCorners[3] = CellCorner.TopSouthEast; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; case CellSide.East: CellCorners[0] = CellCorner.TopSouthEast; CellCorners[1] = CellCorner.TopNorthEast; CellCorners[2] = CellCorner.BaseSouthEast; CellCorners[3] = CellCorner.BaseNorthEast; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; case CellSide.West: CellCorners[0] = CellCorner.TopSouthWest; CellCorners[1] = CellCorner.TopNorthWest; CellCorners[2] = CellCorner.BaseSouthWest; CellCorners[3] = CellCorner.BaseNorthWest; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; case CellSide.South: CellCorners[0] = CellCorner.TopSouthWest; CellCorners[1] = CellCorner.TopSouthEast; CellCorners[2] = CellCorner.BaseSouthWest; CellCorners[3] = CellCorner.BaseSouthEast; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; case CellSide.North: CellCorners[0] = CellCorner.TopNorthWest; CellCorners[1] = CellCorner.TopNorthEast; CellCorners[2] = CellCorner.BaseNorthWest; CellCorners[3] = CellCorner.BaseNorthEast; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; case CellSide.Down: CellCorners[0] = CellCorner.BaseNorthWest; CellCorners[1] = CellCorner.BaseNorthEast; CellCorners[2] = CellCorner.BaseSouthWest; CellCorners[3] = CellCorner.BaseSouthEast; CellCornerPoints = gridInContext.GetCellCorners(CellIndex, CellCorners); break; default: CellCornerPoints = null; break; } return CellCornerPoints; }
public override void OnDrag(IInventoryCellView targetCell, IInventoryCellView effectCell, PointerEventData pointerEventData) { if (targetCell == null) { return; } // auto scroll var pointerViewportPosition = GetLocalPosition(m_ScrollRect.viewport, pointerEventData.position, pointerEventData.enterEventCamera); if (pointerViewportPosition.y < m_ScrollRect.viewport.rect.min.y + holdScrollPadding) { var scrollValue = m_ScrollRect.verticalNormalizedPosition * m_ScrollRect.viewport.rect.height; scrollValue -= holdScrollRate; m_ScrollRect.verticalNormalizedPosition = Mathf.Clamp01(scrollValue / m_ScrollRect.viewport.rect.height); } if (pointerViewportPosition.y > m_ScrollRect.viewport.rect.max.y - holdScrollPadding) { var scrollValue = m_ScrollRect.verticalNormalizedPosition * m_ScrollRect.viewport.rect.height; scrollValue += holdScrollRate; m_ScrollRect.verticalNormalizedPosition = Mathf.Clamp01(scrollValue / m_ScrollRect.viewport.rect.height); } // depends on anchor var pointerLocalPosition = GetLocalPosition(targetCell.RectTransform, pointerEventData.position, pointerEventData.enterEventCamera); var anchor = new Vector2(targetCell.DefaultCellSize.x * 0.5f, -targetCell.DefaultCellSize.y * 0.5f); var anchoredPosition = pointerLocalPosition + anchor; conditionOffset = new Vector3( Mathf.Floor(anchoredPosition.x / targetCell.DefaultCellSize.x) * targetCell.DefaultCellSize.x, Mathf.Ceil(anchoredPosition.y / targetCell.DefaultCellSize.y) * targetCell.DefaultCellSize.y); // cell corner var prevCorner = cellCorner; cellCorner = GetCorner((new Vector2(anchoredPosition.x % targetCell.DefaultCellSize.x, anchoredPosition.y % targetCell.DefaultCellSize.y) - anchor) * 0.5f); // shift the position only even number size int width = effectCell.CellData.Width; int height = effectCell.CellData.Height; //Debug.LogError(cellCorner); if (cellCorner == CellCorner.None) { return; } var evenNumberOffset = GetEvenNumberOffset(width, height, targetCell.DefaultCellSize.x * 0.5f, targetCell.DefaultCellSize.y * 0.5f); conditionTransform.position = targetCell.RectTransform.position + ((conditionOffset + evenNumberOffset) * targetCell.RectTransform.lossyScale.x); // update condition if (prevCorner != cellCorner) { UpdateCondition(targetCell, effectCell); } }
public virtual void OnCellExit(IVariableInventoryCell stareCell) { conditionTransform.gameObject.SetActive(false); condition.color = defaultColor; cellCorner = CellCorner.None; (stareCell as StandardCell).SetHighLight(false); }
public override void OnCellExit(IInventoryCellView targetCell) { conditionTransform.gameObject.SetActive(false); condition.color = defaultColor; cellCorner = CellCorner.None; if (targetCell is PlayerInventoryCellView) { (targetCell as PlayerInventoryCellView).SetHighLight(false); } }
public virtual void OnDrag(IVariableInventoryCell stareCell, IVariableInventoryCell effectCell, PointerEventData pointerEventData) { if (stareCell == null) { return; } // auto scroll var pointerViewportPosition = GetLocalPosition(scrollRect.viewport, pointerEventData.position, pointerEventData.enterEventCamera); if (pointerViewportPosition.y < scrollRect.viewport.rect.min.y + holdScrollPadding) { var scrollValue = scrollRect.verticalNormalizedPosition * scrollRect.viewport.rect.height; scrollValue -= holdScrollRate; scrollRect.verticalNormalizedPosition = Mathf.Clamp01(scrollValue / scrollRect.viewport.rect.height); } if (pointerViewportPosition.y > scrollRect.viewport.rect.max.y - holdScrollPadding) { var scrollValue = scrollRect.verticalNormalizedPosition * scrollRect.viewport.rect.height; scrollValue += holdScrollRate; scrollRect.verticalNormalizedPosition = Mathf.Clamp01(scrollValue / scrollRect.viewport.rect.height); } // depends on anchor var pointerLocalPosition = GetLocalPosition(stareCell.RectTransform, pointerEventData.position, pointerEventData.enterEventCamera); var anchor = new Vector2(stareCell.DefaultCellSize.x * 0.5f, -stareCell.DefaultCellSize.y * 0.5f); var anchoredPosition = pointerLocalPosition + anchor; conditionOffset = new Vector3( Mathf.Floor(anchoredPosition.x / stareCell.DefaultCellSize.x) * stareCell.DefaultCellSize.x, Mathf.Ceil(anchoredPosition.y / stareCell.DefaultCellSize.y) * stareCell.DefaultCellSize.y); // cell corner var prevCorner = cellCorner; cellCorner = GetCorner((new Vector2(anchoredPosition.x % stareCell.DefaultCellSize.x, anchoredPosition.y % stareCell.DefaultCellSize.y) - anchor) * 0.5f); // shift the position only even number size var(width, height) = GetRotateSize(effectCell.CellData); var evenNumberOffset = GetEvenNumberOffset(width, height, stareCell.DefaultCellSize.x * 0.5f, stareCell.DefaultCellSize.y * 0.5f); conditionTransform.position = stareCell.RectTransform.position + ((conditionOffset + evenNumberOffset) * stareCell.RectTransform.lossyScale.x); // update condition if (prevCorner != cellCorner) { UpdateCondition(stareCell, effectCell); } }
private void AddRivers() { List <CellCorner> springs = new List <CellCorner>(); //Get all corners that can possibly be a spring. for (int i = 0; i < corners.Count; i++) { if (corners[i].elevation >= minSpringElevation && corners[i].elevation <= maxSpringElevation && !corners[i].isWater) { springs.Add(corners[i]); } } //Select some corners randomly from the previous list to be used as our springs List <CellCorner> rivers = new List <CellCorner>(); springsSeed = useCustomSeeds ? springsSeed : Random.Range(0, 10000); Random.InitState(springsSeed); while (springs.Count > 0 && rivers.Count < numberOfSprings) { int id = Random.Range(0, springs.Count); rivers.Add(springs[id]); springs.RemoveAt(id); } //Assign the flow of the river for each edge using their downslope. Each time a edge is assigned as a river, the water volume is increased by 1, so if two rivers join together, the next edge will have a bigger volume of water foreach (var river in rivers) { CellCorner currentRiverCorner = river; while (true) { //If the current corner doesn't have a downslope, then we reached the coast if (currentRiverCorner.downslopeCorner == null) { break; } //Increase the water volume for the downslope edge currentRiverCorner.downslopeEdge.waterVolume++; //Set the current river corner to be the dowsnlope, so we can keep going down until we reach the coast currentRiverCorner = currentRiverCorner.downslopeCorner; } } }
protected virtual int?GetIndex(IInventoryCellView targetCell, IInventoryCellData effectCellData, CellCorner cellCorner) { var index = GetIndex(targetCell); // offset index int width = effectCellData.Width; int height = effectCellData.Height; if (width % 2 == 0) { if ((cellCorner & CellCorner.Left) != CellCorner.None) { index--; } } if (height % 2 == 0) { if ((cellCorner & CellCorner.Top) != CellCorner.None) { index -= playerInventoryviewData.width; } } index -= (width - 1) / 2; index -= (height - 1) / 2 * playerInventoryviewData.width; return(index); }
public static List<double> GetListOfPenetratedCellDistances(Grid gridInContext, Borehole bh, List<Index3> ListOfSelectedIntersectingGridCells, bool PerforatedZonesOnly, bool Vertical_only) { IPillarGridIntersectionService pgiservice = CoreSystem.GetService<IPillarGridIntersectionService>(); Quadrilateral Face1; Quadrilateral Face2; CellCorner[] CellCorners = new CellCorner[4]; Point3[] CellCornerPoints1 = new Point3[4]; Point3[] CellCornerPoints2 = new Point3[4]; CellSide Side = new CellSide() ; //Dictionary<Index3,List<double>> DictionaryOfSelectedCells = new Dictionary<Index3,List<double>>(ListOfSelectedIntersectingGridCells.Count); // List<double> Distance = new List<double>(3); //This array will contain the Height of the cell for the kh calculation and two extra elements that will be empty; List<double> Distance = new List<double>(); if (!Vertical_only) { List<CellSide> ListOfEnteringSides = GetListOfEnteringSidesOfIntersectedCells(pgiservice, gridInContext, bh, ListOfSelectedIntersectingGridCells, PerforatedZonesOnly); for (int i = 0; i < ListOfEnteringSides.Count; i++) { switch (ListOfEnteringSides[i]) { case CellSide.Up: CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]); Side = CellSide.Down; CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]); break; case CellSide.East: CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]); Side = CellSide.West; CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]); break; case CellSide.West: CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]); Side = CellSide.East; CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]); break; case CellSide.South: CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]); Side = CellSide.North; CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]); break; case CellSide.North: CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]); Side = CellSide.South; CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]); break; case CellSide.Down: CellCornerPoints1 = KandaIntersectionService.GetCornerSet(ListOfEnteringSides[i], gridInContext, ListOfSelectedIntersectingGridCells[i]); Side = CellSide.Up; CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]); break; default: CellCornerPoints1 = null; CellCornerPoints2= null; break; } try { Face1 = new Quadrilateral(CellCornerPoints1[0], CellCornerPoints1[1], CellCornerPoints1[2], CellCornerPoints1[3]); } catch { Face1 = null; } try { Face2 = new Quadrilateral(CellCornerPoints2[0], CellCornerPoints2[1], CellCornerPoints2[2], CellCornerPoints2[3]); } catch { Face2 = null; } try { // Distance[0] = Face1.Centroid.Distance(Face2.Centroid); //DictionaryOfSelectedCells.Add(ListOfSelectedIntersectingGridCells[i], Distance); Distance.Add(Face1.Centroid.Distance(Face2.Centroid)); } catch { Distance.Add(-1); //DictionaryOfSelectedCells.Add(ListOfSelectedIntersectingGridCells[i], null); } } } else //If only the vertical distance from top to base face of cell is required. { for (int i = 0; i < ListOfSelectedIntersectingGridCells.Count; i++) { //CellCorners[0] = CellCorner.TopNorthWest; CellCorners[1] = CellCorner.TopNorthEast; CellCorners[2] = CellCorner.TopSouthWest; //CellCorners[3] = CellCorner.TopSouthEast; //CellCornerPoints = gridInContext.GetCellCorners(ListOfSelectedIntersectingGridCells[i], CellCorners); Side = CellSide.Up; CellCornerPoints1 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]); Side = CellSide.Down; CellCornerPoints2 = KandaIntersectionService.GetCornerSet(Side, gridInContext, ListOfSelectedIntersectingGridCells[i]); try { Face1 = new Quadrilateral(CellCornerPoints1[0], CellCornerPoints1[1], CellCornerPoints1[2], CellCornerPoints1[3]); } catch { Face1 = null; } try { Face2 = new Quadrilateral(CellCornerPoints2[0], CellCornerPoints2[1], CellCornerPoints2[2], CellCornerPoints2[3]); } catch { Face2 = null; } try { // Distance[0] = Face1.Centroid.Distance(Face2.Centroid); //DictionaryOfSelectedCells.Add(ListOfSelectedIntersectingGridCells[i], Distance); if (!Double.IsNaN(Face1.Centroid.Distance(Face2.Centroid))) { Distance.Add(Face1.Centroid.Distance(Face2.Centroid)); } else { Distance.Add(-1); } } catch { Distance.Add(-1); //DictionaryOfSelectedCells.Add(ListOfSelectedIntersectingGridCells[i], null); } } } return Distance; //return DictionaryOfSelectedCells; }
protected virtual int?GetIndex(IVariableInventoryCell stareCell, IVariableInventoryCellData effectCellData, CellCorner cellCorner) { var index = GetIndex(stareCell); // offset index var(width, height) = GetRotateSize(effectCellData); if (width % 2 == 0) { if ((cellCorner & CellCorner.Left) != CellCorner.None) { index--; } } if (height % 2 == 0) { if ((cellCorner & CellCorner.Top) != CellCorner.None) { index -= StashData.CapacityWidth; } } index -= (width - 1) / 2; index -= (height - 1) / 2 * StashData.CapacityWidth; return(index); }
private void AssignElevations() { List <CellCorner> queue = new List <CellCorner>(); //We have to use a List<T> instead of a Queue<T> because we need to add itens both at the begging and a the end of the list float minElevation = 1, maxElevation = 1; //Find all coast corners and assign their elevation to 0 foreach (var corner in corners) { if (corner.isCoast) { queue.Add(corner); corner.elevation = 0; } else { corner.elevation = Mathf.Infinity; } } //Define some helper functions to help with the loop below bool IsCellLake(CellCenter c) { return(c.isWater && !c.isOcean); } bool IsEdgeLake(CellEdge e) { return(IsCellLake(e.d0) || IsCellLake(e.d1)); } while (queue.Count > 0) { CellCorner currentCorner = queue[0]; //Get the fisrt item on the list queue.RemoveAt(0); //Remove the item from the list int offset = Random.Range(0, currentCorner.connectedEdges.Count); //Add a random offset to the iterator for (int i = 0; i < currentCorner.connectedEdges.Count; i++) { CellEdge e = currentCorner.connectedEdges[(i + offset) % currentCorner.connectedEdges.Count]; //uses the offset to start at a random edge, but still circulate through all of them CellCorner neighbor = e.v0 == currentCorner ? e.v1 : e.v0; //Get the corner that is part of this edge and opposite of the current corner float newElevation = (IsEdgeLake(e) ? 0 : 1) + currentCorner.elevation; //If the neighboor has a higher elevation than the calculated one, we have to change the elevation (in other words, we always use the lowest calculated elevation value) if (newElevation < neighbor.elevation) { neighbor.elevation = newElevation; neighbor.downslopeCorner = currentCorner; //Since this elevation is (corner elevation + (0 || 1)), that means this corner is either higher or the same height as the current corner, and so we can set the parent corner as the downslope neighbor.downslopeEdge = e; //Update the min/max elevations if (neighbor.isOcean && newElevation > minElevation) { minElevation = newElevation; } if (!neighbor.isOcean && newElevation > maxElevation) { maxElevation = newElevation; } //If this corner was a lake, we have to revisit it again to guarantee that all edges of a lake has the same elevation if (IsEdgeLake(e)) { queue.Insert(0, neighbor); } else { queue.Add(neighbor); } } } } //Normalize the elevations so we have a range from 0 to 1 for land/lakes, and -1 to 0 for oceans foreach (var corner in corners) { if (!corner.isOcean) { corner.elevation = elevationCurve.Evaluate(corner.elevation / maxElevation); } else { corner.elevation = -elevationCurve.Evaluate(corner.elevation / minElevation); } } //Set the cell center elevation to be the average of its corners. Also, since the coastline is at elevation 0, if some ocean is greater than it, we override the value float maxOceanElevation = -0.01f; foreach (var center in cells) { float sumElevations = 0; foreach (var corner in center.cellCorners) { sumElevations += corner.elevation; } center.elevation = sumElevations / center.cellCorners.Count; //make sure that ocean cells won't be on a higher elevation than the coast if (center.isOcean && center.elevation > maxOceanElevation) { center.elevation = maxOceanElevation; } } }
private void GenerateGraphs(List <Vector2> points) { //Generate the Voronoi Rectf bounds = new Rectf(0, 0, size.x, size.y); Voronoi voronoi = new Voronoi(points, bounds, relaxation); //Cell centers foreach (var site in voronoi.SitesIndexedByLocation) { CellCenter c = new CellCenter(); c.index = cells.Count; c.position = site.Key; cells.Add(c); } //Cell Corners foreach (var edge in voronoi.Edges) { //If the edge doesn't have clipped ends, it was not withing bounds if (edge.ClippedEnds == null) { continue; } if (!corners.Any(x => x.position == edge.ClippedEnds[LR.LEFT])) { CellCorner c = new CellCorner(); c.index = corners.Count; c.position = edge.ClippedEnds[LR.LEFT]; c.isBorder = c.position.x == 0 || c.position.x == size.x || c.position.y == 0 || c.position.y == size.y; corners.Add(c); } if (!corners.Any(x => x.position == edge.ClippedEnds[LR.RIGHT])) { CellCorner c = new CellCorner(); c.index = corners.Count; c.position = edge.ClippedEnds[LR.RIGHT]; c.isBorder = c.position.x == 0 || c.position.x == size.x || c.position.y == 0 || c.position.y == size.y; corners.Add(c); } } //Define some local helper functions to help with the loop below void AddPointToPointList <T>(List <T> list, T point) where T : MapPoint { if (!list.Contains(point)) { list.Add(point); } } //Voronoi and Delaunay edges. Each edge point to two cells and two corners, so we can store both the sites and corners into a single edge object (thus making two edges into one object) foreach (var voronoiEdge in voronoi.Edges) { if (voronoiEdge.ClippedEnds == null) { continue; } CellEdge edge = new CellEdge(); edge.index = edges.Count; //Set the voronoi edge edge.v0 = corners.First(x => x.position == voronoiEdge.ClippedEnds[LR.LEFT]); edge.v1 = corners.First(x => x.position == voronoiEdge.ClippedEnds[LR.RIGHT]); //Set the Delaunay edge edge.d0 = cells.First(x => x.position == voronoiEdge.LeftSite.Coord); edge.d1 = cells.First(x => x.position == voronoiEdge.RightSite.Coord); edges.Add(edge); /*Set the relationships*/ //Set the relationship between this edge and the connected cells centers/corners edge.d0.borderEdges.Add(edge); edge.d1.borderEdges.Add(edge); edge.v0.connectedEdges.Add(edge); edge.v1.connectedEdges.Add(edge); //Set the relationship between the CELL CENTERS connected to this edge AddPointToPointList(edge.d0.neighborCells, edge.d1); AddPointToPointList(edge.d1.neighborCells, edge.d0); //Set the relationship between the CORNERS connected to this edge AddPointToPointList(edge.v0.neighborCorners, edge.v1); AddPointToPointList(edge.v1.neighborCorners, edge.v0); //Set the relationship of the CORNERS connected to this edge and the CELL CENTERS connected to this edge AddPointToPointList(edge.d0.cellCorners, edge.v0); AddPointToPointList(edge.d0.cellCorners, edge.v1); AddPointToPointList(edge.d1.cellCorners, edge.v0); AddPointToPointList(edge.d1.cellCorners, edge.v1); //Same as above, but the other way around AddPointToPointList(edge.v0.touchingCells, edge.d0); AddPointToPointList(edge.v0.touchingCells, edge.d1); AddPointToPointList(edge.v1.touchingCells, edge.d0); AddPointToPointList(edge.v1.touchingCells, edge.d1); } }