From: Daniel Karbach Date: Wed, 4 Mar 2015 17:22:18 +0000 (+0100) Subject: move outline definition to block type X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=e7a968ef0ae496d1d45d63a25df59db31f9b966f;p=blank.git move outline definition to block type --- diff --git a/src/app.cpp b/src/app.cpp index 8c40c61..5463f7f 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -46,23 +46,6 @@ Application::Application() world.Generate(); - outline.vertices = std::vector({ - { 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, - { 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 0.0f }, - { 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, - { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, - { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f }, - { 1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 1.0f }, - { 1.0f, 1.0f, 0.0f }, { 1.0f, 1.0f, 1.0f }, - { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 1.0f }, - { 0.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 1.0f }, - { 1.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f }, - { 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f, 1.0f }, - { 0.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f }, - }); - outline.colors.resize(24, { -1, -1, -1 }); - outline.Invalidate(); - glClearColor(0.0, 0.0, 0.0, 1.0); } @@ -176,6 +159,7 @@ void Application::Update(int dt) { if (world.Intersection(aim, glm::mat4(1.0f), &chunk, &blkid, &dist, &normal)) { glm::vec3 pos = Chunk::ToCoords(blkid); outline_visible = true; + chunk->BlockAt(blkid).type->FillOutlineModel(outline); outline_transform = glm::translate(chunk->Transform(), pos); } else { outline_visible = false; diff --git a/src/world.cpp b/src/world.cpp index c24450c..2ac65ab 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -61,6 +61,27 @@ void BlockType::FillVBO( normals.insert(normals.end(), 6, glm::vec3( 1.0f, 0.0f, 0.0f)); // right } +void BlockType::FillOutlineVBO( + std::vector &vertices, + std::vector &colors +) const { + vertices = std::vector({ + { 0.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, + { 1.0f, 0.0f, 0.0f }, { 1.0f, 1.0f, 0.0f }, + { 1.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, + { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 0.0f }, + { 0.0f, 0.0f, 0.0f }, { 0.0f, 0.0f, 1.0f }, + { 1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 1.0f }, + { 1.0f, 1.0f, 0.0f }, { 1.0f, 1.0f, 1.0f }, + { 0.0f, 1.0f, 0.0f }, { 0.0f, 1.0f, 1.0f }, + { 0.0f, 0.0f, 1.0f }, { 1.0f, 0.0f, 1.0f }, + { 1.0f, 0.0f, 1.0f }, { 1.0f, 1.0f, 1.0f }, + { 1.0f, 1.0f, 1.0f }, { 0.0f, 1.0f, 1.0f }, + { 0.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 1.0f }, + }); + colors.resize(24, outline_color); +} + BlockTypeRegistry::BlockTypeRegistry() { Add(BlockType::DEFAULT); diff --git a/src/world.hpp b/src/world.hpp index 9f29ab4..9fb0779 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -19,11 +19,13 @@ struct BlockType { bool visible; glm::vec3 color; + glm::vec3 outline_color; constexpr explicit BlockType( bool v = false, - const glm::vec3 &color = { 1, 1, 1 }) - : id(-1), visible(v), color(color) { } + const glm::vec3 &color = { 1, 1, 1 }, + const glm::vec3 &outline_color = { -1, -1, -1 }) + : id(-1), visible(v), color(color), outline_color(outline_color) { } static const BlockType DEFAULT; @@ -37,6 +39,18 @@ struct BlockType { void FillModel(const glm::vec3 &pos, Model &m) const { FillVBO(pos, m.vertices, m.colors, m.normals); + m.Invalidate(); + } + + + void FillOutlineVBO( + std::vector &vertices, + std::vector &colors + ) const; + + void FillOutlineModel(OutlineModel &m) const { + FillOutlineVBO(m.vertices, m.colors); + m.Invalidate(); } };