1 #ifndef BLANK_CHUNK_HPP_
2 #define BLANK_CHUNK_HPP_
5 #include "geometry.hpp"
14 /// cube of size 16 (256 tiles, 4096 blocks)
21 Chunk &operator =(Chunk &&);
23 static constexpr int Width() { return 16; }
24 static constexpr int Height() { return 16; }
25 static constexpr int Depth() { return 16; }
26 static glm::vec3 Extent() { return glm::vec3(Width(), Height(), Depth()); }
27 static constexpr int Size() { return Width() * Height() * Depth(); }
29 static AABB Bounds() { return AABB{ { 0, 0, 0 }, { Width(), Height(), Depth() } }; }
31 static constexpr bool InBounds(const glm::vec3 &pos) {
33 pos.x >= 0 && pos.x < Width() &&
34 pos.y >= 0 && pos.y < Height() &&
35 pos.z >= 0 && pos.z < Depth();
37 static constexpr int ToIndex(const glm::vec3 &pos) {
38 return int(pos.x) + int(pos.y) * Width() + int(pos.z) * Width() * Height();
40 static constexpr bool InBounds(int idx) {
41 return idx >= 0 && idx < Size();
43 static glm::vec3 ToCoords(int idx) {
46 0.5f + (idx / Width()) % Height(),
47 0.5f + idx / (Width() * Height())
51 void Invalidate() { dirty = true; }
53 Block &BlockAt(int index) { return blocks[index]; }
54 const Block &BlockAt(int index) const { return blocks[index]; }
55 Block &BlockAt(const glm::vec3 &pos) { return BlockAt(ToIndex(pos)); }
56 const Block &BlockAt(const glm::vec3 &pos) const { return BlockAt(ToIndex(pos)); }
62 float *dist = nullptr,
63 glm::vec3 *normal = nullptr) const;
65 void Position(const glm::vec3 &);
66 const glm::vec3 &Position() const { return position; }
67 glm::mat4 Transform(const glm::vec3 &offset) const;
72 int VertexCount() const;
76 std::vector<Block> blocks;