public int GetNeighbor(int x, int z, Direction dir) { DataCoordinate offsetToCheck = offsets[(int)dir]; DataCoordinate neightborCoord = new DataCoordinate(x + offsetToCheck.x, 0 + offsetToCheck.y, z + offsetToCheck.z); if (neightborCoord.x < 0 || neightborCoord.x >= Width || neightborCoord.y != 0 || neightborCoord.z < 0 || neightborCoord.z >= Depth) { return(0); } return(GetCell(neightborCoord.x, neightborCoord.z)); }
public void AddPlaque(int radius) { Vector3 center = Vector3.zero; System.Random random = new System.Random(); int w = random.Next(3, radius); int h = random.Next(3, radius); int d = random.Next(3, radius); int x = random.Next(w, X - w - 1); int y = random.Next(h, Y - h - 1); int z = Z - 10 - radius; for (int i = -w; i < w; i++) { for (int j = -h; j < h; j++) { for (int k = -d; k < d; k++) { if (plaqueCount == maxPlaque) { return; } Vector3 position = new Vector3(i, j, k); float distance = Vector3.Distance(position, center); if (distance < radius) { if (data[i + x, j + y, k + z] != 0 && data[i + x, j + y, k + z] != 4 && data[i + x, j + y, k + z] != 6) { for (int dir = 0; dir < 6; dir++) { if (GetNeighbour(i + x, j + y, k + z, (Direction)(dir)) == 0) { DataCoordinate off = offsets[(int)dir]; data[i + x + off.x, j + y + off.y, k + z + off.z] = 6; plaqueCount++; } } } } } } } pCount--; if (pCount != 0) { AddPlaque(radius); } }
public int GetNeighbour(int x, int y, int z, Direction dir) { DataCoordinate offsetToCheck = offsets[(int)dir]; DataCoordinate neighbourCoord = new DataCoordinate(x + offsetToCheck.x, y + offsetToCheck.y, z + offsetToCheck.z); if (neighbourCoord.x < 0 || neighbourCoord.x >= Width || neighbourCoord.y < 0 || neighbourCoord.y >= Depth || neighbourCoord.z < 0 || neighbourCoord.z >= Height) { return(0); } else { return(GetCell(neighbourCoord.x, neighbourCoord.y, neighbourCoord.z)); } }
public int GetNeightbor(int x, int z, Direction dir, int y = 0) { DataCoordinate offSetCheck = offSet[(int)dir]; DataCoordinate neighBor = new DataCoordinate(x + offSetCheck.x, y + offSetCheck.y, z + offSetCheck.z); if (neighBor.x < 0 || neighBor.x >= Width || neighBor.y != 0 || neighBor.z >= Depth || neighBor.z < 0) { return(0); } else { return(GetCell(neighBor.x, neighBor.z)); } }
public int GetNeighbor(int x, int y, int z, Direction dir) { DataCoordinate offset = offsets[(int)dir]; // The offset to check. DataCoordinate neighborCoord = new DataCoordinate(x + offset.x, y + offset.y, z + offset.z); if (neighborCoord.x < 0 || neighborCoord.x >= Width || neighborCoord.y < 0 || neighborCoord.y >= Height || neighborCoord.z < 0 || neighborCoord.z >= Depth) { return(0); } else { return(GetCell(neighborCoord.x, neighborCoord.y, neighborCoord.z)); } }
public int GetNeighbour(int x, int y, int z, Direction dir) { DataCoordinate offsetToCheck = offsets[(int)dir]; DataCoordinate neighborCoord = new DataCoordinate(x + offsetToCheck.x, y + offsetToCheck.y, z + offsetToCheck.z); if (neighborCoord.x < 0 || neighborCoord.x >= Width || neighborCoord.y < 0 || neighborCoord.y >= Height || neighborCoord.z < 0 || neighborCoord.z >= Depth) { //we know for sure it's outside data, it is empty return(0); } else { return(GetCell(neighborCoord.x, neighborCoord.y, neighborCoord.z)); } }
public int GetNeighbour(int x, int y, int z, int chunkX, int chunkY, int chunkZ, Direction dir, Chunk chunk) { DataCoordinate offsetToCheck = _offsets[(int)dir]; DataCoordinate neighbourCoord = new DataCoordinate(x + offsetToCheck.x, y + offsetToCheck.y, z + offsetToCheck.z); if (neighbourCoord.x < 0 || neighbourCoord.x >= Chunk.chunkSize || neighbourCoord.y < 0 || neighbourCoord.y >= Chunk.chunkSize || neighbourCoord.z < 0 || neighbourCoord.z >= Chunk.chunkSize) { return(0); } return(GetCell(neighbourCoord.x, neighbourCoord.y, neighbourCoord.z, chunk)); }
// Find the value of a neighbour of a point in a given direction public int GetNeighbour(int x, int y, int z, Direction direction) { // Derive the offset from the direction supplied DataCoordinate offsetToCheck = directionalOffsets[direction]; // Retrive the coordinate of the neighbour based on the offset derived DataCoordinate neighbour = new DataCoordinate( x + offsetToCheck.x, y + offsetToCheck.y, z + offsetToCheck.z); // Check the neighbour is not out of the bounds of the pointField if (!CoordInField(neighbour)) { return(0); // Nothing is outside the point field } return(GetCell(neighbour.x, neighbour.y, neighbour.z)); }
public int GetNeighbor(int x, int y, int z, Direction dir) { DataCoordinate offsetToCheck = offsets[(int)dir]; DataCoordinate neighborCoord = new DataCoordinate(x, y, z) + offsetToCheck; bool neighborNonexistent = ( neighborCoord.x < 0 || neighborCoord.x >= Width || neighborCoord.y < 0 || neighborCoord.y >= Height || neighborCoord.z < 0 || neighborCoord.z >= Depth ); if (neighborNonexistent) { return(0); } return(GetCell(neighborCoord.x, neighborCoord.y, neighborCoord.z)); }
private bool CoordInField(DataCoordinate coord) { return(CoordInField(new Vector3Int(coord.x, coord.y, coord.z))); }