Пример #1
0
    List <IndexedWeight> GetDepositionWeights(int HeightMapSize, Vector2 Pos)
    {
        int top  = Mathf.FloorToInt(Pos.x);
        int left = Mathf.FloorToInt(Pos.y);

        List <IndexedWeight> PointWeights = new List <IndexedWeight>();
        float WeightSum = 0;

        for (int i = top; i < top + 1; i++)
        {
            for (int n = left; n < left + 1; n++)
            {
                float dist = (new Vector2(i, n) - Pos).magnitude;
                {
                    IndexedWeight IW = new IndexedWeight();
                    IW.Index   = i * HeightMapSize + n;
                    IW.weight  = 2.0f - dist;
                    WeightSum += IW.weight;
                    PointWeights.Add(IW);
                }
            }
        }

        for (int i = 0; i < PointWeights.Count; i++)
        {
            float         Normalizedweight = PointWeights[i].weight / WeightSum;
            IndexedWeight IW = new IndexedWeight();
            IW.Index        = PointWeights[i].Index;
            IW.weight       = Normalizedweight;
            PointWeights[i] = IW;
        }

        return(PointWeights);
    }
Пример #2
0
    List <IndexedWeight> GetErosiondWeights(int HeightMapSize, Vector2 Pos, float P_eradius)
    {
        int top  = Mathf.FloorToInt(Pos.x - (P_eradius - 1));
        int left = Mathf.FloorToInt(Pos.y - (P_eradius - 1));

        List <IndexedWeight> PointWeights = new List <IndexedWeight>();
        float WeightSum = 0;

        for (int i = top; i < top + P_eradius * 2; i++)
        {
            for (int n = left; n < left + P_eradius * 2; n++)
            {
                float dist = (new Vector2(i, n) - Pos).magnitude;
                if (dist < P_eradius)
                {
                    IndexedWeight IW = new IndexedWeight();
                    IW.Index   = i * HeightMapSize + n;
                    IW.weight  = P_eradius - dist;
                    WeightSum += IW.weight;
                    PointWeights.Add(IW);
                }
            }
        }

        for (int i = 0; i < PointWeights.Count; i++)
        {
            float         Normalizedweight = PointWeights[i].weight / WeightSum;
            IndexedWeight IW = new IndexedWeight();
            IW.Index        = PointWeights[i].Index;
            IW.weight       = Normalizedweight;
            PointWeights[i] = IW;
        }

        return(PointWeights);
    }