1 #ifndef BLOBS_WORLD_PLANET_HPP_
2 #define BLOBS_WORLD_PLANET_HPP_
8 #include "../graphics/SimpleVAO.hpp"
9 #include "../math/glm.hpp"
22 /// A planet has six surfaces, numbered 0 to 5, each filled with
23 /// sidelength² tiles.
28 explicit Planet(int sidelength);
31 Planet(const Planet &) = delete;
32 Planet &operator =(const Planet &) = delete;
34 Planet(Planet &&) = delete;
35 Planet &operator =(Planet &&) = delete;
39 glm::dvec3 NormalAt(const glm::dvec3 &p) const noexcept { return normalize(p); }
40 /// height over surface
41 double ElevationAt(const glm::dvec3 &p) const noexcept { return length(p) - Radius(); }
42 /// distance to planet center
43 double DistanceAt(const glm::dvec3 &p) const noexcept { return length(p); }
46 Tile &TileAt(const glm::dvec3 &) noexcept;
47 const Tile &TileAt(const glm::dvec3 &) const noexcept;
48 const TileType &TileTypeAt(const glm::dvec3 &) const noexcept;
50 /// Get the tile at given surface and coordinates.
51 Tile &TileAt(int surface, int x, int y) noexcept;
52 const Tile &TileAt(int surface, int x, int y) const noexcept;
53 const TileType &TypeAt(int surface, int x, int y) const noexcept;
55 /// The length in tiles of the side of each surface.
56 int SideLength() const { return sidelength; }
58 // center point of tile on surface at elevation
59 glm::dvec3 TileCenter(int surface, int x, int y, double elevation = 0.0) const noexcept;
61 void BuildVAO(const Set<TileType> &);
62 void Draw(app::Assets &, graphics::Viewport &) override;
65 /// Convert coordinates into a tile index.
66 int IndexOf(int surface, int x, int y) const {
67 assert(0 <= surface && surface <= 5);
68 assert(0 <= x && x < sidelength);
69 assert(0 <= y && y < sidelength);
70 return surface * TilesPerSurface() + y * SideLength() + x;
72 /// The number of tiles of one surface.
73 int TilesPerSurface() const {
74 return SideLength() * SideLength();
76 /// Total number of tiles of all surfaces combined.
77 int TilesTotal() const {
78 return 6 * TilesPerSurface();
83 std::vector<Tile> tiles;
90 std::unique_ptr<graphics::SimpleVAO<Attributes, unsigned int>> vao;
94 void GenerateEarthlike(const Set<TileType> &, Planet &) noexcept;
95 void GenerateTest(const Set<TileType> &, Planet &) noexcept;