-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperlinCommon.h
37 lines (33 loc) · 1.21 KB
/
perlinCommon.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#ifndef TERRAINGENCPP_PERLINCOMMON_H
#define TERRAINGENCPP_PERLINCOMMON_H
#include "javaRnd.h"
struct PermutationTable {
double xo;
double yo;
double zo; // this actually never used in fixed noise aka 2d noise;)
uint8_t permutations[512];
};
static inline void initOctaves(PermutationTable octaves[], Random *random, int nbOctaves) {
for (int i = 0; i < nbOctaves; ++i) {
octaves[i].xo = next_double(random) * 256.0;
octaves[i].yo = next_double(random) * 256.0;
octaves[i].zo = next_double(random) * 256.0;
uint8_t *permutations = octaves[i].permutations;
uint8_t j=0;
do{
permutations[j] = j;
}while(j++!=255);
uint8_t index = 0;
do {
uint32_t randomIndex = random_next_int(random, 256u - index) + index;
if (randomIndex != index) {
// swap
permutations[index] ^= permutations[randomIndex];
permutations[randomIndex] ^= permutations[index];
permutations[index] ^= permutations[randomIndex];
}
permutations[index + 256] = permutations[index];
}while(index++!=255);
}
}
#endif //TERRAINGENCPP_PERLINCOMMON_H