Esempio n. 1
0
        /// <summary>
        /// Fills the heightmap with values generated from given function.
        /// </summary>
        public void Generate(HeightFunc func)
        {
            int i = 0;

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    data[i++] = calculate(func, x, y);
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Calculates single height value for specified function and coordinates.
        /// </summary>
        float calculate(HeightFunc func, int x, int y)
        {
            float xu = x - Width / 2.0f;
            float yu = y - Height / 2.0f;

            switch (func)
            {
            case HeightFunc.EggBox:
            {
                double r = 4.0f * Math.Sqrt((double)(xu * xu + yu * yu)) / scale;
                double z = Math.Exp(-r * 2) * (Math.Cos(0.2f * xu) + Math.Cos(0.2f * yu));
                float  o = (float)(0.32f + 0.25f * z);
                return(o);
            }

            case HeightFunc.MoreSine:
            {
                double xf = 0.3f * xu / scale;
                double yf = 12.0f * yu / scale;
                double z  = Math.Sin(xf * xf + yf) * Math.Sin(xf + yf * yf);
                float  o  = (float)(0.25f + 0.25f * z);
                return(o);
            }

            case HeightFunc.JustExp:
            {
                float xf = 6 * xu / scale;
                float yf = 6 * yu / scale;
                float z  = xf * xf + yf * yf;
                float o  = (float)(0.3f * z * Math.Cos(xf * yf));
                return(o);
            }

            default:
                throw new ArgumentException("Unexpected height function value: " + func.ToString());
            }
        }
Esempio n. 3
0
		/// <summary>
		/// Calculates single height value for specified function and coordinates.
		/// </summary>
		float calculate(HeightFunc func, int x, int y)
		{
			float xu = x - Width / 2.0f;
			float yu = y - Height / 2.0f;

			switch (func)
			{
				case HeightFunc.EggBox:
					{
						double r = 4.0f * Math.Sqrt((double)(xu * xu + yu * yu)) / scale;
						double z = Math.Exp(-r * 2) * (Math.Cos(0.2f * xu) + Math.Cos(0.2f * yu));
						float o = (float)(0.32f + 0.25f * z);
						return o;
					}

				case HeightFunc.MoreSine:
					{
						double xf = 0.3f * xu / scale;
						double yf = 12.0f * yu / scale;
						double z = Math.Sin(xf * xf + yf) * Math.Sin(xf + yf * yf);
						float o = (float)(0.25f + 0.25f * z);
						return o;
					}

				case HeightFunc.JustExp:
					{
						float xf = 6 * xu / scale;
						float yf = 6 * yu / scale;
						float z = xf * xf + yf * yf;
						float o = (float)(0.3f * z * Math.Cos(xf * yf));
						return o;
					}

				default:
					throw new ArgumentException("Unexpected height function value: " + func.ToString());
			}
		}
Esempio n. 4
0
		/// <summary>
		/// Fills the heightmap with values generated from given function.
		/// </summary>
		public void Generate(HeightFunc func)
		{
			int i = 0;
			for (int y = 0; y < Height; y++)
				for (int x = 0; x < Width; x++)
					data[i++] = calculate(func, x, y);
		}