X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FBlock.hpp;h=2eac5ff6ca13b688ad1892ec879181e87ce26bef;hb=1b3b7203d0db35236108869961c77eaf31881d4b;hp=0bb5fd8964b0655dae6addb1dd49903cf89d08ff;hpb=a74e9630e55ca47c23f3ba3c9ccffcaccad394ff;p=blank.git diff --git a/src/world/Block.hpp b/src/world/Block.hpp index 0bb5fd8..2eac5ff 100644 --- a/src/world/Block.hpp +++ b/src/world/Block.hpp @@ -1,8 +1,9 @@ #ifndef BLANK_WORLD_BLOCK_HPP_ #define BLANK_WORLD_BLOCK_HPP_ +#include "../graphics/glm.hpp" + #include -#include namespace blank { @@ -11,7 +12,6 @@ namespace blank { struct Block { using Type = unsigned short; - using Pos = glm::vec3; enum Face { FACE_UP, @@ -66,12 +66,28 @@ struct Block { } } - static glm::tvec3 FaceNormal(Face face) noexcept { + /// returns 1 for pro-axis, -1 for retro-axis, 0 for invalid faces + static int Direction(Face f) noexcept { + switch (f) { + case FACE_RIGHT: + case FACE_UP: + case FACE_FRONT: + return 1; + case FACE_LEFT: + case FACE_DOWN: + case FACE_BACK: + return -1; + default: + return 0; + } + } + + static glm::ivec3 FaceNormal(Face face) noexcept { return face2normal[face]; } static Face NormalFace(const glm::vec3 &norm) noexcept { - const glm::vec3 anorm(abs(norm)); + const glm::vec3 anorm(glm::abs(norm)); if (anorm.x > anorm.y) { if (anorm.x > anorm.z) { return norm.x > 0.0f ? FACE_RIGHT : FACE_LEFT; @@ -125,13 +141,19 @@ struct Block { }; private: - static const glm::tvec3 face2normal[6]; + static const glm::ivec3 face2normal[6]; static const glm::mat4 orient2transform[ORIENT_COUNT]; static const Face orient2face[ORIENT_COUNT][FACE_COUNT]; }; -bool operator ==(const Block &, const Block &); +inline bool operator ==(const Block &a, const Block &b) { + return a.type == b.type && a.orient == b.orient; +} + +inline bool operator !=(const Block &a, const Block &b) { + return !(a == b); +} std::ostream &operator <<(std::ostream &, const Block &); std::ostream &operator <<(std::ostream &, const Block::Face &);