Esempio n. 1
0
        private static void H()
        {
            var points = new[] {
                new IntVector2(100, 50),
                new IntVector2(100, 100),
                new IntVector2(200, 100),
                new IntVector2(200, 150),
                new IntVector2(200, 200),
                new IntVector2(400, 250),
                new IntVector2(200, 300),
                new IntVector2(400, 315),
                new IntVector2(200, 330),
                new IntVector2(210, 340),
                new IntVector2(220, 350),
                new IntVector2(220, 400),
                new IntVector2(221, 400)
            };

//         }.Concat(Enumerable.Range(1, 90).Select(i => {
//            var p = new IntVector2(220, 400);
//            var r = IntVector2.FromRadiusAngle(20, i * Math.PI / 180);
//            return p + r;
//         })).ToArray();

            PolylineOperations.ExtrudePolygon(points, 10);
        }
Esempio n. 2
0
        private void AddSquiggleHole()
        {
            var holeSquiggle = PolylineOperations.ExtrudePolygon(
                new[] {
                new IntVector2(100, 50),
                new IntVector2(100, 100),
                new IntVector2(200, 100),
                new IntVector2(200, 150),
                new IntVector2(200, 200),
                new IntVector2(400, 250),
                new IntVector2(200, 300),
                new IntVector2(400, 315),
                new IntVector2(200, 330),
                new IntVector2(210, 340),
                new IntVector2(220, 350),
                new IntVector2(220, 400),
                new IntVector2(221, 400)
            }.Select(iv => new IntVector2(iv.X + 160, iv.Y + 200)).ToArray(), 10).FlattenToPolygonAndIsHoles();

            Console.WriteLine("NI: AddSquiggleHole");
            throw new NotImplementedException();
        }
Esempio n. 3
0
        private static void X()
        {
            var mapDimensions = new Size(1000, 1000);
            var holes         = new[] {
                Polygon2.CreateRect(100, 100, 300, 300),
                Polygon2.CreateRect(400, 200, 100, 100),
                Polygon2.CreateRect(200, -50, 100, 150),
                Polygon2.CreateRect(600, 600, 300, 300),
                Polygon2.CreateRect(700, 500, 100, 100),
                Polygon2.CreateRect(200, 700, 100, 100),
                Polygon2.CreateRect(600, 100, 300, 50),
                Polygon2.CreateRect(600, 150, 50, 200),
                Polygon2.CreateRect(850, 150, 50, 200),
                Polygon2.CreateRect(600, 350, 300, 50),
                Polygon2.CreateRect(700, 200, 100, 100)
            };

            var holeSquiggle = PolylineOperations.ExtrudePolygon(
                new[] {
                new IntVector2(100, 50),
                new IntVector2(100, 100),
                new IntVector2(200, 100),
                new IntVector2(200, 150),
                new IntVector2(200, 200),
                new IntVector2(400, 250),
                new IntVector2(200, 300),
                new IntVector2(400, 315),
                new IntVector2(200, 330),
                new IntVector2(210, 340),
                new IntVector2(220, 350),
                new IntVector2(220, 400),
                new IntVector2(221, 400)
            }.Select(iv => new IntVector2(iv.X + 160, iv.Y + 200)).ToArray(), 10).FlattenToPolygonAndIsHoles().Map(t => t.polygon);

            holes = holes.Concat(holeSquiggle).ToArray();

            var landPoly         = Polygon2.CreateRect(0, 0, 1000, 1000);
            var holesUnionResult = PolygonOperations.Offset()
                                   .Include(holes)
                                   .Include(holeSquiggle)
                                   .Dilate(15)
                                   .Execute();
            var landHolePunchResult = PolygonOperations.Punch()
                                      .Include(landPoly)
                                      .IncludeOrExclude(holesUnionResult.FlattenToPolygonAndIsHoles(), true)
                                      .Execute();
            var visibilityGraph = landHolePunchResult.ComputeVisibilityGraph();
//         var debugCanvas = DebugCanvasHost.CreateAndShowCanvas();
//         debugCanvas.DrawPolygons(holes, Color.Red);
//         debugCanvas.DrawVisibilityGraph(visibilityGraph);
//         var testPathFindingQueries = new[] {
//            Tuple.Create(new IntVector2(60, 40), new IntVector2(930, 300)),
//            Tuple.Create(new IntVector2(675, 175), new IntVector2(825, 300)),
//            Tuple.Create(new IntVector2(50, 900), new IntVector2(950, 475)),
//            Tuple.Create(new IntVector2(50, 500), new IntVector2(80, 720))
//         };

//         using (var pen = new Pen(Color.Lime, 2)) {
//            foreach (var query in testPathFindingQueries) {
//               Path path;
//               if (visibilityGraph.TryFindPath(query.Item1, query.Item2, out path))
//                  debugCanvas.DrawLineStrip(path.Points, pen);
//            }
//         }
        }
Esempio n. 4
0
        private static void Step(GraphicsLoop graphicsLoop, Game game, InputSomethingOSDJFH input, Scene scene)
        {
            var expectedTicks = (int)(graphicsLoop.Statistics.FrameTime.TotalSeconds * 60);

            while (game.GameTimeService.Ticks < expectedTicks)
            {
                game.Tick();
            }

            var viewProj = ComputeProjViewMatrix(graphicsLoop.Form.ClientSize);

            viewProj.Transpose();
            var ray = Ray.GetPickRay(input.X, input.Y, new ViewportF(0, 0, 1280, 720, 1.0f, 100.0f), viewProj);

            var terrainOverlayNetwork = game.TerrainService.CompileSnapshot().OverlayNetworkManager.CompileTerrainOverlayNetwork(0);

            // rmb moves
            if (input.IsMouseDown(MouseButtons.Right))
            {
                foreach (var node in terrainOverlayNetwork.TerrainNodes)
                {
                    var origin = node.SectorNodeDescription.LocalToWorld(DoubleVector2.Zero);
                    var normal = node.SectorNodeDescription.LocalToWorldNormal(DoubleVector3.UnitZ);
                    var plane  = new SDXPlane(ToSharpDX(origin), ToSharpDX(normal));
                    if (!plane.Intersects(ref ray, out SDXVector3 intersection))
                    {
                        continue;
                    }

                    var intersectionLocal = node.SectorNodeDescription.WorldToLocal(intersection.ToOpenMoba());
                    if (!node.LandPolyNode.PointInLandPolygonNonrecursive(intersectionLocal.XY.LossyToIntVector2()))
                    {
                        continue;
                    }

                    // recompute intersectionWorld because floating point error in raycast logic
                    var intersectionWorld = node.SectorNodeDescription.LocalToWorld(intersectionLocal.XY);
                    game.MovementSystemService.Pathfind(player, intersectionWorld);
                }
            }

            // lazaars
            if (input.IsKeyDown(Keys.Q))
            {
                foreach (var node in terrainOverlayNetwork.TerrainNodes)
                {
                    var origin = node.SectorNodeDescription.LocalToWorld(DoubleVector2.Zero);
                    var normal = node.SectorNodeDescription.LocalToWorldNormal(DoubleVector3.UnitZ);
                    var plane  = new SDXPlane(ToSharpDX(origin), ToSharpDX(normal));
                    if (!plane.Intersects(ref ray, out SDXVector3 intersection))
                    {
                        continue;
                    }

                    var intersectionLocal = node.SectorNodeDescription.WorldToLocal(intersection.ToOpenMoba());
                    if (!node.SectorNodeDescription.StaticMetadata.LocalBoundary.Contains(new SDPoint((int)intersectionLocal.X, (int)intersectionLocal.Y)))
                    {
                        continue;
                    }
                    if (!node.LandPolyNode.PointInLandPolygonNonrecursive(player.MovementComponent.LocalPositionIv2))
                    {
                        continue;
                    }

                    // recompute intersectionWorld because floating point error in raycast logic
                    var intersectionWorld = node.SectorNodeDescription.LocalToWorld(intersectionLocal.XY);

                    var barriersBvh = node.LandPolyNode.FindContourAndChildHoleBarriersBvh();
                    var q           = new IntLineSegment2(player.MovementComponent.LocalPositionIv2, intersectionLocal.XY.LossyToIntVector2());
                    debugCanvas.Transform = node.SectorNodeDescription.WorldTransform;
                    debugCanvas.DrawLine(q, StrokeStyle.RedHairLineSolid);
                    foreach (var seg in barriersBvh.Segments)
                    {
                        debugCanvas.DrawLine(seg, StrokeStyle.RedThick5Solid);
                    }

                    var intersectingLeaves = barriersBvh.FindPotentiallyIntersectingLeaves(q);
                    var tFar = 1.0;
                    foreach (var bvhNode in intersectingLeaves)
                    {
                        for (var i = bvhNode.SegmentsStartIndexInclusive; i < bvhNode.SegmentsEndIndexExclusive; i++)
                        {
                            if (GeometryOperations.TryFindNonoverlappingSegmentSegmentIntersectionT(ref q, ref bvhNode.Segments[i], out var t))
                            {
                                Console.WriteLine(t);
                                tFar = Math.Min(tFar, t);
                            }
                        }
                    }

                    debugCanvas.Transform = Matrix4x4.Identity;
                    debugCanvas.DrawLine(player.MovementComponent.WorldPosition, node.SectorNodeDescription.LocalToWorld(q.PointAt(tFar)), StrokeStyle.LimeThick5Solid);
                }
            }

            // i love rocks
            var rocksExisting = new List <Entity>();

            foreach (var rock in rocks)
            {
                var distance = rock.MovementComponent.WorldPosition.To(player.MovementComponent.WorldPosition).Norm2D();
                if (distance > player.MovementComponent.ComputedRadius)
                {
                    rocksExisting.Add(rock);
                    continue;
                }
                game.EntityService.RemoveEntity(rock);
            }
            rocks = rocksExisting;

            // W draws walls
            if (input.IsKeyJustDown(Keys.W))
            {
                foreach (var node in terrainOverlayNetwork.TerrainNodes)
                {
                    var origin = node.SectorNodeDescription.LocalToWorld(DoubleVector2.Zero);
                    var normal = node.SectorNodeDescription.LocalToWorldNormal(DoubleVector3.UnitZ);
                    var plane  = new SDXPlane(ToSharpDX(origin), ToSharpDX(normal));
                    if (!plane.Intersects(ref ray, out SDXVector3 intersection))
                    {
                        continue;
                    }

                    var intersectionLocal = node.SectorNodeDescription.WorldToLocal(intersection.ToOpenMoba());
                    if (!node.SectorNodeDescription.StaticMetadata.LocalBoundary.Contains(new SDPoint((int)intersectionLocal.X, (int)intersectionLocal.Y)))
                    {
                        continue;
                    }

                    // recompute intersectionWorld because floating point error in raycast logic
                    var intersectionWorld = node.SectorNodeDescription.LocalToWorld(intersectionLocal.XY);
                    fred.Add(intersectionWorld.XY.LossyToIntVector2());

                    // todo: we really need to iterate over LGVs rather than tnodes
                    break;
                }
            }

            if (input.IsKeyJustDown(Keys.E))
            {
                if (fred.Count > 0)
                {
                    fred.RemoveAt(fred.Count - 1);
                }
            }

            if (input.IsKeyJustDown(Keys.R) && fred.Count >= 2)
            {
                var polyTree    = PolylineOperations.ExtrudePolygon(fred, 10);
                var boundsLower = fred.Aggregate(new IntVector2(int.MaxValue, int.MaxValue), (a, b) => new IntVector2(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y)));
                var boundsUpper = fred.Aggregate(new IntVector2(int.MinValue, int.MinValue), (a, b) => new IntVector2(Math.Max(a.X, b.X), Math.Max(a.Y, b.Y)));
                var bounds      = new SDRectangle(boundsLower.X, boundsLower.Y, boundsUpper.X - boundsLower.X, boundsUpper.Y - boundsLower.Y);

                var holeStaticMetadata = new PrismHoleStaticMetadata(
                    bounds,
                    new[] { new Polygon2(polyTree.Childs[0].Contour) },
                    polyTree.Childs[0].Childs.Map(c => new Polygon2(((IEnumerable <IntVector2>)c.Contour).Reverse().ToList())));

                var terrainHole = game.TerrainService.CreateHoleDescription(holeStaticMetadata);
                game.TerrainService.AddTemporaryHoleDescription(terrainHole);

                if (!input.IsKeyDown(Keys.ShiftKey))
                {
                    var removeEvent = game.CreateRemoveTemporaryHoleEvent(new GameTime(game.GameTimeService.Now.Ticks + 90), terrainHole);
                    game.GameEventQueueService.AddGameEvent(removeEvent);
                }
                fred.Clear();
            }
        }