X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld.hpp;h=67ee355ccbc386d5d8fb08f75ec5c0b7d7fb27df;hb=8881c507009521d08648560984c0f50166224542;hp=304c63a7eded25d33bf7ed26e6e3d182fff2f3a3;hpb=482114e156e91729f2529ea6bb1fe98dacdee97f;p=blank.git diff --git a/src/world.hpp b/src/world.hpp index 304c63a..67ee355 100644 --- a/src/world.hpp +++ b/src/world.hpp @@ -2,6 +2,7 @@ #define BLANK_WORLD_HPP_ #include "model.hpp" +#include "geometry.hpp" #include #include @@ -13,10 +14,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 +41,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 { @@ -70,8 +93,17 @@ public: void Invalidate() { dirty = true; } - Block &BlockAt(const glm::vec3 &pos) { return blocks[ToIndex(pos)]; } - const Block &BlockAt(const glm::vec3 &pos) const { return blocks[ToIndex(pos)]; } + Block &BlockAt(int index) { return blocks[index]; } + const Block &BlockAt(int index) const { return blocks[index]; } + Block &BlockAt(const glm::vec3 &pos) { return BlockAt(ToIndex(pos)); } + const Block &BlockAt(const glm::vec3 &pos) const { return BlockAt(ToIndex(pos)); } + + bool Intersection( + const Ray &, + const glm::mat4 &M, + int *blkid = nullptr, + float *dist = nullptr, + glm::vec3 *normal = nullptr) const; void Draw();