Exemple #1
0
        private static void RenderVisualizationFrame()
        {
            var segments = Util.Generate(200, RandomSegment);
//         var quad = new[] { new IntVector2(100, 100), new IntVector2(200, 200), new IntVector2(300, 300), new IntVector2(400, 400) };
            var quad = Util.Generate(4, RandomPoint);
            var hull = GeometryOperations.ConvexHull4(quad[0], quad[1], quad[2], quad[3]);

            var canvas = host.CreateAndAddCanvas(frameCounter++);

            canvas.BatchDraw(() => {
                foreach (var(x, y) in quad.Zip(quad.RotateLeft()))
                {
                    canvas.DrawLine(x, y, StrokeStyle.BlackHairLineDashed5);
                }
                foreach (var(x, y) in hull.Zip(hull.RotateLeft()))
                {
                    canvas.DrawLine(x, y, StrokeStyle.BlackHairLineSolid);
                }
                foreach (var p in hull)
                {
                    canvas.DrawPoint(p, StrokeStyle.RedThick5Solid);
                }
                foreach (var s in segments)
                {
                    canvas.DrawLine(s.First, s.Second, GeometryOperations.SegmentIntersectsConvexPolygonInterior(s, hull) ? StrokeStyle.LimeHairLineDashed5 : StrokeStyle.RedHairLineDashed5);
                }
            });
        }
Exemple #2
0
        private static void RenderSomething(int canvasIndex, Polygon2 subject, Polygon2 clip)
        {
            var canvas = host.CreateAndAddCanvas(canvasIndex);

            canvas.Transform = Matrix4x4.CreateTranslation(150, 150, 0) * Matrix4x4.CreateScale(2);
            canvas.DrawLineStrip(subject.Points.Concat(new[] { subject.Points[0] }).ToArray(), StrokeStyle.CyanThick3Solid);
            canvas.DrawLineStrip(clip.Points.Concat(new[] { clip.Points[0] }).ToArray(), StrokeStyle.RedThick3Solid);

            canvas.Transform = Matrix4x4.CreateTranslation(450, 150, 0) * Matrix4x4.CreateScale(2);
            canvas.DrawLineStrip(subject.Points.Concat(new[] { subject.Points[0] }).ToArray(), StrokeStyle.CyanHairLineSolid);
            canvas.DrawLineStrip(clip.Points.Concat(new[] { clip.Points[0] }).ToArray(), StrokeStyle.RedHairLineSolid);

            if (PolygonOperations.TryConvexClip(subject, clip, out var result))
            {
                canvas.DrawLineStrip(result.Points.Concat(new[] { result.Points[0] }).ToArray(), StrokeStyle.LimeThick5Solid);
            }
        }
Exemple #3
0
        public static void Main(string[] args)
        {
            var sectorMetadataPresets = SectorMetadataPresets.HashCircle2;
            var terrainStaticMetadata = new TerrainStaticMetadata {
                LocalBoundary         = sectorMetadataPresets.LocalBoundary,
                LocalIncludedContours = sectorMetadataPresets.LocalIncludedContours,
                LocalExcludedContours = sectorMetadataPresets.LocalExcludedContours
            };

            var(localGeometryView, landPolyNode, crossoverPointManager) = BenchmarkAddCrossoverPoints(terrainStaticMetadata);
            var canvas = host.CreateAndAddCanvas(0);

            canvas.Transform = Matrix4x4.CreateScale(1000 / 60000.0f) * Matrix4x4.CreateTranslation(500, 500, 0);
            canvas.DrawPolyNode((PolyTree)landPolyNode.Parent);
            canvas.DrawVisibilityGraph(landPolyNode.ComputeVisibilityGraph());
            canvas.DrawLineList(landPolyNode.FindContourAndChildHoleBarriers(), StrokeStyle.BlackHairLineSolid);
            canvas.DrawPoints(crossoverPointManager.CrossoverPoints, StrokeStyle.RedThick5Solid);

            // var a = landPolyNode.FindAggregateContourCrossoverWaypoints()[6];
            // var b = landPolyNode.FindAggregateContourCrossoverWaypoints()[13];
            // var q = new IntLineSegment2(a, b);
            // canvas.DrawPoint(a, StrokeStyle.RedThick5Solid);
            // canvas.DrawPoint(b, StrokeStyle.RedThick5Solid);
            // var bvh = landPolyNode.FindContourAndChildHoleBarriersBvh();
            // canvas.DrawBvh(bvh);
            // foreach (var (i, val) in bvh.BoundingBoxes.Enumerate()) {
            //    if (val.Intersects(q)) Console.WriteLine(i + " " + val);
            // }
            // var intersects = bvh.Intersects(q);
            // canvas.DrawLine(a, b, intersects ? StrokeStyle.RedHairLineSolid : StrokeStyle.LimeHairLineSolid);

            PolyNodeCrossoverPointManager.DumpPerformanceCounters();

            while (true)
            {
                const int ntrials = 10;
                var       sw      = new Stopwatch();
                sw.Start();
                for (var i = 0; i < ntrials; i++)
                {
                    BenchmarkAddCrossoverPoints(terrainStaticMetadata);
                }
                Console.WriteLine($"{ntrials} trials in {sw.ElapsedMilliseconds} ms");
            }
        }
Exemple #4
0
        private static void RenderVisualizationFrame()
        {
            var segments = Util.Generate(200, RandomSegment);

            var(ax, ay) = RandomPoint();
            var(bx, by) = RandomPoint();
            var rect = new IntRect2(Math.Min(ax, bx), Math.Min(ay, by), Math.Max(ax, bx), Math.Max(ay, by));
            //var rect = new IntRect2(Math.Min(ax, bx), Math.Min(ay, by), Math.Min(ax, bx), Math.Max(ay, by));
            //var rect = new IntRect2(segments[0].X1, segments[0].Y1, segments[0].X1, segments[0].Y1);

            var canvas = host.CreateAndAddCanvas(frameCounter++);

            canvas.BatchDraw(() => {
                canvas.DrawRectangle(rect, 0, StrokeStyle.BlackHairLineSolid);
                foreach (var s in segments)
                {
                    canvas.DrawLine(s.First, s.Second, rect.ContainsOrIntersects(s) ? StrokeStyle.LimeHairLineDashed5 : StrokeStyle.RedHairLineDashed5);
                }
            });
        }
Exemple #5
0
        private static void RenderVisualizationFrame(DoubleVector2 p, IntLineSegment2[] segments, int eventLimit = -1)
        {
            var canvas = host.CreateAndAddCanvas(frameCounter++);
            var vp     = VisibilityPolygon.Create(p, segments, eventLimit);

            vp = new VisibilityPolygon(p);
            foreach (var seg in segments)
            {
                vp.Insert(seg);
            }
//         vp.Insert(new IntLineSegment2(p.LossyToIntVector2() + new IntVector2(50, -20), p.LossyToIntVector2() + new IntVector2(50, 20)));

            canvas.BatchDraw(() => {
                canvas.DrawVisibilityPolygon(vp, 0, new FillStyle(Color.FromArgb(120, Color.Cyan)));
                foreach (var s in segments)
                {
                    canvas.DrawLine(s.First, s.Second, StrokeStyle.BlackHairLineSolid);
                }
                canvas.DrawPoint(p, StrokeStyle.RedThick5Solid);
            });
        }
        private void DebugRenderLocalGeometryView(LocalGeometryView localGeometryView, params IntLineSegment2[] segs)
        {
            if (!kEnableDebugRender)
            {
                return;
            }

            Size bounds      = new Size(1280, 720);
            var  renderScale = 1.0f;

            PerspectiveProjector CreateCanvasProjector()
            {
                var rotation    = 95 * Math.PI / 180.0;
                var displaySize = new Size((int)(bounds.Width * renderScale), (int)(bounds.Height * renderScale));
                var center      = new DoubleVector3(0, 0, 0);
                var projector   = new PerspectiveProjector(
                    center + DoubleVector3.FromRadiusAngleAroundXAxis(1000, rotation),
                    center,
                    DoubleVector3.FromRadiusAngleAroundXAxis(1, rotation - Math.PI / 2),
                    displaySize.Width,
                    displaySize.Height);

                return(projector);
            }

            DebugMultiCanvasHost host = DebugMultiCanvasHost.CreateAndShowCanvas(bounds, new Point(0, 0), CreateCanvasProjector());
            var canvas = host.CreateAndAddCanvas(0);

            canvas.DrawPolyNode(localGeometryView.PunchedLand);
            foreach (var hole in localGeometryView.Job.DynamicHoles)
            {
                canvas.DrawPolygonContours(hole.Value.holeExcludedContours, StrokeStyle.OrangeHairLineSolid);
                canvas.DrawPolygonContours(hole.Value.holeIncludedContours, StrokeStyle.RedHairLineSolid);
            }
            foreach (var seg in segs)
            {
                canvas.DrawLine(seg, StrokeStyle.CyanHairLineSolid);
            }
        }
Exemple #7
0
        public static void Main(string[] args)
        {
            var sectorGraphDescriptionStore = new SectorGraphDescriptionStore();
            var snapshotCompiler            = new TerrainSnapshotCompiler(sectorGraphDescriptionStore);
            var terrainService = new TerrainService(sectorGraphDescriptionStore, snapshotCompiler);

            // Add test sectors
            var leftSnd = terrainService.CreateSectorNodeDescription(SectorMetadataPresets.HashCircle2);

//         leftSnd.EnableDebugHighlight = true;
            leftSnd.WorldTransform = Matrix4x4.CreateScale(1000.0f / 60000.0f) * Matrix4x4.CreateTranslation(-1000, 0, 0);
            terrainService.AddSectorNodeDescription(leftSnd);

            var centerSnd = terrainService.CreateSectorNodeDescription(SectorMetadataPresets.Blank2D);

            centerSnd.EnableDebugHighlight = true;
            centerSnd.WorldTransform       = Matrix4x4.CreateScale(1000.0f / 60000.0f);
            terrainService.AddSectorNodeDescription(centerSnd);

            /*+		[0]	{(-30000, -18000)}	OpenMOBA.Geometry.IntVector2
             +		[1]	{(-30000, -6000)}	OpenMOBA.Geometry.IntVector2
             +		[2]	{(-6000, -6000)}	OpenMOBA.Geometry.IntVector2
             +		[3]	{(-6000, -18000)}	OpenMOBA.Geometry.IntVector2
             +		[4]	{(-30000, -18000)}	OpenMOBA.Geometry.IntVector2
             */
            var rightSnd = terrainService.CreateSectorNodeDescription(SectorMetadataPresets.HashCircle2);

            rightSnd.WorldTransform = Matrix4x4.CreateScale(1000.0f / 60000.0f) * Matrix4x4.CreateTranslation(1000, 0, 0);
            terrainService.AddSectorNodeDescription(rightSnd);

            // edges between test sectors

            var rightTopSegment    = new IntLineSegment2(new IntVector2(30000, 6000), new IntVector2(30000, 18000));
            var leftTopSegment     = new IntLineSegment2(new IntVector2(-30000, 6000), new IntVector2(-30000, 18000));
            var rightBottomSegment = new IntLineSegment2(new IntVector2(30000, -18000), new IntVector2(30000, -6000));
            var leftBottomSegment  = new IntLineSegment2(new IntVector2(-30000, -18000), new IntVector2(-30000, -6000));

            terrainService.AddSectorEdgeDescription(PortalSectorEdgeDescription.Build(
                                                        leftSnd, centerSnd,
                                                        rightTopSegment,
                                                        leftTopSegment));
            terrainService.AddSectorEdgeDescription(PortalSectorEdgeDescription.Build(
                                                        centerSnd, leftSnd,
                                                        leftTopSegment,
                                                        rightTopSegment));
            terrainService.AddSectorEdgeDescription(PortalSectorEdgeDescription.Build(
                                                        leftSnd, centerSnd,
                                                        rightBottomSegment,
                                                        leftBottomSegment));
            terrainService.AddSectorEdgeDescription(PortalSectorEdgeDescription.Build(
                                                        centerSnd, leftSnd,
                                                        leftBottomSegment,
                                                        rightBottomSegment));

            //
            terrainService.AddSectorEdgeDescription(PortalSectorEdgeDescription.Build(
                                                        centerSnd, rightSnd,
                                                        rightTopSegment,
                                                        leftTopSegment));
            terrainService.AddSectorEdgeDescription(PortalSectorEdgeDescription.Build(
                                                        rightSnd, centerSnd,
                                                        leftTopSegment,
                                                        rightTopSegment));

            terrainService.AddSectorEdgeDescription(PortalSectorEdgeDescription.Build(
                                                        centerSnd, rightSnd,
                                                        rightBottomSegment,
                                                        leftBottomSegment));
            terrainService.AddSectorEdgeDescription(PortalSectorEdgeDescription.Build(
                                                        rightSnd, centerSnd,
                                                        leftBottomSegment,
                                                        rightBottomSegment));

            // add some obstacles
//         terrainService.AddTemporaryHoleDescription(terrainService.CreateHoleDescription(
//            HoleStaticMetadata.CreateRectangleHoleMetadata(-500, 250, 60, 60, 0)));
//         terrainService.AddTemporaryHoleDescription(terrainService.CreateHoleDescription(
//            HoleStaticMetadata.CreateRectangleHoleMetadata(0, 130, 60, 60, 0)));
            for (var i = 0; i < 100; i++)
            {
                break;
                terrainService.AddTemporaryHoleDescription(terrainService.CreateHoleDescription(
                                                               HoleStaticMetadata.CreateRectangleHoleMetadata(
                                                                   random.Next(-1500, 1500),
                                                                   random.Next(-500, 500),
                                                                   random.Next(10, 50),
                                                                   random.Next(10, 50),
                                                                   random.NextDouble() * Math.PI * 2)));
            }

            var terrainSnapshot = terrainService.CompileSnapshot();
            var overlayNetwork  = terrainSnapshot.OverlayNetworkManager.CompileTerrainOverlayNetwork(30);

            for (var i = 0; i < 360; i += 10)
            {
                var canvas = host.CreateAndAddCanvas(i);
                canvas.BatchDraw(() => {
                    foreach (var terrainNode in overlayNetwork.TerrainNodes)
                    {
                        canvas.Transform = terrainNode.SectorNodeDescription.WorldTransform;
                        canvas.DrawPolyNode(terrainNode.LandPolyNode, StrokeStyle.BlackHairLineSolid, StrokeStyle.DarkRedHairLineSolid);
                    }

                    foreach (var terrainNode in overlayNetwork.TerrainNodes)
                    {
                        canvas.Transform = terrainNode.SectorNodeDescription.WorldTransform;
                        foreach (var outboundEdgeGroup in terrainNode.OutboundEdgeGroups)
                        {
                            foreach (var outboundEdge in outboundEdgeGroup.Value)
                            {
                                Console.WriteLine(outboundEdge.EdgeJob.SourceSegment);
                                canvas.DrawLine(outboundEdge.EdgeJob.SourceSegment, StrokeStyle.CyanThick3Solid);
                            }
                        }
                    }

                    foreach (var terrainNode in overlayNetwork.TerrainNodes)
                    {
                        canvas.Transform = terrainNode.SectorNodeDescription.WorldTransform;

                        foreach (var hole in terrainNode.LocalGeometryView.Job.DynamicHoles)
                        {
                            var(holeIncludedContours, holeExcludedContours) = hole.Value;
                            canvas.DrawPolygonContours(holeIncludedContours, StrokeStyle.RedHairLineSolid);
                            canvas.DrawPolygonContours(holeExcludedContours, StrokeStyle.OrangeHairLineSolid);
                        }
                    }

                    int asdfa = -1;
                    foreach (var terrainNode in overlayNetwork.TerrainNodes)
                    {
                        asdfa++;
                        canvas.Transform = terrainNode.SectorNodeDescription.WorldTransform;

                        if (terrainNode.SectorNodeDescription.EnableDebugHighlight)
                        {
                            var visibilityPolygonOrigin = IntVector2.FromRadiusAngle(50 * 60, i * Math.PI / 180) + new IntVector2(0, 0);
                            canvas.DrawCrossSectorVisibilityPolygon(terrainNode, visibilityPolygonOrigin);
                        }
                    }
                });
            }
        }