| 245 | } |
| 246 | } |
| 247 | void createRadialMask(std::vector<std::vector<float>>& pNoise) { |
| 248 | float centerX = (float) pNoise.size() / 2; |
| 249 | float centerY = (float) pNoise[0].size() / 2; |
| 250 | |
| 251 | float furthestDistance = (float)sqrt((centerX * centerX) + (centerY * centerY)); |
| 252 | |
| 253 | for (size_t i = 0; i < pNoise.size(); i++) { |
| 254 | for (size_t j = 0; j < pNoise[i].size(); j++) { |
| 255 | |
| 256 | //Simple squaring, you can use whatever math libraries are available to you to make this more readable |
| 257 | //The cool thing about squaring is that it will always give you a positive distance! (-10 * -10 = 100) |
| 258 | float distanceX = (centerX - i) * (centerX - i); |
| 259 | float distanceY = (centerY - j) * (centerY - j); |
| 260 | |
| 261 | float distanceToCenter = (float)sqrt(distanceX + distanceY); |
| 262 | |
| 263 | //Make sure this value ends up as a float and not an integer |
| 264 | //If you're not outputting this to an image, get the correct 1.0 white on the furthest edges by dividing by half the map size, in this case 64. You will get higher than 1.0 values, so clamp them! |
| 265 | distanceToCenter = distanceToCenter / furthestDistance; |
| 266 | |
| 267 | pNoise[i][j] *= (1 - distanceToCenter); |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | std::vector<std::vector<float>> CreateArray( size_t pWidth, size_t pHeight, size_t pOctaves, float pRoughness, float pScale, short pSeed, bool pRadialEnabled, float pEdgeFade) { |
| 273 | |