Level generation bugfixes:
- cell bodies match the shape of the cell (triangulation didn't work correctly because the center of the cell was given in display units while vertices were in sim units) - ignoring graph edges whose length is zero when generating cells (fixes "invalid left/right normal" errors)
This commit is contained in:
@@ -185,6 +185,8 @@ namespace Barotrauma
|
||||
|
||||
foreach (GraphEdge ge in graphEdges)
|
||||
{
|
||||
if (ge.point1 == ge.point2) continue;
|
||||
|
||||
for (int i = 0; i < 2; i++)
|
||||
{
|
||||
Site site = (i == 0) ? ge.site1 : ge.site2;
|
||||
@@ -408,31 +410,29 @@ namespace Barotrauma
|
||||
bodyPoints[i] = ConvertUnits.ToSimUnits(bodyPoints[i]);
|
||||
}
|
||||
|
||||
|
||||
if (cell.CellType == CellType.Empty) continue;
|
||||
|
||||
triangles = MathUtils.TriangulateConvexHull(bodyPoints, cell.Center);
|
||||
triangles = MathUtils.TriangulateConvexHull(bodyPoints, ConvertUnits.ToSimUnits(cell.Center));
|
||||
|
||||
Body edgeBody = new Body(GameMain.World);
|
||||
Body cellBody = new Body(GameMain.World);
|
||||
|
||||
for (int i = 0; i < triangles.Count; i++)
|
||||
{
|
||||
if (triangles[i][0].Y == triangles[i][1].Y && triangles[i][0].Y == triangles[i][2].Y) continue;
|
||||
if (triangles[i][0].X == triangles[i][1].X && triangles[i][0].X == triangles[i][2].X) continue;
|
||||
|
||||
if (Vector2.DistanceSquared(triangles[i][0], triangles[i][1]) < 0.1f) continue;
|
||||
if (Vector2.DistanceSquared(triangles[i][1], triangles[i][2]) < 0.1f) continue;
|
||||
|
||||
Vertices bodyVertices = new Vertices(triangles[i]);
|
||||
FixtureFactory.AttachPolygon(bodyVertices, 5.0f, edgeBody);
|
||||
FixtureFactory.AttachPolygon(bodyVertices, 5.0f, cellBody);
|
||||
}
|
||||
|
||||
edgeBody.UserData = cell;
|
||||
edgeBody.SleepingAllowed = false;
|
||||
edgeBody.BodyType = BodyType.Kinematic;
|
||||
edgeBody.CollisionCategories = Physics.CollisionLevel;
|
||||
cellBody.UserData = cell;
|
||||
cellBody.SleepingAllowed = false;
|
||||
cellBody.BodyType = BodyType.Kinematic;
|
||||
cellBody.CollisionCategories = Physics.CollisionLevel;
|
||||
|
||||
cell.body = edgeBody;
|
||||
bodies.Add(edgeBody);
|
||||
cell.body = cellBody;
|
||||
bodies.Add(cellBody);
|
||||
}
|
||||
|
||||
return bodies;
|
||||
@@ -489,7 +489,7 @@ namespace Barotrauma
|
||||
if (!MathUtils.IsValid(leftNormal))
|
||||
{
|
||||
#if DEBUG
|
||||
DebugConsole.ThrowError("Invalid right normal");
|
||||
DebugConsole.ThrowError("Invalid left normal");
|
||||
#endif
|
||||
if (cell.body != null)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user