diff options
| author | Mel <einebeere@gmail.com> | 2024-02-02 16:16:25 +0100 |
|---|---|---|
| committer | Mel <einebeere@gmail.com> | 2024-02-02 16:16:25 +0100 |
| commit | a4a61ac2e6389af0968ac4fb305b82c6eb90bf0e (patch) | |
| tree | 800749ed6a5d503837a6bf0c389c133fcb59143d /src/World/Position.hpp | |
| parent | 250e37c742f3ad46f093f4534098cdf8f68a29a9 (diff) | |
| download | meowcraft-a4a61ac2e6389af0968ac4fb305b82c6eb90bf0e.tar.zst meowcraft-a4a61ac2e6389af0968ac4fb305b82c6eb90bf0e.zip | |
Placing blocks
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. |
