From 52732d71e72b02ff45e25f44e414f87ec9ab7666 Mon Sep 17 00:00:00 2001 From: Mel Date: Thu, 29 Jun 2023 22:15:32 +0200 Subject: Pretty terrain generation --- src/Math/Common.hpp | 3 ++- src/Math/Constants.hpp | 8 ++++++++ src/Math/Perlin.hpp | 3 ++- src/Math/Sigmoid.hpp | 13 +++++++++++++ src/Math/Trig.hpp | 4 ++-- 5 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 src/Math/Constants.hpp create mode 100644 src/Math/Sigmoid.hpp (limited to 'src/Math') diff --git a/src/Math/Common.hpp b/src/Math/Common.hpp index 94840b1..1ea75f2 100644 --- a/src/Math/Common.hpp +++ b/src/Math/Common.hpp @@ -3,4 +3,5 @@ #include "Vector.hpp" #include "Matrix.hpp" #include "Rotation.hpp" -#include "Trig.hpp" \ No newline at end of file +#include "Trig.hpp" +#include "Constants.hpp" \ No newline at end of file diff --git a/src/Math/Constants.hpp b/src/Math/Constants.hpp new file mode 100644 index 0000000..9c62e94 --- /dev/null +++ b/src/Math/Constants.hpp @@ -0,0 +1,8 @@ +#pragma once + +namespace Math { + +constexpr double PI = 3.14159265358979323846; +constexpr double E = 2.71828182845904523536; + +} \ No newline at end of file diff --git a/src/Math/Perlin.hpp b/src/Math/Perlin.hpp index c31697b..17d33fd 100644 --- a/src/Math/Perlin.hpp +++ b/src/Math/Perlin.hpp @@ -16,6 +16,7 @@ struct Noise { uint octaves = 3; float persistence = 0.3f; + float lacunarity = 2.0f; float at(Vector pos) const { float result = 0; @@ -27,7 +28,7 @@ struct Noise { result += raw((pos + offset).abs() / scale * frequency) * amplitude; max += amplitude; - frequency *= 2; + frequency *= lacunarity; amplitude *= persistence; } diff --git a/src/Math/Sigmoid.hpp b/src/Math/Sigmoid.hpp new file mode 100644 index 0000000..f2fa009 --- /dev/null +++ b/src/Math/Sigmoid.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include +#include "Constants.hpp" + +namespace Math { + +template +T sigmoid(T x) { + return 1 / (1 + std::pow(E, -x)); +} + +} diff --git a/src/Math/Trig.hpp b/src/Math/Trig.hpp index c64e2f2..2a415f5 100644 --- a/src/Math/Trig.hpp +++ b/src/Math/Trig.hpp @@ -1,8 +1,8 @@ #pragma once -namespace Math { +#include "Constants.hpp" -constexpr double PI = 3.14159265358979323846; +namespace Math { template T radians(T degrees) { -- cgit 1.4.1