diff --git a/src/voxels/Block.cpp b/src/voxels/Block.cpp index c05d9af5..e63392b3 100644 --- a/src/voxels/Block.cpp +++ b/src/voxels/Block.cpp @@ -33,47 +33,55 @@ std::optional BlockModel_from(std::string_view str) { CoordSystem::CoordSystem(glm::ivec3 axisX, glm::ivec3 axisY, glm::ivec3 axisZ) : axisX(axisX), axisY(axisY), axisZ(axisZ) { - fix = glm::ivec3(0); - if (isVectorHasNegatives(axisX)) fix -= axisX; - if (isVectorHasNegatives(axisY)) fix -= axisY; - if (isVectorHasNegatives(axisZ)) fix -= axisZ; + fix = glm::ivec3(0); + if (isVectorHasNegatives(axisX)) fix -= axisX; + if (isVectorHasNegatives(axisY)) fix -= axisY; + if (isVectorHasNegatives(axisZ)) fix -= axisZ; } void CoordSystem::transform(AABB& aabb) const { - glm::vec3 X(axisX); - glm::vec3 Y(axisY); - glm::vec3 Z(axisZ); - aabb.a = X * aabb.a.x + Y * aabb.a.y + Z * aabb.a.z; - aabb.b = X * aabb.b.x + Y * aabb.b.y + Z * aabb.b.z; - aabb.a += fix; - aabb.b += fix; + glm::vec3 X(axisX); + glm::vec3 Y(axisY); + glm::vec3 Z(axisZ); + aabb.a = X * aabb.a.x + Y * aabb.a.y + Z * aabb.a.z; + aabb.b = X * aabb.b.x + Y * aabb.b.y + Z * aabb.b.z; + aabb.a += fix; + aabb.b += fix; } +const BlockRotProfile BlockRotProfile::NONE {"none", { + {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // North + {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // East + {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // South + {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // West + {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // Up + {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, // Down +}}; + + const BlockRotProfile BlockRotProfile::PIPE {"pipe", { - { { 1, 0, 0 }, { 0, 0, 1 }, { 0, -1, 0 }}, // North - { { 0, 0, 1 }, {-1, 0, 0 }, { 0, -1, 0 }}, // East - { {-1, 0, 0 }, { 0, 0,-1 }, { 0, -1, 0 }}, // South - { { 0, 0,-1 }, { 1, 0, 0 }, { 0, -1, 0 }}, // West - { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }}, // Up - { { 1, 0, 0 }, { 0,-1, 0 }, { 0, 0,-1 }}, // Down + { { 1, 0, 0 }, { 0, 0, 1 }, { 0, -1, 0 }}, // North + { { 0, 0, 1 }, {-1, 0, 0 }, { 0, -1, 0 }}, // East + { {-1, 0, 0 }, { 0, 0,-1 }, { 0, -1, 0 }}, // South + { { 0, 0,-1 }, { 1, 0, 0 }, { 0, -1, 0 }}, // West + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }}, // Up + { { 1, 0, 0 }, { 0,-1, 0 }, { 0, 0,-1 }}, // Down }}; const BlockRotProfile BlockRotProfile::PANE {"pane", { - { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }}, // North - { { 0, 0,-1 }, { 0, 1, 0 }, { 1, 0, 0 }}, // East - { {-1, 0, 0 }, { 0, 1, 0 }, { 0, 0,-1 }}, // South - { { 0, 0, 1 }, { 0, 1, 0 }, {-1, 0, 0 }}, // West + { { 1, 0, 0 }, { 0, 1, 0 }, { 0, 0, 1 }}, // North + { { 0, 0,-1 }, { 0, 1, 0 }, { 1, 0, 0 }}, // East + { {-1, 0, 0 }, { 0, 1, 0 }, { 0, 0,-1 }}, // South + { { 0, 0, 1 }, { 0, 1, 0 }, {-1, 0, 0 }}, // West }}; Block::Block(const std::string& name) - : name(name), + : name(name), caption(util::id_to_caption(name)), - textureFaces {TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND, - TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND}, - rotations(BlockRotProfile::PIPE) + textureFaces {TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND, + TEXTURE_NOTFOUND,TEXTURE_NOTFOUND,TEXTURE_NOTFOUND} {} Block::Block(std::string name, const std::string& texture) : name(std::move(name)), - textureFaces{texture,texture,texture,texture,texture,texture}, - rotations(BlockRotProfile::PIPE) + textureFaces{texture,texture,texture,texture,texture,texture} {} diff --git a/src/voxels/Block.hpp b/src/voxels/Block.hpp index be9c5660..ce83079d 100644 --- a/src/voxels/Block.hpp +++ b/src/voxels/Block.hpp @@ -58,6 +58,9 @@ struct BlockRotProfile { std::string name; CoordSystem variants[MAX_COUNT]; + /// @brief No rotation + static const BlockRotProfile NONE; + /// @brief Wood logs, pillars, pipes static const BlockRotProfile PIPE; @@ -160,7 +163,7 @@ public: std::vector hitboxes; /// @brief Set of available block rotations (coord-systems) - BlockRotProfile rotations; + BlockRotProfile rotations = BlockRotProfile::NONE; /// @brief Item will be picked on MMB click on the block std::string pickingItem = name+BLOCK_ITEM_SUFFIX; @@ -207,12 +210,7 @@ public: }; inline glm::ivec3 get_ground_direction(const Block* def, int rotation) { - const auto& profileName = def->rotations.name; - if (profileName == BlockRotProfile::PIPE_NAME) { - return -def->rotations.variants[rotation].axisY; - } else { - return glm::ivec3(0, -1, 0); - } + return -def->rotations.variants[rotation].axisY; } #endif // VOXELS_BLOCK_HPP_