示例#1
0
        private List <Vector2> GenerateConvexHull()
        {
            List <Structure> subWalls = Structure.WallList.FindAll(wall => wall.Submarine == submarine);

            if (subWalls.Count == 0)
            {
                return(new List <Vector2> {
                    new Vector2(-1.0f, 1.0f), new Vector2(1.0f, 1.0f), new Vector2(0.0f, -1.0f)
                });
            }

            List <Vector2> points = new List <Vector2>();

            foreach (Structure wall in subWalls)
            {
                points.Add(new Vector2(wall.Rect.X, wall.Rect.Y));
                points.Add(new Vector2(wall.Rect.X + wall.Rect.Width, wall.Rect.Y));
                points.Add(new Vector2(wall.Rect.X, wall.Rect.Y - wall.Rect.Height));
                points.Add(new Vector2(wall.Rect.X + wall.Rect.Width, wall.Rect.Y - wall.Rect.Height));
            }

            List <Vector2> hullPoints = MathUtils.GiftWrap(points);

            return(hullPoints);
        }
示例#2
0
        private void GenerateWallVertices(XElement rootElement)
        {
            List <Vector2> points = new List <Vector2>();

            var wallPrefabs = StructurePrefab.Prefabs.Where(mp => mp.Body);

            foreach (XElement element in rootElement.Elements())
            {
                if (element.Name != "Structure")
                {
                    continue;
                }

                string name       = element.GetAttributeString("name", "");
                string identifier = element.GetAttributeString("identifier", "");

                StructurePrefab prefab = Structure.FindPrefab(name, identifier);
                if (prefab == null)
                {
                    continue;
                }

                var rect = element.GetAttributeVector4("rect", Vector4.Zero);

                points.Add(new Vector2(rect.X, rect.Y));
                points.Add(new Vector2(rect.X + rect.Z, rect.Y));
                points.Add(new Vector2(rect.X, rect.Y - rect.W));
                points.Add(new Vector2(rect.X + rect.Z, rect.Y - rect.W));
            }

            wallVertices = MathUtils.GiftWrap(points);
        }
示例#3
0
        private void GenerateWallVertices(XElement rootElement)
        {
            List <Vector2> points = new List <Vector2>();

            var wallPrefabs =
                MapEntityPrefab.List.FindAll(mp => (mp is StructurePrefab) && ((StructurePrefab)mp).Body);

            foreach (XElement element in rootElement.Elements())
            {
                if (element.Name != "Structure")
                {
                    continue;
                }

                string name = element.GetAttributeString("name", "");
                if (!wallPrefabs.Any(wp => wp.Name == name))
                {
                    continue;
                }

                var rect = element.GetAttributeVector4("rect", Vector4.Zero);

                points.Add(new Vector2(rect.X, rect.Y));
                points.Add(new Vector2(rect.X + rect.Z, rect.Y));
                points.Add(new Vector2(rect.X, rect.Y - rect.W));
                points.Add(new Vector2(rect.X + rect.Z, rect.Y - rect.W));
            }

            wallVertices = MathUtils.GiftWrap(points);
        }
示例#4
0
        public LevelWall(List <Vector2> vertices, Color color, Level level, bool giftWrap = false)
        {
            this.level = level;
            this.color = color;
            List <Vector2> originalVertices = new List <Vector2>(vertices);

            if (giftWrap)
            {
                vertices = MathUtils.GiftWrap(vertices);
            }
            if (vertices.Count < 3)
            {
                throw new ArgumentException("Failed to generate a wall (not enough vertices). Original vertices: " + string.Join(", ", originalVertices.Select(v => v.ToString())));
            }
            VoronoiCell wallCell = new VoronoiCell(vertices.ToArray());

            for (int i = 0; i < wallCell.Edges.Count; i++)
            {
                wallCell.Edges[i].Cell1   = wallCell;
                wallCell.Edges[i].IsSolid = true;
            }
            Cells = new List <VoronoiCell>()
            {
                wallCell
            };
            Body = CaveGenerator.GeneratePolygons(Cells, level, out triangles);
            if (triangles.Count == 0)
            {
                throw new ArgumentException("Failed to generate a wall (not enough triangles). Original vertices: " + string.Join(", ", originalVertices.Select(v => v.ToString())));
            }
#if CLIENT
            GenerateVertices();
#endif
        }
示例#5
0
        public LevelWall(List <Vector2> vertices, Color color, Level level, bool giftWrap = false)
        {
            if (giftWrap)
            {
                vertices = MathUtils.GiftWrap(vertices);
            }

            VoronoiCell wallCell = new VoronoiCell(vertices.ToArray());

            for (int i = 0; i < wallCell.Edges.Count; i++)
            {
                wallCell.Edges[i].Cell1   = wallCell;
                wallCell.Edges[i].IsSolid = true;
            }
            cells = new List <VoronoiCell>()
            {
                wallCell
            };

            body = CaveGenerator.GeneratePolygons(cells, level, out List <Vector2[]> triangles);
#if CLIENT
            List <VertexPositionTexture> bodyVertices = CaveGenerator.GenerateRenderVerticeList(triangles);
            SetBodyVertices(bodyVertices.ToArray(), color);
            SetWallVertices(CaveGenerator.GenerateWallShapes(cells, level), color);
#endif
        }
示例#6
0
        private List <LocationConnection> GetMapEdges()
        {
            List <Vector2> verts = Locations.Select(l => l.MapPosition).ToList();

            List <Vector2> giftWrappedVerts = MathUtils.GiftWrap(verts);

            List <LocationConnection> edges = new List <LocationConnection>();

            foreach (LocationConnection connection in connections)
            {
                if (giftWrappedVerts.Contains(connection.Locations[0].MapPosition) ||
                    giftWrappedVerts.Contains(connection.Locations[1].MapPosition))
                {
                    edges.Add(connection);
                }
            }

            return(edges);
        }