-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRND.h
More file actions
45 lines (38 loc) · 980 Bytes
/
RND.h
File metadata and controls
45 lines (38 loc) · 980 Bytes
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
38
39
40
41
42
43
44
45
#pragma once
#include <stdint.h>
uint32_t
Noise1D(int position, uint32_t seed = 0)
{
constexpr unsigned int BIT_NOISE1 = 0xB5297A4D;
constexpr unsigned int BIT_NOISE2 = 0x68E31DA4;
constexpr unsigned int BIT_NOISE3 = 0x1B56C4E9;
unsigned int mangled = position;
mangled *= BIT_NOISE1;
mangled += seed;
mangled ^= (mangled >> 8);
mangled += BIT_NOISE2;
mangled ^= (mangled << 8);
mangled *= BIT_NOISE2;
mangled ^= (mangled >> 8);
return mangled;
}
inline uint32_t
Noise2D(int posX, int posY, uint32_t seed = 0)
{
constexpr int PRIME_NUMBER = 198491317;
return Noise1D(posX + (PRIME_NUMBER * posY), seed);
}
inline uint32_t
Noise3D(int posX, int posY, int posZ, uint32_t seed = 0)
{
constexpr int PRIME_NUMBER1 = 198491317;
constexpr int PRIME_NUMBER2 = 6542989;
return Noise1D(posX + (PRIME_NUMBER1 * posY)
+ (PRIME_NUMBER2 * posZ), seed);
}
uint32_t
Rand()
{
constexpr int PRIME_NUMBER = 198491317;
return Noise1D(PRIME_NUMBER);
}