diff options
Diffstat (limited to 'src/World/Position.hpp')
| -rw-r--r-- | src/World/Position.hpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/World/Position.hpp b/src/World/Position.hpp index f2915aa..f9b8ad1 100644 --- a/src/World/Position.hpp +++ b/src/World/Position.hpp @@ -2,6 +2,7 @@ #include <array> #include <algorithm> +#include "../Common/Casts.hpp" #include "ChunkDimensions.hpp" #include "../Math/Common.hpp" #include "../Math/Vector.hpp" @@ -19,6 +20,18 @@ class BlockLocalOffset : public Vector<3, I16> { public: MC_POSITION_MAKE_DEFAULT_CONSTRUCTORS(BlockLocalOffset, I16) + // Create a block local offset from a unit normal, + // which is a vector with exactly one component being 1 or -1, + // with the rest being 0. + template<typename T> + static BlockLocalOffset from_unit_normal(Vector<3, T> normal) { + return { + TO(I16, normal.x()), + TO(I16, normal.y()), + TO(I16, normal.z()) + }; + } + Bool fits_within_chunk() const { using namespace MC::World::ChunkDimensions; return x() >= 0 && x() < Width && y() >= 0 && y() < Height && z() >= 0 && z() < Width; @@ -44,6 +57,18 @@ public: class BlockWorldOffset : public Vector<3, I64> { public: MC_POSITION_MAKE_DEFAULT_CONSTRUCTORS(BlockWorldOffset, I64) + + // Create a block world offset from a unit normal, + // which is a vector with exactly one component being 1 or -1, + // with the rest being 0. + template<typename T> + static BlockWorldOffset from_unit_normal(Vector<3, T> normal) { + return { + TO(I64, normal.x()), + TO(I64, normal.y()), + TO(I64, normal.z()) + }; + } }; // Position of a block within entire world. |
