1 #ifndef TACOS_WORLD_FLOOR_HPP_
2 #define TACOS_WORLD_FLOOR_HPP_
14 /// width and depth in vertices, so will have one less
15 /// in each dimension in tiles
16 Floor(int width, int depth);
19 Floor(const Floor &) = delete;
20 Floor &operator =(const Floor &) = delete;
22 static constexpr int VAO_DIVISOR = 32;
24 int Width() const noexcept { return width; }
25 int Depth() const noexcept { return depth; }
27 int VAOWidth() const noexcept { return vao_width; }
28 int VAODepth() const noexcept { return vao_depth; }
30 glm::vec3 VAOPosition(int vao_x, int vao_z) const noexcept {
31 return glm::vec3(float(vao_x * VAO_DIVISOR), 0.0f, float(vao_z * VAO_DIVISOR));
33 void DrawVAO(int vao_x, int vao_z) const noexcept;
35 void SetElevation(int x, int z, float e) noexcept {
36 elevation[z * width + x] = e;
38 float GetElevation(int x, int z) const noexcept {
39 return elevation[z * width + x];
41 float ClampedElevation(int x, int z) const noexcept {
42 return GetElevation(glm::clamp(x, 0, width), glm::clamp(z, 0, depth));
44 glm::vec3 GetNormal(int x, int z) const noexcept;
46 void GenerateVertices();
49 void SetupVAO(int which, GLuint element_buffer, int vertex_count) noexcept;
50 void FillElementBuffer(GLuint which, int tile_width, int tile_depth);
51 void FillAttribBuffer(int vao_x, int vao_z);
52 glm::ivec2 Tiles(int vao_x, int vao_z) const noexcept;
53 int NumTiles(int vao_x, int vao_z) const noexcept;
54 int NumVertices(int vao_x, int vao_z) const noexcept;
59 std::vector<float> elevation;
67 std::vector<GLuint> vaos;
68 // index of general element buffer
70 // index of unclean width element buffer, if any
71 int unclean_width_elements;
72 // index of unclean depth element buffer, if any
73 int unclean_depth_elements;
74 // index of unclean corner element buffer, if any
75 int unclean_corner_elements;
76 std::vector<GLuint> buffers;