From: Daniel Karbach Date: Sun, 8 Mar 2015 10:33:31 +0000 (+0100) Subject: add null shape for void blocks X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=5588a6a9b1e2fb6fee8f1166f855ef497e551a09;p=blank.git add null shape for void blocks --- diff --git a/src/shape.cpp b/src/shape.cpp index 3df4257..e8bd2e6 100644 --- a/src/shape.cpp +++ b/src/shape.cpp @@ -3,6 +3,31 @@ namespace blank { +size_t NullShape::VertexCount() const { + return 0; +} + +void NullShape::Vertices(std::vector &out, const glm::vec3 &pos) const { + +} + +void NullShape::Normals(std::vector &out) const { + +} + +size_t NullShape::OutlineCount() const { + return 0; +} + +void NullShape::Outline(std::vector &out, const glm::vec3 &pos) const { + +} + +bool NullShape::Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const { + return false; +} + + CuboidShape::CuboidShape(const AABB &b) : Shape() , bb(b) { diff --git a/src/shape.hpp b/src/shape.hpp index 434f427..66827d0 100644 --- a/src/shape.hpp +++ b/src/shape.hpp @@ -23,6 +23,22 @@ struct Shape { }; +class NullShape +: public Shape { + +public: + size_t VertexCount() const override; + void Vertices(std::vector &, const glm::vec3 &) const override; + void Normals(std::vector &) const override; + + size_t OutlineCount() const override; + void Outline(std::vector &, const glm::vec3 &) const override; + + bool Intersects(const Ray &, const glm::mat4 &, float &, glm::vec3 &) const override; + +}; + + class CuboidShape : public Shape { diff --git a/src/world.cpp b/src/world.cpp index 6ce0700..aea6ec2 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -7,7 +7,7 @@ namespace blank { const BlockType BlockType::DEFAULT; -const CuboidShape BlockType::DEFAULT_SHAPE({{ 0, 0, 0 }, { 1, 1, 1 }}); +const NullShape BlockType::DEFAULT_SHAPE; void BlockType::FillVBO( const glm::vec3 &pos, @@ -138,7 +138,6 @@ void Chunk::Position(const glm::vec3 &pos) { int Chunk::VertexCount() const { - // TODO: query blocks as soon as type shapes are implemented int count = 0; for (const auto &block : blocks) { count += block.type->shape->VertexCount(); @@ -151,9 +150,7 @@ void Chunk::Update() { model.Reserve(VertexCount()); for (size_t i = 0; i < Size(); ++i) { - if (blocks[i].type->visible) { - blocks[i].type->FillModel(ToCoords(i), model); - } + blocks[i].type->FillModel(ToCoords(i), model); } model.Invalidate(); diff --git a/src/world.hpp b/src/world.hpp index 6fabe9a..738e6f0 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -32,7 +32,7 @@ struct BlockType { : id(-1), visible(v), shape(shape), color(color), outline_color(outline_color) { } static const BlockType DEFAULT; - static const CuboidShape DEFAULT_SHAPE; + static const NullShape DEFAULT_SHAPE; void FillVBO(