aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/util')
-rw-r--r--src/util/directiontables.cpp72
-rw-r--r--src/util/directiontables.h3
-rw-r--r--src/util/numeric.h31
3 files changed, 31 insertions, 75 deletions
diff --git a/src/util/directiontables.cpp b/src/util/directiontables.cpp
index 86ea6a45f..297058c9c 100644
--- a/src/util/directiontables.cpp
+++ b/src/util/directiontables.cpp
@@ -110,78 +110,6 @@ const v3s16 g_27dirs[27] =
v3s16(0,0,0),
};
-const v3s16 g_64dirs[64] =
-{
- // +right, +top, +back
- v3s16( -1, -1, -1),
- v3s16( -1, 0, -1),
- v3s16( -1, 1, -1),
- v3s16( -1, 2, -1),
- v3s16( -1, -1, 0),
- v3s16( -1, 0, 0),
- v3s16( -1, 1, 0),
- v3s16( -1, 2, 0),
- v3s16( -1, -1, 1),
- v3s16( -1, 0, 1),
- v3s16( -1, 1, 1),
- v3s16( -1, 2, 1),
- v3s16( -1, -1, 2),
- v3s16( -1, 0, 2),
- v3s16( -1, 1, 2),
- v3s16( -1, 2, 2),
-
- v3s16( 0, -1, -1),
- v3s16( 0, 0, -1),
- v3s16( 0, 1, -1),
- v3s16( 0, 2, -1),
- v3s16( 0, -1, 0),
- v3s16( 0, 0, 0),
- v3s16( 0, 1, 0),
- v3s16( 0, 2, 0),
- v3s16( 0, -1, 1),
- v3s16( 0, 0, 1),
- v3s16( 0, 1, 1),
- v3s16( 0, 2, 1),
- v3s16( 0, -1, 2),
- v3s16( 0, 0, 2),
- v3s16( 0, 1, 2),
- v3s16( 0, 2, 2),
-
- v3s16( 1, -1, -1),
- v3s16( 1, 0, -1),
- v3s16( 1, 1, -1),
- v3s16( 1, 2, -1),
- v3s16( 1, -1, 0),
- v3s16( 1, 0, 0),
- v3s16( 1, 1, 0),
- v3s16( 1, 2, 0),
- v3s16( 1, -1, 1),
- v3s16( 1, 0, 1),
- v3s16( 1, 1, 1),
- v3s16( 1, 2, 1),
- v3s16( 1, -1, 2),
- v3s16( 1, 0, 2),
- v3s16( 1, 1, 2),
- v3s16( 1, 2, 2),
-
- v3s16( 2, -1, -1),
- v3s16( 2, 0, -1),
- v3s16( 2, 1, -1),
- v3s16( 2, 2, -1),
- v3s16( 2, -1, 0),
- v3s16( 2, 0, 0),
- v3s16( 2, 1, 0),
- v3s16( 2, 2, 0),
- v3s16( 2, -1, 1),
- v3s16( 2, 0, 1),
- v3s16( 2, 1, 1),
- v3s16( 2, 2, 1),
- v3s16( 2, -1, 2),
- v3s16( 2, 0, 2),
- v3s16( 2, 1, 2),
- v3s16( 2, 2, 2),
-};
-
const u8 wallmounted_to_facedir[6] = {
20,
0,
diff --git a/src/util/directiontables.h b/src/util/directiontables.h
index 7cdcebaa4..3883a6e37 100644
--- a/src/util/directiontables.h
+++ b/src/util/directiontables.h
@@ -31,9 +31,6 @@ extern const v3s16 g_26dirs[26];
// 26th is (0,0,0)
extern const v3s16 g_27dirs[27];
-// all positions around an octablock in sector-first order
-extern const v3s16 g_64dirs[64];
-
extern const u8 wallmounted_to_facedir[6];
extern const v3s16 wallmounted_dirs[8];
diff --git a/src/util/numeric.h b/src/util/numeric.h
index 265046a63..f0d4fe482 100644
--- a/src/util/numeric.h
+++ b/src/util/numeric.h
@@ -145,6 +145,37 @@ inline v3s16 componentwise_max(const v3s16 &a, const v3s16 &b)
return v3s16(MYMAX(a.X, b.X), MYMAX(a.Y, b.Y), MYMAX(a.Z, b.Z));
}
+/// @brief Describes a grid with given step, oirginating at (0,0,0)
+struct MeshGrid {
+ u16 cell_size;
+
+ u32 getCellVolume() const { return cell_size * cell_size * cell_size; }
+
+ /// @brief returns closest step of the grid smaller than p
+ s16 getMeshPos(s16 p) const
+ {
+ return ((p - (p < 0) * (cell_size - 1)) / cell_size * cell_size);
+ }
+
+ /// @brief Returns coordinates of the origin of the grid cell containing p
+ v3s16 getMeshPos(v3s16 p) const
+ {
+ return v3s16(getMeshPos(p.X), getMeshPos(p.Y), getMeshPos(p.Z));
+ }
+
+ /// @brief Returns true if p is an origin of a cell in the grid.
+ bool isMeshPos(v3s16 &p) const
+ {
+ return ((p.X + p.Y + p.Z) % cell_size) == 0;
+ }
+
+ /// @brief Returns index of the given offset in a grid cell
+ /// All offset coordinates must be smaller than the size of the cell
+ u16 getOffsetIndex(v3s16 offset) const
+ {
+ return (offset.Z * cell_size + offset.Y) * cell_size + offset.X;
+ }
+};
/** Returns \p f wrapped to the range [-360, 360]
*