summary refs log tree commit diff
path: root/src/Math
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-06-29 22:15:32 +0200
committerMel <einebeere@gmail.com>2023-06-29 22:15:32 +0200
commit52732d71e72b02ff45e25f44e414f87ec9ab7666 (patch)
treea3db775e01e04abaf0291e7d172740ff47ff1006 /src/Math
parent92ac46df6afa8ee76f972cceb681cf32658f84a2 (diff)
downloadmeowcraft-52732d71e72b02ff45e25f44e414f87ec9ab7666.tar.zst
meowcraft-52732d71e72b02ff45e25f44e414f87ec9ab7666.zip
Pretty terrain generation
Diffstat (limited to 'src/Math')
-rw-r--r--src/Math/Common.hpp3
-rw-r--r--src/Math/Constants.hpp8
-rw-r--r--src/Math/Perlin.hpp3
-rw-r--r--src/Math/Sigmoid.hpp13
-rw-r--r--src/Math/Trig.hpp4
5 files changed, 27 insertions, 4 deletions
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<D> 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 <cmath>
+#include "Constants.hpp"
+
+namespace Math {
+
+template <typename T>
+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<typename T>
 T radians(T degrees) {