fCraft.Noise.ApplyBias C# (CSharp) Method

ApplyBias() public static method

public static ApplyBias ( [ data, float c00, float c01, float c10, float c11, float midpoint ) : void
data [
c00 float
c01 float
c10 float
c11 float
midpoint float
return void
        public static void ApplyBias( [NotNull] float[,] data, float c00, float c01, float c10, float c11, float midpoint )
        {
            if ( data == null )
                throw new ArgumentNullException( "data" );
            float maxX = 2f / data.GetLength( 0 );
            float maxY = 2f / data.GetLength( 1 );
            int offsetX = data.GetLength( 0 ) / 2;
            int offsetY = data.GetLength( 1 ) / 2;

            for ( int x = offsetX - 1; x >= 0; x-- ) {
                for ( int y = offsetY - 1; y >= 0; y-- ) {
                    data[x, y] += InterpolateCosine( c00, ( c00 + c01 ) / 2, ( c00 + c10 ) / 2, midpoint, x * maxX, y * maxY );
                    data[x + offsetX, y] += InterpolateCosine( ( c00 + c10 ) / 2, midpoint, c10, ( c11 + c10 ) / 2, x * maxX, y * maxY );
                    data[x, y + offsetY] += InterpolateCosine( ( c00 + c01 ) / 2, c01, midpoint, ( c01 + c11 ) / 2, x * maxX, y * maxY );
                    data[x + offsetX, y + offsetY] += InterpolateCosine( midpoint, ( c01 + c11 ) / 2, ( c11 + c10 ) / 2, c11, x * maxX, y * maxY );
                }
            }
        }

Usage Example

Example #1
0
        private void ApplyBias()
        {
            // set corners and midpoint
            float[] corners = new float[4];
            int     c       = 0;

            for (int i = 0; i < args.RaisedCorners; i++)
            {
                corners[c++] = args.Bias;
            }
            for (int i = 0; i < args.LoweredCorners; i++)
            {
                corners[c++] = -args.Bias;
            }
            float midpoint = (args.MidPoint * args.Bias);

            // shuffle corners
            corners = corners.OrderBy(r => rand.Next()).ToArray();

            // overlay the bias
            Noise.ApplyBias(heightmap, corners[0], corners[1], corners[2], corners[3], midpoint);
        }