示例#1
0
        /// <summary>
        /// Fill a buffer with random noise
        /// </summary>
        public void NewMap(int size, float initialDensity, AnimationCurve spreadCurve)
        {
            //reset the swapchain if needed
            if (size != map)
            {
                map    = size;
                height = size;
            }
            map.Write((Coordinate c) => {
                float x = (((float)c.x / (float)size) - 0.5f) * 1.5f;
                float y = (((float)c.y / (float)size) - 0.5f) * 1.5f;
                return(Random.value < spreadCurve.Evaluate(Mathf.Sqrt((x * x) + (y * y))));
            });

            float rndPositionX = Random.Range(-50, 50);
            float rndPositionY = Random.Range(-50, 50);
            float rndDimention = 0.05f;

            height.Write((Coordinate c) => {
                return(Mathf.PerlinNoise(
                           ((float)c.x + rndPositionX) * rndDimention,
                           ((float)c.y + rndPositionY) * rndDimention));
            });
        }
 /// <summary>
 /// Build a swapchain from another swapchain (clone)
 /// </summary>
 /// <param name="previousSwapChain">the base swapchain for clonnage</param>
 public Swapchain(Swapchain <T> previousSwapChain)
 {
     writeBuffer = previousSwapChain.writeBuffer.Clone() as T[, ];
     readBuffer  = previousSwapChain.readBuffer.Clone() as T[, ];
 }