Ejemplo n.º 1
0
float CPerlinNoise::interpolate_noise(float x, float y) const
{
	static int integer_X;
	static int integer_Y;
	static float fractional_X;
	static float fractional_Y;
	static float v1, v2, v3, v4, i1, i2;

	// separate integer & decimal x
	integer_X = (int) x;
	fractional_X = x - integer_X;

	// separate integer & decimal y
	integer_Y = (int) y;
	fractional_Y = y - integer_Y;

	// get 4 corners
	v1 = smooth_noise(integer_X,     integer_Y);
	v2 = smooth_noise(integer_X + 1, integer_Y);
	v3 = smooth_noise(integer_X,     integer_Y + 1);
	v4 = smooth_noise(integer_X + 1, integer_Y + 1);

	// interpolate 4 corners
	i1 = m_Interpolation(v1, v2, fractional_X);
	i2 = m_Interpolation(v3, v4, fractional_X);

	// interpolate 2 points
	return m_Interpolation(i1, i2 ,fractional_Y);
}
Ejemplo n.º 2
0
float noise_handler(float x, float y) {
    int int_val[2];
    float frac_val[2];
    float value[4];
    float res[2];

    int_val[0] = (int)x;
    int_val[1] = (int)y;
    frac_val[0] = x - int_val[0];
    frac_val[1] = y - int_val[1];
    value[0] = smooth_noise(int_val[0], int_val[1]);
    value[1] = smooth_noise(int_val[0] + 1, int_val[1]);
    value[2] = smooth_noise(int_val[0], int_val[1] + 1);
    value[3] = smooth_noise(int_val[0] + 1, int_val[1] + 1);
    res[0] = interpolate(value[0], value[1], frac_val[0]);
    res[1] = interpolate(value[2], value[3], frac_val[0]);
    return (interpolate(res[0], res[1], frac_val[1]));
}
Ejemplo n.º 3
0
double			ft_perlin(double x, double y, double z)
{
	double		result;
	double		f;
	double		amplitude;
	int			i;
	int			t;

	result = 0;
	f = FREQUENCY;
	amplitude = 1;
	i = -1;
	while (++i < OCTAVES)
	{
		t = i * 4096;
		result += smooth_noise(x * f + t, y * f + t, z * f + t) * amplitude;
		amplitude *= PERSISTANCE;
		f *= 2;
	}
	result *= (1 - PERSISTANCE) / (1 - amplitude);
	return (result);
}