mirror of
https://github.com/projectM-visualizer/projectm.git
synced 2026-03-11 09:55:23 +00:00
just in case
git-svn-id: https://projectm.svn.sourceforge.net/svnroot/projectm/trunk@1087 6778bc44-b910-0410-a7a0-be141de4315d
This commit is contained in:
@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#include "PerlinNoise.hpp"
|
||||
#include <iostream>
|
||||
|
||||
PerlinNoise::PerlinNoise()
|
||||
{
|
||||
@ -17,9 +18,27 @@ PerlinNoise::PerlinNoise()
|
||||
for (int y = 0; y < 32;y++)
|
||||
noise_lq_lite[x][y] = Noise(x,y);
|
||||
|
||||
int scale = 4;
|
||||
int width = 12413;
|
||||
int seed = 61;
|
||||
|
||||
for (int x = 0; x < 256;x++)
|
||||
for (int y = 0; y < 256;y++)
|
||||
noise_hq[x][y] = perlin_noise_2D(x,y,5,1.414);
|
||||
{
|
||||
|
||||
float disp1= perlin_noise(x*scale,y*scale,width,1,seed,100);
|
||||
float disp2= perlin_noise(x*scale,y*scale,width,1,seed,25);
|
||||
float disp3= perlin_noise(x*scale,y*scale,width,1,seed,12.5);
|
||||
float disp4= perlin_noise(x*scale,y*scale,width,1,seed,6.25);
|
||||
float disp5= perlin_noise(x*scale,y*scale,width,1,seed,3.125);
|
||||
float disp6= perlin_noise(x*scale,y*scale,width,1,seed,1.56);
|
||||
|
||||
noise_hq[x][y] = disp1+(disp2*.25)+(disp3*.125)+(disp4*.0625)+(disp5*.03125)+(disp6*.0156);
|
||||
|
||||
|
||||
//noise_hq[x][y] = perlin_noise_2D(x,y,5,0.5);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
PerlinNoise::~PerlinNoise()
|
||||
|
||||
@ -27,7 +27,15 @@ public:
|
||||
|
||||
private:
|
||||
|
||||
static inline int Noise(int x, int y)
|
||||
|
||||
static inline float Noise(int x)
|
||||
{
|
||||
int n = (x<<13) ^ x;
|
||||
return ( 1.0 - ( (n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0);
|
||||
|
||||
}
|
||||
|
||||
static inline float Noise(int x, int y)
|
||||
{
|
||||
int n = x + y * 57;
|
||||
n = (n<<13) ^ n;
|
||||
@ -63,10 +71,10 @@ private:
|
||||
|
||||
static inline float InterpolatedNoise(float x, float y)
|
||||
{
|
||||
int integer_X = int(x);
|
||||
int integer_X = int(x);
|
||||
float fractional_X = x - integer_X;
|
||||
|
||||
int integer_Y = int(y);
|
||||
int integer_Y = int(y);
|
||||
float fractional_Y = y - integer_Y;
|
||||
|
||||
float v1 = SmoothedNoise(integer_X, integer_Y);
|
||||
@ -85,18 +93,51 @@ private:
|
||||
{
|
||||
float total = 0;
|
||||
|
||||
for (int i = 0; i <= n; i++)
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
float frequency = pow(2,i);
|
||||
float amplitude = pow(p,i);
|
||||
|
||||
total = total + InterpolatedNoise(x * frequency, y * frequency) * amplitude;
|
||||
total += InterpolatedNoise(x * frequency, y * frequency) * amplitude;
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
|
||||
static inline float InterPolation(float a, float b, float c)
|
||||
{
|
||||
return a+(b-a)*c*c*(3-2*c);
|
||||
|
||||
}
|
||||
|
||||
static inline float perlin_noise(float x,float y, int width, int octaves, int seed, float periode){
|
||||
|
||||
float a,b,value,freq,tam_pas,zone_x,zone_y;
|
||||
int s,box,num,step_x,step_y;
|
||||
int amplitude=1;
|
||||
int noisedata;
|
||||
|
||||
freq=1/(float)(periode);
|
||||
|
||||
for ( s=0;s<octaves;s++)
|
||||
{
|
||||
num=(int)(width*freq);
|
||||
step_x=(int)(x*freq);
|
||||
step_y=(int)(y*freq);
|
||||
zone_x=x*freq-step_x;
|
||||
zone_y=y*freq-step_y;
|
||||
box=step_x+step_y*num;
|
||||
noisedata=(box+seed);
|
||||
a=InterPolation(Noise(noisedata),Noise(noisedata+1),zone_x);
|
||||
b=InterPolation(Noise(noisedata+num),Noise(noisedata+1+num),zone_x);
|
||||
value=InterPolation(a,b,zone_y)*amplitude;
|
||||
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user