public static void DrawBvh(this IDebugCanvas canvas, BvhILS2 bvh) { void Helper(BvhILS2 node, int d) { if (d != 0) { var s = new StrokeStyle(d % 2 == 0 ? Color.Red : Color.Lime, 10.0f / d, new[] { d % 2 == 0 ? 1.0f : 3.0f, d % 2 == 0 ? 3.0f : 1.0f }); canvas.DrawRectangle(node.Bounds, 0.0f, s); } if (node.First != null) { Helper(node.First, d + 1); Helper(node.Second, d + 1); } else { for (var i = node.SegmentsStartIndexInclusive; i < node.SegmentsEndIndexExclusive; i++) { canvas.DrawLine(node.Segments[i].First, node.Segments[i].Second, StrokeStyle3); } } } Helper(bvh, 0); }
public static void DrawLineStrip(this IDebugCanvas canvas, IReadOnlyList <DoubleVector3> points, StrokeStyle strokeStyle) { canvas.BatchDraw(() => { for (var i = 0; i < points.Count - 1; i++) { var a = points[i]; var b = points[i + 1]; canvas.DrawLine(a, b, strokeStyle); } }); }
public static void DrawVisibilityPolygon(this IDebugCanvas debugCanvas, VisibilityPolygon avss, double z = 0.0, FillStyle fillStyle = null, StrokeStyle angleBoundaryStrokeStyle = null, StrokeStyle visibleWallStrokeStyle = null) { fillStyle = fillStyle ?? DefaultFillStyle; var oxy = avss.Origin; foreach (var range in avss.Get().Where(range => range.Id != VisibilityPolygon.RANGE_ID_INFINITELY_FAR && range.Id != VisibilityPolygon.RANGE_ID_INFINITESIMALLY_NEAR)) { var rstart = DoubleVector2.FromRadiusAngle(100, range.ThetaStart); var rend = DoubleVector2.FromRadiusAngle(100, range.ThetaEnd); var s = range.Segment; var s1 = s.First.ToDoubleVector2(); var s2 = s.Second.ToDoubleVector2(); DoubleVector2 visibleStart, visibleEnd; if (!GeometryOperations.TryFindLineLineIntersection(oxy, oxy + rstart, s1, s2, out visibleStart) || !GeometryOperations.TryFindLineLineIntersection(oxy, oxy + rend, s1, s2, out visibleEnd)) { continue; } debugCanvas.FillTriangle(oxy, visibleStart, visibleEnd, fillStyle); debugCanvas.DrawLine( new DoubleVector3(oxy.X, oxy.Y, z), new DoubleVector3(visibleStart.X, visibleStart.Y, z), angleBoundaryStrokeStyle ?? DefaultAngleBoundaryStrokeStyle); debugCanvas.DrawLine( new DoubleVector3(oxy.X, oxy.Y, z), new DoubleVector3(visibleEnd.X, visibleEnd.Y, z), angleBoundaryStrokeStyle ?? DefaultAngleBoundaryStrokeStyle); debugCanvas.DrawLine( new DoubleVector3(visibleStart.X, visibleStart.Y, z), new DoubleVector3(visibleEnd.X, visibleEnd.Y, z), visibleWallStrokeStyle ?? DefaultVisibleWallStrokeStyle); } }
private void DrawPathfindingQueryResult(IDebugCanvas debugCanvas, double agentRadius, DoubleVector3 source, DoubleVector3 dest) { if (Game.PathfinderCalculator.TryFindPath(agentRadius, source, dest, out var roadmap)) { Console.WriteLine("Yippee "); debugCanvas.DrawRoadmap(roadmap); } else { Console.WriteLine("Nope"); debugCanvas.Transform = Matrix4x4.Identity; debugCanvas.DrawLine(source, dest, NoPathStroke); } }
public static void DrawLineList(this IDebugCanvas canvas, IReadOnlyList <DoubleVector3> points, StrokeStyle strokeStyle) { if (points.Count % 2 != 0) { throw new ArgumentException("Line List points must have even length."); } canvas.BatchDraw(() => { for (var i = 0; i < points.Count; i += 2) { var a = points[i]; var b = points[i + 1]; canvas.DrawLine(a, b, strokeStyle); } }); }
private void DrawEntityMotionVectors(IDebugCanvas debugCanvas) { debugCanvas.Transform = Matrix4x4.Identity; foreach (var(i, entity) in EntityService.EnumerateEntities().Enumerate()) { var mc = entity.MovementComponent; if (mc?.Swarm != null) { var local = mc.LocalPosition; var motionVectorUnnormalized = mc.WeightedSumNBodyForces; if (motionVectorUnnormalized.Norm2D() < 1E-9) { continue; } var v = motionVectorUnnormalized.ToUnit() * mc.TerrainOverlayNetworkNode.SectorNodeDescription.WorldToLocalScalingFactor * 100; var goalWorld = mc.TerrainOverlayNetworkNode.SectorNodeDescription.LocalToWorld(local + v); debugCanvas.DrawLine(mc.WorldPosition, goalWorld, StrokeStyle.RedHairLineSolid); } } }
public static void DrawRoadmap(this IDebugCanvas debugCanvas, MotionRoadmap roadmap, MovementComponent movementComponent = null) { var skip = movementComponent?.PathingRoadmapProgressIndex ?? 0; foreach (var(i, action) in roadmap.Plan.Skip(skip).Enumerate()) { switch (action) { case MotionRoadmapWalkAction walk: debugCanvas.Transform = Matrix4x4.Identity; var s = i == 0 && movementComponent != null ? movementComponent.WorldPosition : Vector3.Transform(new Vector3(walk.Source.X, walk.Source.Y, 0), walk.Node.SectorNodeDescription.WorldTransform).ToOpenMobaVector(); var t = Vector3.Transform(new Vector3(walk.Destination.X, walk.Destination.Y, 0), walk.Node.SectorNodeDescription.WorldTransform).ToOpenMobaVector(); // Console.WriteLine("S: " + s + "\t AND T: " + t); // for (var i = 0; i < 100; i++) { // debugCanvas.DrawPoint((s * (100 - i) + t * i) / 100, new StrokeStyle(Color.Cyan, 50)); // } debugCanvas.DrawLine(s, t, PathStroke); break; } } }
public static void DrawLine(this IDebugCanvas canvas, DoubleVector2 p1, DoubleVector2 p2, StrokeStyle strokeStyle) { canvas.DrawLine(ToDV3(p1), ToDV3(p2), strokeStyle); }
public static void DrawLine(this IDebugCanvas canvas, DoubleLineSegment2 segment, StrokeStyle strokeStyle) { canvas.DrawLine(ToDV3(segment.First), ToDV3(segment.Second), strokeStyle); }
// public static void FillPolygon(this IDebugCanvas canvas, Polygon3 polygon, FillStyle fillStyle) { // canvas.FillPolygon(polygon.Points.Select(p => p.ToDoubleVector3()).ToList(), fillStyle); // } // // public static void DrawPolygonContour(this IDebugCanvas canvas, Polygon3 polygon, StrokeStyle strokeStyle) { // canvas.DrawPolygonContour(polygon.Points.Select(p => p.ToDoubleVector3()).ToList(), strokeStyle); // } // public static void DrawPolygons(this IDebugCanvas canvas, IReadOnlyList<Polygon3> polygons, StrokeStyle strokeStyle) { // canvas.BatchDraw(() => { // foreach (var polygon in polygons) { // canvas.DrawPolygonContour(polygon, strokeStyle); // } // }); // } // // public static void DrawPolygons(this IDebugCanvas canvas, IReadOnlyList<IReadOnlyList<DoubleVector3>> contours, StrokeStyle strokeStyle) { // canvas.BatchDraw(() => { // foreach (var contour in contours) { // canvas.DrawPolygonContour(contour, strokeStyle); // } // }); // } public static void DrawAxisAlignedBoundingBox(this IDebugCanvas canvas, AxisAlignedBoundingBox box, StrokeStyle strokeStyle) { var extents = box.Extents; var nbl = box.Center - extents; var ftr = box.Center + extents; canvas.BatchDraw(() => { canvas.DrawLine(new DoubleVector3(nbl.X, nbl.Y, nbl.Z), new DoubleVector3(ftr.X, nbl.Y, nbl.Z), strokeStyle); canvas.DrawLine(new DoubleVector3(nbl.X, nbl.Y, nbl.Z), new DoubleVector3(nbl.X, ftr.Y, nbl.Z), strokeStyle); canvas.DrawLine(new DoubleVector3(nbl.X, nbl.Y, nbl.Z), new DoubleVector3(nbl.X, nbl.Y, ftr.Z), strokeStyle); canvas.DrawLine(new DoubleVector3(nbl.X, ftr.Y, nbl.Z), new DoubleVector3(ftr.X, ftr.Y, nbl.Z), strokeStyle); canvas.DrawLine(new DoubleVector3(nbl.X, nbl.Y, ftr.Z), new DoubleVector3(ftr.X, nbl.Y, ftr.Z), strokeStyle); canvas.DrawLine(new DoubleVector3(nbl.X, ftr.Y, ftr.Z), new DoubleVector3(ftr.X, ftr.Y, ftr.Z), strokeStyle); canvas.DrawLine(new DoubleVector3(nbl.X, nbl.Y, ftr.Z), new DoubleVector3(nbl.X, ftr.Y, ftr.Z), strokeStyle); canvas.DrawLine(new DoubleVector3(nbl.X, ftr.Y, nbl.Z), new DoubleVector3(nbl.X, ftr.Y, ftr.Z), strokeStyle); canvas.DrawLine(new DoubleVector3(ftr.X, nbl.Y, nbl.Z), new DoubleVector3(ftr.X, ftr.Y, nbl.Z), strokeStyle); canvas.DrawLine(new DoubleVector3(ftr.X, nbl.Y, ftr.Z), new DoubleVector3(ftr.X, ftr.Y, ftr.Z), strokeStyle); canvas.DrawLine(new DoubleVector3(ftr.X, nbl.Y, nbl.Z), new DoubleVector3(ftr.X, nbl.Y, ftr.Z), strokeStyle); canvas.DrawLine(new DoubleVector3(ftr.X, ftr.Y, nbl.Z), new DoubleVector3(ftr.X, ftr.Y, ftr.Z), strokeStyle); }); }