| 50 | } |
| 51 | |
| 52 | double PerlinNoise::GetValue(double x, double y) const |
| 53 | { |
| 54 | int Xint = (int)x; |
| 55 | int Yint = (int)y; |
| 56 | double Xfrac = x - Xint; |
| 57 | double Yfrac = y - Yint; |
| 58 | |
| 59 | //noise values |
| 60 | double n01 = Noise(Xint-1, Yint-1); |
| 61 | double n02 = Noise(Xint+1, Yint-1); |
| 62 | double n03 = Noise(Xint-1, Yint+1); |
| 63 | double n04 = Noise(Xint+1, Yint+1); |
| 64 | double n05 = Noise(Xint-1, Yint); |
| 65 | double n06 = Noise(Xint+1, Yint); |
| 66 | double n07 = Noise(Xint, Yint-1); |
| 67 | double n08 = Noise(Xint, Yint+1); |
| 68 | double n09 = Noise(Xint, Yint); |
| 69 | |
| 70 | double n12 = Noise(Xint+2, Yint-1); |
| 71 | double n14 = Noise(Xint+2, Yint+1); |
| 72 | double n16 = Noise(Xint+2, Yint); |
| 73 | |
| 74 | double n23 = Noise(Xint-1, Yint+2); |
| 75 | double n24 = Noise(Xint+1, Yint+2); |
| 76 | double n28 = Noise(Xint, Yint+2); |
| 77 | |
| 78 | double n34 = Noise(Xint+2, Yint+2); |
| 79 | |
| 80 | //find the noise values of the four corners |
| 81 | double x0y0 = 0.0625*(n01+n02+n03+n04) + 0.125*(n05+n06+n07+n08) + 0.25*(n09); |
| 82 | double x1y0 = 0.0625*(n07+n12+n08+n14) + 0.125*(n09+n16+n02+n04) + 0.25*(n06); |
| 83 | double x0y1 = 0.0625*(n05+n06+n23+n24) + 0.125*(n03+n04+n09+n28) + 0.25*(n08); |
| 84 | double x1y1 = 0.0625*(n09+n16+n28+n34) + 0.125*(n08+n14+n06+n24) + 0.25*(n04); |
| 85 | |
| 86 | //interpolate between those values according to the x and y fractions |
| 87 | double v1 = Interpolate(x0y0, x1y0, Xfrac); //interpolate in x direction (y) |
| 88 | double v2 = Interpolate(x0y1, x1y1, Xfrac); //interpolate in x direction (y+1) |
| 89 | double fin = Interpolate(v1, v2, Yfrac); //interpolate in y direction |
| 90 | |
| 91 | return fin; |
| 92 | } |
| 93 | |
| 94 | double PerlinNoise::Interpolate(double x, double y, double a) const |
| 95 | { |
nothing calls this directly
no outgoing calls
no test coverage detected