1 #ifndef BLANK_WORLD_HPP_
2 #define BLANK_WORLD_HPP_
13 /// attributes of a type of block
18 constexpr explicit BlockType(bool v = false)
21 static const BlockType DEFAULT;
26 std::vector<glm::vec3> &vertices,
27 std::vector<glm::vec3> &colors,
28 std::vector<glm::vec3> &normals
31 void FillModel(const glm::vec3 &pos, Model &m) const {
32 FillVBO(pos, m.vertices, m.colors, m.normals);
41 const BlockType *type;
43 constexpr explicit Block(const BlockType *t = &BlockType::DEFAULT)
49 /// cube of size 16 (256 tiles, 4096 blocks)
55 static constexpr int Width() { return 16; }
56 static constexpr int Height() { return 16; }
57 static constexpr int Depth() { return 16; }
58 static constexpr int Size() { return Width() * Height() * Depth(); }
60 static constexpr int ToIndex(const glm::vec3 &pos) {
61 return pos.x + pos.y * Width() + pos.z * Width() * Height();
63 static glm::vec3 ToCoords(int idx) {
66 (idx / Width()) % Height(),
67 idx / (Width() * Height())
71 void Invalidate() { dirty = true; }
73 Block &BlockAt(const glm::vec3 &pos) { return blocks[ToIndex(pos)]; }
74 const Block &BlockAt(const glm::vec3 &pos) const { return blocks[ToIndex(pos)]; }
79 int VertexCount() const;
83 std::vector<Block> blocks;