Exemplo n.º 1
0
    private void DrawLandMask(MapArray <int> bitmask)
    {
        int gbt_radius = (int)Mathf.Max(ChunkOrder, Mathf.Ceil(2.0f * Mathf.Log(1.0f + 1.00f * Radius) / Mathf.Log(7.0f))) - ChunkOrder + 1;

        int count  = 0;
        var chunks = new List <ChunkData>();

        for (int i = 0; i < Utils.Pow(7, gbt_radius); i++)
        {
            var chunk = new ChunkData(i, ChunkSize);
            for (int j = 0; j < ChunkSize; j++)
            {
                var   hex       = new GBTHex(i * ChunkSize + j);
                Color hex_color = Color.black;
                if ((bitmask[hex] & 1) > 0)
                {
                    count    += 1;
                    hex_color = Color.white;
                }
                chunk.AddColors(hex_color);
            }
            chunks.Add(chunk);
        }
        Debug.Log(count);
        m_DrawPolygonEvent.Invoke(chunks);
    }
Exemplo n.º 2
0
    private MapArray <int> GenerateLandMask(MapArray <int> bitmask)
    {
        var simplex = new Simplex2D(43);

        int gbt_radius = (int)Mathf.Max(ChunkOrder, Mathf.Ceil(2.0f * Mathf.Log(1.0f + 1.00f * Radius) / Mathf.Log(7.0f))) - ChunkOrder + 1;

        for (int i = 0; i < Utils.Pow(7, gbt_radius); i++)
        {
            for (int j = 0; j < ChunkSize; j++)
            {
                GBTHex  hex = new GBTHex(i * ChunkSize + j);
                Vector2 pos = hex.position;
                if (GetLandMaskValue(pos, simplex) > Threshold)
                {
                    bitmask[hex] |= 1;
                    foreach (GBTCorner corner in hex.GetCorners())
                    {
                        bitmask[corner] |= 1;
                    }
                }
                else
                {
                    bitmask[hex] |= 2;
                    foreach (GBTCorner corner in hex.GetCorners())
                    {
                        bitmask[corner] |= 2;
                    }
                }
            }
        }
        return(bitmask);
    }
Exemplo n.º 3
0
 public TValue this[GBTHex key] {
     get {
         return(GetValue(key));
     }
     set {
         SetValue(key, value);
     }
 }
Exemplo n.º 4
0
    public List <GBTCorner> GetAdjacent()
    {
        var result = new List <GBTCorner>();

        for (int i = 0; i < 3; i++)
        {
            GBTCorner corner  = _Adjacent[i + 3 * ((_value & Left) >> 29)];
            GBTHex    new_hex = new GBTHex(_value & HexMask) + new GBTHex(corner._value & HexMask);
            result.Add(new GBTCorner(new_hex, ((corner._value & Left) > 0 ? CornerDirection.L : CornerDirection.R)));
        }
        return(result);
    }
Exemplo n.º 5
0
 public override bool Equals(object obj)
 {
     if (obj == null || GetType() != obj.GetType())
     {
         return(false);
     }
     else
     {
         GBTHex b = (GBTHex)obj;
         return(this == b);
     }
 }
Exemplo n.º 6
0
    public TValue GetValue(GBTHex key)
    {
        TValue output;

        if (hex_data.TryGetValue(key, out output))
        {
            return(output);
        }
        else
        {
            return(default_value);
        }
    }
Exemplo n.º 7
0
    private void TriangulateHex(GBTHex hex, Color[] colors)
    {
        if (colors == null)
        {
            return;
        }
        Vector2 center  = hex.position;
        var     corners = hex.GetCorners();

        for (int i = 0; i < corners.Count; i++)
        {
            int       inext  = (i + 1) % 6;
            GBTCorner first  = corners[i];
            GBTCorner second = corners[inext];
            CreateTriangle(center, colors[0], second.position, colors[inext + 1], first.position, colors[i + 1]);
        }
    }
Exemplo n.º 8
0
    private void DrawGrayscaleArray(MapArray <float> array, MapArray <int> bitmask, float minimum, float maximum)
    {
        int gbt_radius = (int)Mathf.Max(ChunkOrder, Mathf.Ceil(2.0f * Mathf.Log(1.0f + 1.00f * Radius) / Mathf.Log(7.0f))) - ChunkOrder + 1;

        int count  = 0;
        var chunks = new List <ChunkData>();

        for (int i = 0; i < Utils.Pow(7, gbt_radius); i++)
        {
            var chunk = new ChunkData(i, ChunkSize);
            for (int j = 0; j < ChunkSize; j++)
            {
                var hex = new GBTHex(i * ChunkSize + j);
                if ((bitmask[hex] & 1) > 0)
                {
                    var   colors  = new Color[7];
                    var   corners = hex.GetCorners();
                    float average = 0.0f;
                    for (int k = 0; k < 6; k++)
                    {
                        colors[1 + k] = GetGrayscale((array[corners[k]] - minimum) / (maximum - minimum));
                        average      += array[corners[k]] / 6.0f;
                    }
                    colors[0] = GetGrayscale((average - minimum) / (maximum - minimum));
                    chunk.AddColors(colors);
                }
                else
                {
                    chunk.AddColors(null);
                }
            }
            chunks.Add(chunk);
        }
        Debug.Log(count);
        m_DrawPolygonEvent.Invoke(chunks);
    }
Exemplo n.º 9
0
 // Constructor
 public GBTCorner(GBTHex hex, CornerDirection direction)
 {
     // Value needs to be <= CornerMask.
     _value = hex.value | CornerMask | (direction > 0 ? Left : 0);
 }
Exemplo n.º 10
0
 public void SetValue(GBTHex key, TValue value)
 {
     hex_data[key] = value;
 }