Exemplo n.º 1
0
    public IslandTileEdge (VoronoiEdge e)
    {
        edge = e;

        // Corner Index are assumed to be populated from IslandTile
        cornerA = IslandTileCorner.Index[e.VVertexA];
        cornerB = IslandTileCorner.Index[e.VVertexB];   
    }
Exemplo n.º 2
0
    public IslandTileEdge(VoronoiEdge e)
    {
        edge = e;

        // Corner Index are assumed to be populated from IslandTile
        cornerA = IslandTileCorner.Index[e.VVertexA];
        cornerB = IslandTileCorner.Index[e.VVertexB];
    }
Exemplo n.º 3
0
    private void AddCorners(VoronoiEdge e)
    {
        IslandTileCorner cA = AddCorner(e.VVertexA);
        IslandTileCorner cB = AddCorner(e.VVertexB);

        cA.protrudes.Add(e);
        cA.adjacent.Add(cB);
        cA.touches.Add(this);

        cB.protrudes.Add(e);
        cB.adjacent.Add(cA);
        cB.touches.Add(this);
    }
Exemplo n.º 4
0
    public static IslandTileCorner GetDownSlopeCorner(IslandTileCorner corner)
    {
        float            lowestY    = corner.ElevatedPosition.y;
        IslandTileCorner downCorner = corner;

        foreach (IslandTileCorner c in corner.adjacent)
        {
            float cornerY = c.ElevatedPosition.y;
            if (cornerY < lowestY)
            {
                downCorner = c;
                lowestY    = cornerY;
            }
        }

        return(downCorner);
    }
Exemplo n.º 5
0
    private IslandTileCorner AddCorner(Vector v)
    {
        IslandTileCorner c;
        Dictionary <Vector, IslandTileCorner> cIdx = IslandTileCorner.Index;

        if (cIdx.ContainsKey(v))
        {
            c = IslandTileCorner.Index[v];
        }
        else
        {
            c = new IslandTileCorner(v);
        }

        corners.Add(c);

        return(c);
    }
Exemplo n.º 6
0
    private Vector3 CalcNormal()
    {
        Vector3 norm = Vector3.zero;

        IslandTileCorner[] cArray = new IslandTileCorner[corners.Count];
        corners.CopyTo(cArray);

        for (int i = 0; i < cArray.Length; i++)
        {
            Vector3 current = cArray[i].ElevatedPosition;
            Vector3 next    = cArray[(i + 1) % cArray.Length].ElevatedPosition;

            norm.x += (current.y - next.y) * (current.z + next.z);
            norm.y += (current.z - next.z) * (current.x + next.x);
            norm.z += (current.x - next.x) * (current.y + next.y);
        }

        return(norm.normalized);
    }
Exemplo n.º 7
0
    private void SetCornerElevations()
    {
        Queue <IslandTileCorner> cornerQueue = new Queue <IslandTileCorner>();
        var islandCorners = GetCorners();

        foreach (IslandTileCorner c in islandCorners)
        {
            if (c.IsWater)
            {
                c.elevation = 0;
                cornerQueue.Enqueue(c);
            }
        }

        while (cornerQueue.Count > 0)
        {
            IslandTileCorner c = cornerQueue.Dequeue();

            foreach (IslandTileCorner ac in c.adjacent)
            {
                if (ac.elevation != Mathf.Infinity || ac.IsWater)
                {
                    continue;
                }

                float newElevation = c.elevation;

                float nLevel = islandNoise.GetValue((float)ac.position[0],
                                                    (float)ac.position[1],
                                                    0);

                newElevation += elevationStep * nLevel * scale;

                ac.inlandDistance = c.inlandDistance + 1;
                ac.elevation      = newElevation;

                cornerQueue.Enqueue(ac);
            }
        }
    }
Exemplo n.º 8
0
    private IslandTileCorner AddCorner (Vector v)
    {
        IslandTileCorner c;
        Dictionary<Vector, IslandTileCorner> cIdx = IslandTileCorner.Index;

        if (cIdx.ContainsKey(v)) { c = IslandTileCorner.Index[v]; }
        else                     { c = new IslandTileCorner(v);   }

        corners.Add(c);

        return c;
    }
Exemplo n.º 9
0
    private Vector3 CalcNormal ()
    {
        Vector3 norm = Vector3.zero;
        IslandTileCorner[] cArray = new IslandTileCorner[corners.Count];
        corners.CopyTo(cArray);

        for (int i = 0; i < cArray.Length; i++)
        {
            Vector3 current = cArray[i].ElevatedPosition;
            Vector3 next    = cArray[(i + 1) % cArray.Length].ElevatedPosition;

            norm.x += (current.y - next.y) * (current.z + next.z);
            norm.y += (current.z - next.z) * (current.x + next.x);
            norm.z += (current.x - next.x) * (current.y + next.y);
        }
        
        return norm.normalized;
    }
Exemplo n.º 10
0
    public static IslandTileCorner GetDownSlopeCorner(IslandTileCorner corner)
    {
        float lowestY = corner.ElevatedPosition.y;
        IslandTileCorner downCorner = corner; 

        foreach (IslandTileCorner c in corner.adjacent)
        {
            float cornerY = c.ElevatedPosition.y;
            if (cornerY < lowestY) 
            { 
                downCorner = c;
                lowestY    = cornerY; 
            }
        }

        return downCorner;
    }