Beispiel #1
0
/**
 * Hj. Malthaner's routine included 2 different noise smoothing methods.
 * We now use the "raw" int_noise one.
 * However, it may be useful to move to the other routine in future.
 * So it is included too.
 */
static double smoothed_noise(const int x, const int y, const int prime)
{
#if 0
	/* A hilly world (four corner smooth) */
	const double sides = int_noise(x - 1, y) + int_noise(x + 1, y) + int_noise(x, y - 1) + int_noise(x, y + 1);
	const double center  =  int_noise(x, y);
	return (sides + sides + center * 4) / 8.0;
#endif

	/* This gives very hilly world */
	return int_noise(x, y, prime);
}
Beispiel #2
0
/**
 * This routine returns the smoothed interpolated noise for an x and y, using
 * the values from the surrounding positions.
 */
static double interpolated_noise(const double x, const double y, const int prime)
{
	const int integer_X = (int)x;
	const int integer_Y = (int)y;

	const double fractional_X = x - (double)integer_X;
	const double fractional_Y = y - (double)integer_Y;

	const double v1 = int_noise(integer_X,     integer_Y,     prime);
	const double v2 = int_noise(integer_X + 1, integer_Y,     prime);
	const double v3 = int_noise(integer_X,     integer_Y + 1, prime);
	const double v4 = int_noise(integer_X + 1, integer_Y + 1, prime);

	const double i1 = linear_interpolate(v1, v2, fractional_X);
	const double i2 = linear_interpolate(v3, v4, fractional_X);

	return linear_interpolate(i1, i2, fractional_Y);
}