public static void DrawPolygonTriangulation(this IDebugCanvas canvas, Polygon2 poly, StrokeStyle strokeStyle) { var cps = new Polygon(poly.Points.Map(p => new PolygonPoint(p.X, p.Y))); P2T.Triangulate(cps); foreach (var triangle in cps.Triangles) { canvas.DrawTriangle(ToDV3(triangle.Points[0]), ToDV3(triangle.Points[1]), ToDV3(triangle.Points[2]), strokeStyle); } }
public static void DrawTriangulation(this IDebugCanvas canvas, Triangulation triangulation, StrokeStyle strokeStyle) { canvas.BatchDraw(() => { foreach (var island in triangulation.Islands) { foreach (var triangle in island.Triangles) { canvas.DrawTriangle(triangle, strokeStyle); } } }); }
private void DrawEntities(IDebugCanvas debugCanvas) { foreach (var(i, entity) in EntityService.EnumerateEntities().Enumerate()) { // if (i == 2 || i == 1) continue; var movementComponent = entity.MovementComponent; if (movementComponent != null) { debugCanvas.Transform = Matrix4x4.Identity; debugCanvas.DrawPoint(movementComponent.WorldPosition, new StrokeStyle(Color.Black, 2 * movementComponent.BaseRadius)); debugCanvas.DrawPoint(movementComponent.WorldPosition, new StrokeStyle(Color.White, 2 * movementComponent.BaseRadius - 2)); // if (movementComponent.Swarm != null && movementComponent.WeightedSumNBodyForces.Norm2D() > GeometryOperations.kEpsilon) { // var direction = movementComponent.WeightedSumNBodyForces.ToUnit() * movementComponent.BaseRadius; // var to = movementComponent.WorldPosition + new DoubleVector3(direction.X, direction.Y, 0.0); // debugCanvas.DrawLine(movementComponent.WorldPosition, to, new StrokeStyle(Color.Gray)); // } //if (movementComponent.DebugLines != null) // debugCanvas.DrawLineList( // movementComponent.DebugLines.SelectMany(pair => new[] { pair.Item1, pair.Item2 }).ToList(), // new StrokeStyle(Color.Black)); continue; var terrainOverlayNetwork = TerrainService.CompileSnapshot().OverlayNetworkManager.CompileTerrainOverlayNetwork(entity.MovementComponent.BaseRadius); if (terrainOverlayNetwork.TryFindTerrainOverlayNode(movementComponent.WorldPosition, out var node, out var plocal)) { debugCanvas.Transform = node.SectorNodeDescription.WorldTransform; //debugCanvas.DrawTriangulation(node.LocalGeometryView.Triangulation, StrokeStyle.BlackHairLineSolid); if (node.LocalGeometryView.Triangulation.TryIntersect(plocal.X, plocal.Y, out var island, out var triangleIndex)) { debugCanvas.DrawTriangle(island.Triangles[triangleIndex], StrokeStyle.RedHairLineSolid); } } } } }
public static void DrawTriangle(this IDebugCanvas canvas, DoubleVector2 p1, DoubleVector2 p2, DoubleVector2 p3, StrokeStyle strokeStyle) { canvas.DrawTriangle(ToDV3(p1), ToDV3(p2), ToDV3(p3), strokeStyle); }