added 3d simplex
This commit is contained in:
1 parent
1a873be361
commit
7d1a9e519b
2 files changed
+131
-20
No files matched your search
@@ -38,7 +38,7 @@ public class SimplexNoiseSampler extends PerlinNoiseSampler {
|
||||
return g;
|
||||
}
|
||||
|
||||
public double sample(double x, double y) {
|
||||
public double sample2d(double x, double y) {
|
||||
double d = (x + y) * SKEW_FACTOR_2D;
|
||||
int i = PerlinNoiseSampler.floor(x + d);
|
||||
int j = PerlinNoiseSampler.floor(y + d);
|
||||
@@ -73,6 +73,95 @@ public class SimplexNoiseSampler extends PerlinNoiseSampler {
|
||||
return 35.0D * (aa + ab + ac)+0.5;
|
||||
}
|
||||
|
||||
public double sample3d(double d, double e, double f) {
|
||||
double g = 0.3333333333333333D;
|
||||
double h = (d + e + f) * 0.3333333333333333D;
|
||||
int i = floor(d + h);
|
||||
int j = floor(e + h);
|
||||
int k = floor(f + h);
|
||||
double l = 0.16666666666666666D;
|
||||
double m = (double)(i + j + k) * 0.16666666666666666D;
|
||||
double n = (double)i - m;
|
||||
double o = (double)j - m;
|
||||
double p = (double)k - m;
|
||||
double q = d - n;
|
||||
double r = e - o;
|
||||
double s = f - p;
|
||||
byte z;
|
||||
byte aa;
|
||||
byte ab;
|
||||
byte ac;
|
||||
byte ad;
|
||||
byte bc;
|
||||
if (q >= r) {
|
||||
if (r >= s) {
|
||||
z = 1;
|
||||
aa = 0;
|
||||
ab = 0;
|
||||
ac = 1;
|
||||
ad = 1;
|
||||
bc = 0;
|
||||
} else if (q >= s) {
|
||||
z = 1;
|
||||
aa = 0;
|
||||
ab = 0;
|
||||
ac = 1;
|
||||
ad = 0;
|
||||
bc = 1;
|
||||
} else {
|
||||
z = 0;
|
||||
aa = 0;
|
||||
ab = 1;
|
||||
ac = 1;
|
||||
ad = 0;
|
||||
bc = 1;
|
||||
}
|
||||
} else if (r < s) {
|
||||
z = 0;
|
||||
aa = 0;
|
||||
ab = 1;
|
||||
ac = 0;
|
||||
ad = 1;
|
||||
bc = 1;
|
||||
} else if (q < s) {
|
||||
z = 0;
|
||||
aa = 1;
|
||||
ab = 0;
|
||||
ac = 0;
|
||||
ad = 1;
|
||||
bc = 1;
|
||||
} else {
|
||||
z = 0;
|
||||
aa = 1;
|
||||
ab = 0;
|
||||
ac = 1;
|
||||
ad = 1;
|
||||
bc = 0;
|
||||
}
|
||||
|
||||
double bd = q - (double)z + 0.16666666666666666D;
|
||||
double be = r - (double)aa + 0.16666666666666666D;
|
||||
double bf = s - (double)ab + 0.16666666666666666D;
|
||||
double bg = q - (double)ac + 0.3333333333333333D;
|
||||
double bh = r - (double)ad + 0.3333333333333333D;
|
||||
double bi = s - (double)bc + 0.3333333333333333D;
|
||||
double bj = q - 1.0D + 0.5D;
|
||||
double bk = r - 1.0D + 0.5D;
|
||||
double bl = s - 1.0D + 0.5D;
|
||||
int bm = i & 255;
|
||||
int bn = j & 255;
|
||||
int bo = k & 255;
|
||||
int bp = this.getGradient(bm + this.getGradient(bn + this.getGradient(bo))) % 12;
|
||||
int bq = this.getGradient(bm + z + this.getGradient(bn + aa + this.getGradient(bo + ab))) % 12;
|
||||
int br = this.getGradient(bm + ac + this.getGradient(bn + ad + this.getGradient(bo + bc))) % 12;
|
||||
int bs = this.getGradient(bm + 1 + this.getGradient(bn + 1 + this.getGradient(bo + 1))) % 12;
|
||||
double bt = this.grad(bp, q, r, s, 0.6D);
|
||||
double bu = this.grad(bq, bd, be, bf, 0.6D);
|
||||
double bv = this.grad(br, bg, bh, bi, 0.6D);
|
||||
double bw = this.grad(bs, bj, bk, bl, 0.6D);
|
||||
return 16.0D * (bt + bu + bv + bw) + 0.5;
|
||||
}
|
||||
|
||||
static {
|
||||
SKEW_FACTOR_2D = 0.5D * (sqrt3 - 1.0D);
|
||||
UNSKEW_FACTOR_2D = (3.0D - sqrt3) / 6.0D;
|
||||
|
||||
Reference in new issue
Block a user