X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fblock.cpp;h=c9fceec85aeb6da7ebe03381bd3af182cf1ac22f;hb=6933bedd9a46d69d9ad3cbdee4f17cd78103e336;hp=02e8476c4a2af7cf9ec407fd76040acf8c057dba;hpb=804bde3fc09e4317eef629861638a68bfad3e343;p=blank.git diff --git a/src/block.cpp b/src/block.cpp index 02e8476..c9fceec 100644 --- a/src/block.cpp +++ b/src/block.cpp @@ -1,36 +1,85 @@ #include "block.hpp" +#include "geometry.hpp" + +#include +#include + namespace blank { -const BlockType BlockType::DEFAULT; +namespace { + +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 +}; + +} + +const glm::mat4 &Block::Transform() const { + return block_transforms[orient]; +} + + const NullShape BlockType::DEFAULT_SHAPE; -void BlockType::FillVBO( - const glm::vec3 &pos, - std::vector &vertices, - std::vector &colors, - std::vector &normals +BlockType::BlockType(bool v, const glm::vec3 &col, const Shape *s) +: shape(s) +, color(col) +, outline_color(-1, -1, -1) +, id(0) +, visible(v) +, fill({ false, false, false, false, false, false }) { + +} + +void BlockType::FillModel( + Model::Buffer &buf, + const glm::mat4 &transform, + Model::Index idx_offset ) const { - shape->Vertices(vertices, pos); - colors.insert(colors.end(), shape->VertexCount(), color); - shape->Normals(normals); + shape->Vertices(buf.vertices, buf.normals, buf.indices, transform, idx_offset); + buf.colors.insert(buf.colors.end(), shape->VertexCount(), color); } -void BlockType::FillOutlineVBO( - std::vector &vertices, - std::vector &colors +void BlockType::FillOutlineModel( + OutlineModel &model, + const glm::vec3 &pos_offset, + OutlineModel::Index idx_offset ) const { - shape->Outline(vertices); - colors.insert(colors.end(), shape->OutlineCount(), outline_color); + shape->Outline(model.vertices, model.indices, pos_offset, idx_offset); + model.colors.insert(model.colors.end(), shape->OutlineCount(), outline_color); } BlockTypeRegistry::BlockTypeRegistry() { - Add(BlockType::DEFAULT); + Add(BlockType()); } -int BlockTypeRegistry::Add(const BlockType &t) { +Block::Type BlockTypeRegistry::Add(const BlockType &t) { int id = types.size(); types.push_back(t); types.back().id = id;