예제 #1
0
        public void C()
        {
            var localGeometryView = BuildLgv(SectorMetadataPresets.Blank2D, 14, BuildRectangleHole(-664, 133, 174, 188));
            var seg = new IntLineSegment2(new IntVector2(0, 600), new IntVector2(0, 800));

            DebugRenderLocalGeometryView(localGeometryView, seg);
            var results = PortalSectorEdgeDescription.X(seg, localGeometryView).ToArray();

            Assert.Equal(2, results.Length);
        }
예제 #2
0
        public void F()
        {
            var localGeometryView = BuildLgv(
                SectorMetadataPresets.HashCircle2,
                0
                );
            var seg     = new IntLineSegment2(new IntVector2(-2, 620), new IntVector2(-2, 780));
            var results = PortalSectorEdgeDescription.X(seg, localGeometryView).ToArray();

            DebugRenderLocalGeometryView(localGeometryView, seg);
            Assert.Equal(results.Map(x => x.Item2), new[] { 0.0, 1.0 });
        }
예제 #3
0
        public void D()
        {
            var localGeometryView = BuildLgv(
                SectorMetadataPresets.Blank2D,
                14,
                BuildRectangleHole(-517, 107, 5, 5, 4607552631852924299),
                BuildRectangleHole(-506, 100, 6, 7, 4613867344244209246),
                BuildRectangleHole(-505, 136, 6, 7, 4615794974257582119)
                );
            var seg     = new IntLineSegment2(new IntVector2(0, 600), new IntVector2(0, 800));
            var results = PortalSectorEdgeDescription.X(seg, localGeometryView).ToArray();

            DebugRenderLocalGeometryView(localGeometryView, seg);
            Assert.Equal(2, results.Length);
        }
예제 #4
0
        private LocalGeometryView BuildLgv(TerrainStaticMetadata mapStaticMetadata, double holeDilationRadius, params IHoleStaticMetadata[] holeMetadatas)
        {
            var store          = new SectorGraphDescriptionStore();
            var terrainService = new TerrainService(store, new TerrainSnapshotCompiler(store));

            var sector = terrainService.CreateSectorNodeDescription(mapStaticMetadata);

            sector.WorldTransform = Matrix4x4.Multiply(Matrix4x4.CreateScale(1), Matrix4x4.CreateTranslation(-500, -500, 0));
            terrainService.AddSectorNodeDescription(sector);

            var left2 = new IntLineSegment2(new IntVector2(0, 600), new IntVector2(0, 800));

            terrainService.AddSectorEdgeDescription(PortalSectorEdgeDescription.Build(sector, sector, left2, left2));

            foreach (var holeMetadata in holeMetadatas)
            {
                var terrainHole = terrainService.CreateHoleDescription(holeMetadata);
                terrainService.AddTemporaryHoleDescription(terrainHole);
            }

            var terrainOverlayNetwork = terrainService.CompileSnapshot().OverlayNetworkManager.CompileTerrainOverlayNetwork(holeDilationRadius);

            return(terrainOverlayNetwork.TerrainNodes.First().LocalGeometryView);
        }
예제 #5
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);
                        }
                    }
                });
            }
        }