From f1fc192ddc4c739fa8b4b376c759b7d3218a34eb Mon Sep 17 00:00:00 2001 From: Mel Date: Fri, 7 Jul 2023 21:39:42 +0200 Subject: Chunk-bound tree decoration --- src/Math/Random.hpp | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/Math/Random.hpp (limited to 'src/Math/Random.hpp') diff --git a/src/Math/Random.hpp b/src/Math/Random.hpp new file mode 100644 index 0000000..ab94871 --- /dev/null +++ b/src/Math/Random.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include "array" +#include "Common.hpp" + +namespace Math::Random { + +std::array break_float(float f); +float to_float(uint8_t u); + +uint8_t hash(uint8_t x); + +float random(); + +template +struct Noise { + float at(Vector pos) const { + uint8_t to_hash[D * 4]; + for (int i = 0; i < D; i++) { + auto b = break_float(pos[i]); + to_hash[i*4] = b[0]; to_hash[i*4+1] = b[1]; to_hash[i*4+2] = b[2]; to_hash[i*4+3] = b[3]; + } + uint8_t h = 0; + for (int i = 0; i < D * 4; i++) { + h = hash(h) + to_hash[i]; + } + return to_float(h); + } +}; + +} \ No newline at end of file -- cgit 1.4.1