From: Daniel Karbach Date: Fri, 20 Feb 2015 07:21:05 +0000 (+0100) Subject: block type colors X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=ac8765b510707d77cac9620778f40ddf3a4ad2a2;p=blank.git block type colors --- diff --git a/src/app.cpp b/src/app.cpp index 8c957a7..b398e9c 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -17,12 +17,12 @@ Application::Application() , move_velocity(0.003f) , pitch_sensitivity(-0.0025f) , yaw_sensitivity(-0.001f) -, testBlockType(true) +, blockType() , cam() , chunk() , light_position(17.0f, 17.0f, 17.0f) , light_color(1.0f, 1.0f, 1.0f) -, light_power(100.0f) +, light_power(250.0f) , m_handle(0) , v_handle(0) , mv_handle(0) @@ -107,12 +107,27 @@ Application::Application() cam.Position(glm::vec3(0, 4, 4)); - chunk.BlockAt(glm::vec3(0, 0, 0)) = Block(&testBlockType); - chunk.BlockAt(glm::vec3(1, 0, 0)) = Block(&testBlockType); - chunk.BlockAt(glm::vec3(1, 1, 0)) = Block(&testBlockType); - chunk.BlockAt(glm::vec3(1, 1, 1)) = Block(&testBlockType); - chunk.BlockAt(glm::vec3(2, 1, 1)) = Block(&testBlockType); - chunk.BlockAt(glm::vec3(2, 2, 1)) = Block(&testBlockType); + blockType.Add(BlockType(true, glm::vec3(1, 1, 1))); + blockType.Add(BlockType(true, glm::vec3(1, 0, 0))); + blockType.Add(BlockType(true, glm::vec3(0, 1, 0))); + blockType.Add(BlockType(true, glm::vec3(0, 0, 1))); + + chunk.BlockAt(glm::vec3(0, 0, 0)) = Block(blockType[4]); + chunk.BlockAt(glm::vec3(0, 0, 1)) = Block(blockType[1]); + chunk.BlockAt(glm::vec3(1, 0, 0)) = Block(blockType[2]); + chunk.BlockAt(glm::vec3(1, 0, 1)) = Block(blockType[3]); + chunk.BlockAt(glm::vec3(2, 0, 0)) = Block(blockType[4]); + chunk.BlockAt(glm::vec3(2, 0, 1)) = Block(blockType[1]); + chunk.BlockAt(glm::vec3(3, 0, 0)) = Block(blockType[2]); + chunk.BlockAt(glm::vec3(3, 0, 1)) = Block(blockType[3]); + chunk.BlockAt(glm::vec3(2, 0, 2)) = Block(blockType[4]); + chunk.BlockAt(glm::vec3(2, 0, 3)) = Block(blockType[1]); + chunk.BlockAt(glm::vec3(3, 0, 2)) = Block(blockType[2]); + chunk.BlockAt(glm::vec3(3, 0, 3)) = Block(blockType[3]); + chunk.BlockAt(glm::vec3(1, 1, 0)) = Block(blockType[1]); + chunk.BlockAt(glm::vec3(1, 1, 1)) = Block(blockType[4]); + chunk.BlockAt(glm::vec3(2, 1, 1)) = Block(blockType[3]); + chunk.BlockAt(glm::vec3(2, 2, 1)) = Block(blockType[2]); chunk.Invalidate(); m_handle = program.UniformLocation("M"); diff --git a/src/app.hpp b/src/app.hpp index d9b7046..e5cddce 100644 --- a/src/app.hpp +++ b/src/app.hpp @@ -42,7 +42,7 @@ private: float pitch_sensitivity; float yaw_sensitivity; - BlockType testBlockType; + BlockTypeRegistry blockType; Camera cam; Chunk chunk; diff --git a/src/world.cpp b/src/world.cpp index 2dd7b30..96b48ee 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -48,12 +48,7 @@ void BlockType::FillVBO( vertices.emplace_back(pos.x + 1, pos.y + 1, pos.z ); vertices.emplace_back(pos.x + 1, pos.y + 1, pos.z + 1); - colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // front - colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // back - colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // top - colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // bottom - colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // left - colors.insert(colors.end(), 6, glm::vec3(1.0f, 1.0f, 1.0f)); // right + colors.insert(colors.end(), 6 * 6, color); normals.insert(normals.end(), 6, glm::vec3( 0.0f, 0.0f, 1.0f)); // front normals.insert(normals.end(), 6, glm::vec3( 0.0f, 0.0f, -1.0f)); // back @@ -64,6 +59,18 @@ void BlockType::FillVBO( } +BlockTypeRegistry::BlockTypeRegistry() { + Add(BlockType::DEFAULT); +} + +int BlockTypeRegistry::Add(const BlockType &t) { + int id = types.size(); + types.push_back(t); + types.back().id = id; + return id; +} + + Chunk::Chunk() : blocks(Size()) , model() diff --git a/src/world.hpp b/src/world.hpp index 304c63a..58f7a25 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -13,10 +13,15 @@ namespace blank { /// attributes of a type of block struct BlockType { + int id; + bool visible; + glm::vec3 color; - constexpr explicit BlockType(bool v = false) - : visible(v) { } + constexpr explicit BlockType( + bool v = false, + const glm::vec3 &color = { 1, 1, 1 }) + : id(-1), visible(v), color(color) { } static const BlockType DEFAULT; @@ -35,6 +40,23 @@ struct BlockType { }; +class BlockTypeRegistry { + +public: + BlockTypeRegistry(); + +public: + int Add(const BlockType &); + + BlockType *operator [](int id) { return &types[id]; } + const BlockType *Get(int id) const { return &types[id]; } + +private: + std::vector types; + +}; + + /// single 1x1x1 cube struct Block {