Esempio n. 1
0
        public static void CreateTorrents(Matrix heights, Matrix2D <int> order, Matrix torrents)
        {
            CoordRect rect = heights.rect;

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


                MooreCross height  = new MooreCross(heights.arr, pos, rect.size.x);
                MooreCross torrent = new MooreCross(torrents.arr, pos, rect.size.x);                                 //moore
                if (torrent.vals[4] > 200000000)
                {
                    torrent.vals[4] = 200000000;
                }

                MooreCross delta = height.vals[4] - height;
                delta = MooreCross.ClampMax(delta, 0);

                MooreCross percents = MooreCross.Zero();
                float      sum      = delta.Sum();
                if (sum > 0.00001f)
                {
                    percents = delta / sum;
                }

                MooreCross newTorrent = percents * torrent.vals[4];
                newTorrent.AddToMatrix(torrents.arr, pos, rect.size.x);
            }
        }
Esempio n. 2
0
        public static void CreateTorrentsRef(float[] heights, int[] order, float[] torrents, CoordRect rect = new CoordRect())
        {
            for (int i = 0; i < heights.Length; i++)
            {
                torrents[i] = 1;                                                              //casting initial rain
            }
            for (int j = heights.Length - 1; j >= 0; j--)
            {
                //finding column ordered by height
                int pos = order[j];
                if (pos < 0)
                {
                    continue;
                }


                MooreCross height  = new MooreCross(heights, pos, rect.size.x);
                MooreCross torrent = new MooreCross(torrents, pos, rect.size.x);                                 //moore
                if (torrent.vals[4] > 200000000)
                {
                    torrent.vals[4] = 200000000;
                }

                MooreCross delta = height.vals[4] - height;
                delta = MooreCross.ClampMax(delta, 0);

                MooreCross percents = MooreCross.Zero();
                float      sum      = delta.Sum();
                if (sum > 0.00001f)
                {
                    percents = delta / sum;
                }

                MooreCross newTorrent = percents * torrent.vals[4];
                newTorrent.AddToMatrix(torrents, pos, rect.size.x);
            }
        }