From: Daniel Karbach Date: Thu, 12 Mar 2015 20:05:45 +0000 (+0100) Subject: use precalculated matrices for block orientation X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=6933bedd9a46d69d9ad3cbdee4f17cd78103e336;p=blank.git use precalculated matrices for block orientation --- diff --git a/src/block.cpp b/src/block.cpp index fa39790..c9fceec 100644 --- a/src/block.cpp +++ b/src/block.cpp @@ -10,31 +10,31 @@ namespace blank { namespace { -const glm::mat4 block_transforms[Block::DIR_COUNT * Block::ROT_COUNT] = { - glm::mat4(1.0f), - glm::eulerAngleY(PI_0p5), - glm::eulerAngleY(PI), - glm::eulerAngleY(PI_1p5), - glm::eulerAngleX(PI), - glm::eulerAngleYX(PI_0p5, PI), - glm::eulerAngleYX(PI, PI), - glm::eulerAngleYX(PI_1p5, PI), - glm::eulerAngleZ(PI_0p5), - glm::eulerAngleYZ(PI_0p5, PI_0p5), - glm::eulerAngleYZ(PI, PI_0p5), - glm::eulerAngleYZ(PI_1p5, PI_0p5), - glm::eulerAngleZ(PI_1p5), - glm::eulerAngleYZ(PI_0p5, PI_1p5), - glm::eulerAngleYZ(PI, PI_1p5), - glm::eulerAngleYZ(PI_1p5, PI_1p5), - glm::eulerAngleX(PI_0p5), - glm::eulerAngleYX(PI_0p5, PI_0p5), - glm::eulerAngleYX(PI, PI_0p5), - glm::eulerAngleYX(PI_1p5, PI_0p5), - glm::eulerAngleX(PI_1p5), - glm::eulerAngleYX(PI_0p5, PI_1p5), - glm::eulerAngleYX(PI, PI_1p5), - glm::eulerAngleYX(PI_1p5, PI_1p5), +const glm::mat4 block_transforms[Block::FACE_COUNT * Block::TURN_COUNT] = { + { 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, }, // face: up, turn: none + { 0, 0, -1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, }, // face: up, turn: left + { -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, }, // face: up, turn: around + { 0, 0, 1, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 1, }, // face: up, turn: right + { 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, }, // face: down, turn: none + { 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 1, }, // face: down, turn: left + { -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, }, // face: down, turn: around + { 0, 0, 1, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, }, // face: down, turn: right + { 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, }, // face: right, turn: none + { 0, -1, 0, 0, 0, 0, -1, 0, 1, 0, 0, 0, 0, 0, 0, 1, }, // face: right, turn: left + { 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, }, // face: right, turn: around + { 0, -1, 0, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 0, 1, }, // face: right, turn: right + { 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, }, // face: left, turn: none + { 0, 1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 1, }, // face: left, turn: left + { 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 1, }, // face: left, turn: around + { 0, 1, 0, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, 0, 0, 1, }, // face: left, turn: right + { 1, 0, 0, 0, 0, 0, 1, 0, 0, -1, 0, 0, 0, 0, 0, 1, }, // face: front, turn: none + { 0, 0, -1, 0, 1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1, }, // face: front, turn: left + { -1, 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 1, }, // face: front, turn: around + { 0, 0, 1, 0, -1, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, 1, }, // face: front, turn: right + { 1, 0, 0, 0, 0, 0, -1, 0, 0, 1, 0, 0, 0, 0, 0, 1, }, // face: back, turn: none + { 0, 0, -1, 0, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, }, // face: back, turn: left + { -1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, }, // face: back, turn: around + { 0, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, }, // face: back, turn: right }; } diff --git a/src/block.hpp b/src/block.hpp index a63cf26..3777e6d 100644 --- a/src/block.hpp +++ b/src/block.hpp @@ -17,28 +17,28 @@ struct Block { using Type = unsigned short; using Pos = glm::vec3; - enum Direction { - DIR_UP, - DIR_DOWN, - DIR_LEFT, - DIR_RIGHT, - DIR_FRONT, - DIR_BACK, - DIR_COUNT, + enum Face { + FACE_UP, + FACE_DOWN, + FACE_RIGHT, + FACE_LEFT, + FACE_FRONT, + FACE_BACK, + FACE_COUNT, }; - enum Rotation { - ROT_NONE, - ROT_90, - ROT_180, - ROT_270, - ROT_COUNT, + enum Turn { + TURN_NONE, + TURN_LEFT, + TURN_AROUND, + TURN_RIGHT, + TURN_COUNT, }; Type type; unsigned char orient; - constexpr explicit Block(Type type = 0, Direction dir = DIR_UP, Rotation rot = ROT_NONE) - : type(type), orient(dir * ROT_COUNT + rot) { } + constexpr explicit Block(Type type = 0, Face face = FACE_UP, Turn turn = TURN_NONE) + : type(type), orient(face * TURN_COUNT + turn) { } const glm::mat4 &Transform() const; diff --git a/src/chunk.cpp b/src/chunk.cpp index 1493086..fbee721 100644 --- a/src/chunk.cpp +++ b/src/chunk.cpp @@ -224,6 +224,15 @@ void ChunkLoader::Generate(const Chunk::Pos &from, const Chunk::Pos &to) { loaded.emplace_back(reg); loaded.back().Position(pos); gen(loaded.back()); + + // orientation testing + // for (int i = 0; i < Block::FACE_COUNT; ++i) { + // for (int j = 0; j < Block::TURN_COUNT; ++j) { + // loaded.back().BlockAt(512 * j + 2 * i) = Block(3 * (j + 1), Block::Face(i), Block::Turn(j)); + // } + // } + // loaded.back().Invalidate(); + // loaded.back().CheckUpdate(); } else { to_generate.emplace_back(pos); }