1 #ifndef TACOS_WORLD_FLOOR_HPP_
2 #define TACOS_WORLD_FLOOR_HPP_
4 #include "../physics/ray.hpp"
16 /// width and depth in vertices, so will have one less
17 /// in each dimension in tiles
18 Floor(int width, int depth);
21 Floor(const Floor &) = delete;
22 Floor &operator =(const Floor &) = delete;
24 static constexpr int VAO_DIVISOR = 32;
26 int Width() const noexcept { return width; }
27 int Depth() const noexcept { return depth; }
29 int VAOWidth() const noexcept { return vao_width; }
30 int VAODepth() const noexcept { return vao_depth; }
32 glm::vec3 VAOPosition(int vao_x, int vao_z) const noexcept {
33 return glm::vec3(float(vao_x * VAO_DIVISOR), 0.0f, float(vao_z * VAO_DIVISOR));
35 void DrawVAO(int vao_x, int vao_z) const noexcept;
37 void SetElevation(int x, int z, float e) noexcept {
38 elevation[z * width + x] = e;
40 float GetElevation(int x, int z) const noexcept {
41 return elevation[z * width + x];
43 float ClampedElevation(int x, int z) const noexcept {
44 return GetElevation(glm::clamp(x, 0, width), glm::clamp(z, 0, depth));
46 glm::vec3 GetNormal(int x, int z) const noexcept;
48 void GenerateVertices();
50 /// check if ray intersects floor, write point of intersection to point
51 bool Intersection(const Ray &ray, glm::vec3 &point);
54 void SetupVAO(int which, GLuint element_buffer, int vertex_count) noexcept;
55 void FillElementBuffer(GLuint which, int tile_width, int tile_depth);
56 void FillAttribBuffer(int vao_x, int vao_z);
57 glm::ivec2 Tiles(int vao_x, int vao_z) const noexcept;
58 int NumTiles(int vao_x, int vao_z) const noexcept;
59 int NumVertices(int vao_x, int vao_z) const noexcept;
64 std::vector<float> elevation;
72 std::vector<GLuint> vaos;
73 // index of general element buffer
75 // index of unclean width element buffer, if any
76 int unclean_width_elements;
77 // index of unclean depth element buffer, if any
78 int unclean_depth_elements;
79 // index of unclean corner element buffer, if any
80 int unclean_corner_elements;
81 std::vector<GLuint> buffers;