summary refs log tree commit diff
path: root/src/Math/Grid.cpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2023-06-12 17:09:55 +0200
committerMel <einebeere@gmail.com>2023-06-12 17:14:03 +0200
commitd0de60dc33df75fbcacb53a09568b14d0fd48cb9 (patch)
tree7aefdbb81f114552881834bd5b0d842bc2bdb691 /src/Math/Grid.cpp
parent23b0bc4d1ddc9fad3c32e8257497ddd13ac6a155 (diff)
downloadmeowcraft-d0de60dc33df75fbcacb53a09568b14d0fd48cb9.tar.zst
meowcraft-d0de60dc33df75fbcacb53a09568b14d0fd48cb9.zip
Multithreaded world generation with Perlin
Diffstat (limited to 'src/Math/Grid.cpp')
-rw-r--r--src/Math/Grid.cpp77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/Math/Grid.cpp b/src/Math/Grid.cpp
new file mode 100644
index 0000000..422cf87
--- /dev/null
+++ b/src/Math/Grid.cpp
@@ -0,0 +1,77 @@
+#include "Grid.hpp"
+
+namespace Math {
+
+GridCellBoundaries grid_cell_for_point(Vector<2> point) {
+    auto x1 = std::trunc(point.x());
+    auto y1 = std::trunc(point.y());
+    auto x2 = x1 + 1.0f;
+    auto y2 = y1 + 1.0f;
+
+    return GridCellBoundaries{x1, x2, y1, y2};
+}
+
+Vector<2> GridCellBoundaries::top_left() const {
+    return {x1, y1};
+}
+
+Vector<2> GridCellBoundaries::top_right() const {
+    return {x2, y1};
+}
+
+Vector<2> GridCellBoundaries::bottom_left() const {
+    return {x1, y2};
+}
+
+Vector<2> GridCellBoundaries::bottom_right() const {
+    return {x2, y2};
+}
+
+CubeCellBoundaries cube_cell_for_point(Vector<3> point) {
+    auto x1 = std::trunc(point.x());
+    auto y1 = std::trunc(point.y());
+    auto z1 = std::trunc(point.z());
+    auto x2 = x1 + 1.0f;
+    auto y2 = y1 + 1.0f;
+    auto z2 = z1 + 1.0f;
+
+    return CubeCellBoundaries{x1, x2, y1, y2, z1, z2};
+}
+
+Vector<3> CubeCellBoundaries::front_top_left() const {
+    return {x1, y1, z1};
+}
+
+Vector<3> CubeCellBoundaries::front_top_right() const {
+    return {x2, y1, z1};
+}
+
+Vector<3> CubeCellBoundaries::front_bottom_left() const {
+    return {x1, y2, z1};
+}
+
+Vector<3> CubeCellBoundaries::front_bottom_right() const {
+    return {x2, y2, z1};
+}
+
+Vector<3> CubeCellBoundaries::back_top_left() const {
+    return {x1, y1, z2};
+}
+
+Vector<3> CubeCellBoundaries::back_top_right() const {
+    return {x2, y1, z2};
+}
+
+Vector<3> CubeCellBoundaries::back_bottom_left() const {
+    return {x1, y2, z2};
+}
+
+Vector<3> CubeCellBoundaries::back_bottom_right() const {
+    return {x2, y2, z2};
+}
+
+GridCellBoundaries CubeCellBoundaries::grid_cell() const {
+    return {x1, x2, y1, y2};
+}
+
+}
\ No newline at end of file