예제 #1
0
        private void AddSite(Point tail, Point head)
        {
            PointSite ps = new PointSite(tail, pointSitePrefab, spheres);

            if (!pointSites.ContainsNear(ps))
            {
                pointSites.Add(ps);
                sites.Add(ps);
            }

            LineSite ls = new LineSite(tail, head, lineSitePrefab, cylinders);

            if (!lineSites.Contains(ls))
            {
                lineSites.Add(ls);
                sites.Add(ls);
            }
        }
예제 #2
0
        public void Generate()
        {
            wall2point = new Point[maze.Length, 4];

            for (int iwall = 0; iwall < maze.Length; ++iwall)
            {
                Transform wall = maze[iwall];

                for (int icorner = 0; icorner < 4; ++icorner)
                {
                    Point p = Corner(wall, icorner);

                    if (points.ContainsNear(p))
                    {
                        p = points.GetNear(p);
                    }
                    else
                    {
                        points.Add(p);

                        List <WallIndex> walls = new List <WallIndex>();
                        point2wall.Add(p, walls);
                    }

                    point2wall[p].Add(new WallIndex(iwall, icorner));
                    wall2point[iwall, icorner] = p;
                }
            }

            WallIndex currentWall = new WallIndex(0, 2);
            Point     current     = vertices.AddNear(LookupPoint(currentWall));
            Point     first       = current;

            Point     prev     = null;
            WallIndex peekWall = null;
            Point     peek     = null;

            for (int ii = 0; ii < 100; ++ii)
            {
                prev = current;

                currentWall = FindNextWall(currentWall).Rotate;

                current = LookupPoint(currentWall);
                if (current.IsCoincident(first))
                {
                    edges.Add(new PolygonEdge(prev, first));
                    break;
                }

                // combine parallel wall edges
                for (int jj = 0; jj < 5; ++jj)
                {
                    peekWall = FindNextWall(currentWall).Rotate;

                    peek = LookupPoint(peekWall);
                    Vector v0 = current - prev;
                    Vector v1 = peek - current;

                    if (v1.IsParallel(v0)) // (peek - current).IsParallel(current - prev))
                    {
                        currentWall = peekWall;
                        current     = peek;
                    }
                    else
                    {
                        break;
                    }
                }

                current = vertices.AddNear(current);
                edges.Add(new PolygonEdge(prev, current));
            }

            DetermineBounds();
        }