示例#1
0
文件: Erosion.cs 项目: AJ213/Awitu
        public static void TransferMudflow(Matrix heights, Matrix mudflow, Matrix sediments, Matrix2D <int> order, int erosionFluidityIterations = 3)
        {
            CoordRect rect = heights.rect;

            for (int i = 0; i < sediments.count; i++)
            {
                sediments.arr[i] = 0;
            }

            #region Settling sediment

            for (int l = 0; l < erosionFluidityIterations; l++)
            {
                for (int j = heights.count - 1; j >= 0; j--)
                {
                    //finding column ordered by height
                    int pos = order.arr[j];
                    if (pos < 0)
                    {
                        continue;
                    }

                    Cross height   = new Cross(heights.arr, pos, rect.size.x);
                    Cross sediment = new Cross(mudflow.arr, pos, rect.size.x);

                    float sedimentSum = sediment.Sum();
                    if (sedimentSum < 0.00001f)
                    {
                        continue;
                    }

                    Cross pour = Cross.Pour(height, sedimentSum);

                    pour.SetToMatrix(mudflow.arr, pos, rect.size.x);
                    if (sediments != null)
                    {
                        pour.AddToMatrix(sediments.arr, pos, rect.size.x);
                    }
                }
            }

            //for (int i=0; i<heights.Length; i++)
            //	if (float.IsNaN(heights[i])) Debug.Log("NaN");

            #endregion
        }
示例#2
0
        public static void FillDirs(Matrix2D <Coord> dirs, Coord to, MatrixWorld heights, Matrix mask, Factors factors,
                                    Matrix weights    = null, FixedList <int> changedPoses = null, FixedList <int> newChangedPoses = null,
                                    int maxIterations = -1)
        /// Using Dijkstra to calculate directions matrix
        /// Re-writing weights, dirs and changedposes
        /// Returns null if path could not be found (in manhattan dist * 2 cells)
        {
            CoordRect rect = heights != null ? heights.rect : mask.rect;
            Coord     rectMin = rect.offset; Coord rectMax = rect.offset + rect.size;

            if (weights == null)
            {
                weights = new Matrix(rect);
            }
            if (dirs == null)
            {
                dirs = new Matrix2D <Coord>(rect);
            }

            if (changedPoses == null)
            {
                changedPoses = new FixedList <int>(capacity: 10000);
            }
            if (newChangedPoses == null)
            {
                newChangedPoses = new FixedList <int>(capacity: 10000);
            }

            weights.Fill(float.MaxValue);             //clearing arrays (migh be used for previous pathfinding)
            weights[to] = 0;

            dirs.Fill(new Coord());

            changedPoses.arr[0] = rect.GetPos(to);
            changedPoses.count  = 1;

            if (maxIterations < 0)
            {
                maxIterations = rect.size.x + rect.size.z;
            }
            Coord min = rect.Min; Coord max = rect.Max;

            for (int i = 0; i < maxIterations; i++)
            {
                for (int c = 0; c < changedPoses.count; c++)
                {
                    int   pos   = changedPoses.arr[c];
                    Coord coord = rect.GetCoord(pos);

                    if (coord.x < rectMin.x || coord.x > rectMax.x - 1 ||
                        coord.z < rectMin.z || coord.z > rectMax.z - 1)
                    {
                        return;
                    }

                    float weight = weights.arr[pos];

                    for (int d = 0; d < 8; d++)
                    {
                        Coord nCoord = neigDiagonalFirst[d];

                        if ((coord.x == rectMin.x && nCoord.x == -1) || (coord.x == rectMax.x - 1 && nCoord.x == 1) ||
                            (coord.z == rectMin.z && nCoord.z == -1) || (coord.z == rectMax.z - 1 && nCoord.z == 1))
                        {
                            continue;
                        }

                        int nPos = pos + rect.size.x * nCoord.z + nCoord.x;

                        float nWeight    = weights.arr[nPos];
                        float nNewWeight = CalcWeight(coord, nCoord, heights, mask, factors) + weight;

                        if (nNewWeight < nWeight - 0.0001f)                        //using an epsilon delta to avoid overwriting nearly equal values
                        {
                            weights.arr[nPos] = nNewWeight;
                            dirs.arr[nPos]    = nCoord;

                            newChangedPoses.arr[newChangedPoses.count] = nPos;
                            newChangedPoses.count++;
                        }
                    }
                }

                FixedList <int> tempList = changedPoses;
                changedPoses          = newChangedPoses;
                newChangedPoses       = tempList;
                newChangedPoses.count = 0;
            }
        }
示例#3
0
文件: Erosion.cs 项目: AJ213/Awitu
 public MatrixInt(Matrix2D <int> src)
 {
     rect = src.rect; count = src.count; pos = src.pos; arr = src.arr;
 }
示例#4
0
文件: Erosion.cs 项目: AJ213/Awitu
 public static void TransferSettleMudflow(Matrix heights, Matrix mudflow, Matrix sediments, Matrix2D <int> order, int erosionFluidityIterations = 3)
 {
     TransferMudflow(heights, mudflow, sediments, order, erosionFluidityIterations);
     SettleMudflow(heights, mudflow, order, ruffle: 1f);
 }
示例#5
0
 public static extern void TransferSettleMudflow(Matrix heights, Matrix mudflow, Matrix sediments, Matrix2D <int> order, int erosionFluidityIterations = 3);
示例#6
0
 public static extern void Erode(Matrix heights, Matrix torrents, Matrix mudflow, Matrix2D <int> order,
                                 float erosionDurability = 0.9f, float erosionAmount = 1, float sedimentAmount = 0.5f);
示例#7
0
 public static extern void CreateTorrents(Matrix heights, Matrix2D <int> order, Matrix torrents);
示例#8
0
 public static extern void MaskBorders(Matrix2D <int> order);
示例#9
0
 public static extern void SetOrder(Matrix refm, Matrix2D <int> order);