Exemplo n.º 1
0
 public void Relax(int nIterations)
 {
     if (m_voronoi == null) {
         Gen ();
     }
     m_voronoi = m_voronoi.Relax(nIterations);
     m_edges = m_voronoi.ComputeVoronoiDiagram ();
     Debug.Log ("Relax done!");
 }
Exemplo n.º 2
0
    public void Gen()
    {
        // generate set of random points
        m_points = new List<Vector2> ();
        for (int i = 0; i < m_pointCount; i++) {
            m_points.Add (new Vector2 (
                    UnityEngine.Random.Range (0, m_mapWidth),
                    UnityEngine.Random.Range (0, m_mapHeight))
            );
        }

        // generate voronoi region
        if (m_voronoi != null) {
            m_voronoi.Dispose();
        }
        m_voronoi = new Delaunay.Voronoi (m_points, new Rect (0, 0, m_mapWidth, m_mapHeight));
        m_edges = m_voronoi.ComputeVoronoiDiagram ();

        //m_spanningTree = v.SpanningTree (KruskalType.MINIMUM);
        //m_delaunayTriangulation = v.DelaunayTriangulation ();

        Debug.Log ("Gen done!");
    }
Exemplo n.º 3
0
    public void GenerateRegions()
    {
        List<Vector2> points = new List<Vector2> ();

        dimensions = new Vector2(Map.terrainSize.tileSize, Map.terrainSize.tileSize);

        // 1. generate points
        GeneratePoints (points);

        if (voronoi != null) {
            voronoi.Dispose();
        }

        // 2. generate voronoi regions
        voronoi = new Delaunay.Voronoi (points, new Rect (0, 0, dimensions.x, dimensions.y));

        // 3. relax, to make regions a bit more uniform
        //m_voronoi = m_voronoi.Relax (1);

        // 4a. get sites defining the island boundary
        hullSites = voronoi.GetHullSites ();

        // 4b. get dalaunay boundary
        //m_delaunayHullSegments = m_voronoi.GetHullLineSegments ();

        // 4c. get edges for drawing
        voronoiEdges = voronoi.ComputeVoronoiDiagram ();

        // 5. Initialize additional structure information
        InitSiteData ();

        // force a re-draw
        debugDraw = null;
    }