12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #ifndef HIGHMAP_H
- #define HIGHMAP_H
- #include "common/utils/Types.h"
- #include "common/utils/Random.h"
- template<uint W, uint H>
- class HighMap {
- public:
- HighMap() {
- Random r(0);
- for(uint x = 0; x < W; x++) {
- for(uint y = 0; y < H; y++) {
- data[x][y] = r.nextFloat();
- }
- }
- smooth();
- smooth();
- smooth();
- smooth();
- }
- void smooth() {
- float oldNoice[W][H];
- for(uint x = 0; x < W; x++) {
- for(uint y = 0; y < H; y++) {
- oldNoice[x][y] = data[x][y];
- }
- }
- for(uint x = 0; x < W; x++) {
- for(uint y = 0; y < H; y++) {
- float sum = 0.0f;
- for(uint mx = 0; mx <= 2; mx++) {
- for(uint my = 0; my <= 2; my++) {
- sum += oldNoice[(x + mx - 1) % W][(y + my - 1) % H];
- }
- }
- data[x][y] = sum / 9.0f;
- }
- }
- }
- uint getHeight(uint x, uint y, uint max) const {
- return (uint) (data[x][y] * max);
- }
- private:
- float data[W][H];
- };
- #endif
|