Here you can find the source of interpolatedNoise(int x, int z, int reciprocal)
Parameter | Description |
---|---|
x | The x coordinate. |
z | The z coordinate. |
reciprocal | The frequency reciprocal. |
private static int interpolatedNoise(int x, int z, int reciprocal)
//package com.java2s; public class Main { /**/*from ww w. j a va 2s . c om*/ * The cosine table used for interpolation. */ private static final int[] COSINE = new int[2048]; /** * Gets interpolated noise for the specified coordinate pair, using the specified frequency reciprocal. * * @param x The x coordinate. * @param z The z coordinate. * @param reciprocal The frequency reciprocal. * @return The interpolated noise. */ private static int interpolatedNoise(int x, int z, int reciprocal) { int xt = x % reciprocal; int zt = z % reciprocal; x /= reciprocal; z /= reciprocal; int c = smoothNoise(x, z); int e = smoothNoise(x + 1, z); int ce = interpolate(c, e, xt, reciprocal); int n = smoothNoise(x, z + 1); int ne = smoothNoise(x + 1, z + 1); int u = interpolate(n, ne, xt, reciprocal); return interpolate(ce, u, zt, reciprocal); } /** * Computes smooth noise for the specified coordinate pair. * * @param x The x coordinate. * @param z The z coordinate. * @return The smooth noise. */ private static int smoothNoise(int x, int z) { int corners = noise(x - 1, z - 1) + noise(x + 1, z - 1) + noise(x - 1, z + 1) + noise(x + 1, z + 1); int sides = noise(x - 1, z) + noise(x + 1, z) + noise(x, z - 1) + noise(x, z + 1); int center = noise(x, z); return corners / 16 + sides / 8 + center / 4; } /** * Interpolates two smooth noise values. * * @param a The first smooth noise value. * @param b The second smooth noise value. * @param theta The angle. * @param reciprocal The frequency reciprocal. * @return The interpolated value. */ private static int interpolate(int a, int b, int theta, int reciprocal) { int cosine = 65536 - COSINE[theta * COSINE.length / (2 * reciprocal)] / 2; return (a * (65536 - cosine)) / 65536 + (b * cosine) / 65536; } /** * Computes noise for the specified coordinate pair. * * @param x The x coordinate. * @param z The z coordinate. * @return The noise. */ private static int noise(int x, int z) { int n = x + z * 57; n = (n << 13) ^ n; n = (n * (n * n * 15731 + 789221) + 1376312589) & Integer.MAX_VALUE; return (n >> 19) & 0xff; } }