This commit is contained in:
Regalis
2015-10-31 15:16:49 +02:00
parent bcc96cee97
commit b0deba514e
29 changed files with 348 additions and 81 deletions

View File

@@ -305,9 +305,9 @@ namespace Barotrauma
cells = CleanCells(pathCells);
pathCells.AddRange(CreateBottomHoles(1.0f, new Rectangle(
pathCells.AddRange(CreateBottomHoles(0.8f, new Rectangle(
(int)(borders.Width * 0.2f), 0,
(int)(borders.Width * 0.6f), (int)(borders.Height * 0.3f))));
(int)(borders.Width * 0.6f), (int)(borders.Height * 0.5f))));
foreach (VoronoiCell cell in pathCells)
{
@@ -338,7 +338,7 @@ namespace Barotrauma
{
for (int i = 0; i < 2; i++)
{
wrappingWalls[side, i] = new WrappingWall(pathCells, cells, borders.Height * 0.7f,
wrappingWalls[side, i] = new WrappingWall(pathCells, cells, borders.Height * 0.5f,
(side == 0 ? -1 : 1) * (i == 0 ? 1 : 2));
wrappingWalls[side, i].Vertices = GeneratePolygons(wrappingWalls[side, i].Cells, new List<VoronoiCell>());
@@ -651,7 +651,7 @@ namespace Barotrauma
if (!tempVertices.Contains(ge.point2)) tempVertices.Add(ge.point2);
VoronoiCell adjacentCell = ge.AdjacentCell(cell);
if (adjacentCell!=null && !emptyCells.Contains(adjacentCell)) continue;
if (adjacentCell!=null && cells.Contains(adjacentCell)) continue;
ge.isSolid = true;
@@ -929,7 +929,30 @@ namespace Barotrauma
}
}
return edges;
for (int side = 0; side < 2; side++ )
{
for (int n = 0 ; n<2; n++)
{
if (Vector2.Distance(wrappingWalls[side, n].MidPos, refPos) > WrappingWall.WallWidth) continue;
foreach (VoronoiCell cell in wrappingWalls[side, n].Cells)
{
for (int i = 0; i < cell.edges.Count; i++)
{
if (onlySolid && !cell.edges[i].isSolid) continue;
Vector2 start = cell.edges[i].point1 + Position;
start.Y = -start.Y;
Vector2 end = cell.edges[i].point2 + Position;
end.Y = -end.Y;
edges.Add(new Vector2[] { start, end });
}
}
}
}
return edges;
}
public void Render(GraphicsDevice graphicsDevice, Camera cam)

View File

@@ -157,6 +157,12 @@ namespace Voronoi2
edges.Add(ge);
}
GraphEdge lastEdge = new GraphEdge();
lastEdge.point1 = vertices[0];
lastEdge.point2 = vertices[vertices.Length-1];
edges.Add(lastEdge);
site = new Site();
site.SetPoint(midPoint);
}

View File

@@ -13,7 +13,7 @@ namespace Barotrauma
class WrappingWall
{
const float wallWidth = 20000.0f;
public const float WallWidth = 20000.0f;
public VertexPositionTexture[] Vertices;
@@ -34,6 +34,11 @@ namespace Barotrauma
get { return cells; }
}
public Vector2 MidPos
{
get { return midPos; }
}
public WrappingWall(List<VoronoiCell> pathCells, List<VoronoiCell> mapCells, float maxY, int dir = -1)
{
cells = new List<VoronoiCell>();
@@ -61,21 +66,21 @@ namespace Barotrauma
}
}
Vector2 wallSectionSize = new Vector2(2300.0f, 2300.0f);
Vector2 wallSectionSize = new Vector2(2000.0f, 2000.0f);
Vector2 startPos = (dir < 0) ?
edgeCell.Center + Vector2.UnitX * wallWidth * dir :
edgeCell.Center + wallWidth * Vector2.UnitX * (dir - 1);
edgeCell.Center + Vector2.UnitX * WallWidth * dir :
edgeCell.Center + WallWidth * Vector2.UnitX * (dir - 1);
midPos = startPos + Vector2.UnitX * wallWidth/2;
midPos = startPos + Vector2.UnitX * WallWidth/2;
List<Vector2> bottomVertices = new List<Vector2>();
for (float x = 0; x <= wallWidth; x += wallSectionSize.X)
for (float x = 0; x <= WallWidth; x += wallSectionSize.X)
{
Vector2 center = new Vector2(startPos.X + x, edgeCell.Center.Y);
float distFromCenter = Math.Abs(x - wallWidth / 2);
float distFromEdge = wallWidth / 2 - distFromCenter;
float normalizedDist = distFromEdge / (wallWidth / 2);
float distFromCenter = Math.Abs(x - WallWidth / 2);
float distFromEdge = WallWidth / 2 - distFromCenter;
float normalizedDist = distFromEdge / (WallWidth / 2);
float variance = 1000.0f * normalizedDist;
bottomVertices.Add(center + new Vector2(Rand.Range(-variance, variance, false), Rand.Range(-variance, variance, false)*2.0f));
@@ -90,23 +95,16 @@ namespace Barotrauma
vertices[3] = vertices[0] + Vector2.UnitY * wallSectionSize.Y;
VoronoiCell wallCell = new VoronoiCell(vertices);
wallCell.edges[1].cell1 = wallCell;
wallCell.edges[3].cell1 = wallCell;
if (i > 1)
{
wallCell.edges[1].cell2 = cells[i - 2];
cells[i - 2].edges[3].cell2 = wallCell;
}
cells.Add(wallCell);
}
//for (float x = 0; x<=wallWidth; x+=wallSectionSize.X)
//{
// Vector2 center = new Vector2(startPos.X+x, edgeCell.Center.Y);
// Vector2[] vertices = new Vector2[4];
// vertices[0] = center - wallSectionSize / 2;
// vertices[2] = center + wallSectionSize / 2;
// vertices[1] = new Vector2(vertices[2].X, vertices[0].Y);
// vertices[3] = new Vector2(vertices[0].X, vertices[2].Y);
// VoronoiCell wallCell = new VoronoiCell(vertices);
// wallCells.Add(wallCell);
//}
}
@@ -150,7 +148,7 @@ namespace Barotrauma
{
slot += amount;
Vector2 moveAmount = Vector2.UnitX * wallWidth * amount;
Vector2 moveAmount = Vector2.UnitX * WallWidth * amount;
Vector2 simMoveAmount = ConvertUnits.ToSimUnits(moveAmount);
foreach (VoronoiCell cell in cells)