1 #ifndef BLOBS_WORLD_PLANET_HPP_
2 #define BLOBS_WORLD_PLANET_HPP_
8 #include "../graphics/glm.hpp"
9 #include "../graphics/SimpleVAO.hpp"
21 /// A planet has six surfaces, numbered 0 to 5, each filled with
22 /// sidelength² tiles.
27 explicit Planet(int sidelength);
30 Planet(const Planet &) = delete;
31 Planet &operator =(const Planet &) = delete;
33 Planet(Planet &&) = delete;
34 Planet &operator =(Planet &&) = delete;
37 /// Get the tile at given surface and coordinates.
38 Tile &TileAt(int surface, int x, int y) {
39 return tiles[IndexOf(surface, x, y)];
41 const Tile &TileAt(int surface, int x, int y) const {
42 return tiles[IndexOf(surface, x, y)];
45 const TileType &TypeAt(int surface, int x, int y) const;
47 /// Convert coordinates into a tile index.
48 int IndexOf(int surface, int x, int y) const {
49 assert(0 <= surface && surface <= 5);
50 assert(0 <= x && x <= sidelength);
51 assert(0 <= y && y <= sidelength);
52 return surface * TilesPerSurface() + y * SideLength() + x;
54 /// The length of the side of each surface.
55 int SideLength() const {
58 /// The number of tiles of one surface.
59 int TilesPerSurface() const {
60 return SideLength() * SideLength();
62 /// Total number of tiles of all surfaces combined.
63 int TilesTotal() const {
64 return 6 * TilesPerSurface();
67 glm::dvec3 TileCenter(int surface, int x, int y) const noexcept;
69 void BuildVAO(const Set<TileType> &);
70 void Draw(app::Assets &, graphics::Viewport &) override;
74 std::vector<Tile> tiles;
80 graphics::SimpleVAO<Attributes, unsigned int> vao;
84 void GenerateEarthlike(const Set<TileType> &, Planet &) noexcept;
85 void GenerateTest(const Set<TileType> &, Planet &) noexcept;