X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FPlanet.hpp;h=af3b512aea6b058bc97b4dadb7435b0bc65d4347;hb=bcf776b6d51aeb9147bde32da8dd0768b10db993;hp=6106ccf06aa8a770d5928b4e1def95a1c8463a7c;hpb=91dfd6cd62ea0723c3c83572b4ebfa4ef7b4ac5f;p=blobs.git diff --git a/src/world/Planet.hpp b/src/world/Planet.hpp index 6106ccf..af3b512 100644 --- a/src/world/Planet.hpp +++ b/src/world/Planet.hpp @@ -1,31 +1,38 @@ #ifndef BLOBS_WORLD_PLANET_HPP_ #define BLOBS_WORLD_PLANET_HPP_ +#include "Body.hpp" + +#include "Set.hpp" #include "Tile.hpp" +#include "../graphics/glm.hpp" +#include "../graphics/SimpleVAO.hpp" #include -#include +#include +#include namespace blobs { namespace world { -struct Tile; +class TileType; -/// A planet has six surfaces, numbered 0 to 5, each with tiles from -/// +radius to -radius. -class Planet { +/// A planet has six surfaces, numbered 0 to 5, each filled with +/// sidelength² tiles. +class Planet +: public Body { public: - explicit Planet(int radius); + explicit Planet(int sidelength); ~Planet(); - Planet(Planet &&); - Planet &operator =(Planet &&); - Planet(const Planet &) = delete; Planet &operator =(const Planet &) = delete; + Planet(Planet &&) = delete; + Planet &operator =(Planet &&) = delete; + public: /// Get the tile at given surface and coordinates. Tile &TileAt(int surface, int x, int y) { @@ -38,38 +45,42 @@ public: /// Convert coordinates into a tile index. int IndexOf(int surface, int x, int y) const { assert(0 <= surface && surface <= 5); - assert(-radius <= x && x <= radius); - assert(-radius <= y && y <= radius); - return surface * SurfaceArea() + ToOffset(y) * SideLength() + ToOffset(x); - } - /// Convert coordinate into offset - int ToOffset(int c) const { - return c + radius; - } - /// The "radius" of the planet. - int Radius() const { - return radius; + assert(0 <= x && x <= sidelength); + assert(0 <= y && y <= sidelength); + return surface * TilesPerSurface() + y * SideLength() + x; } /// The length of the side of each surface. int SideLength() const { - return 2 * radius + 1; + return sidelength; } - /// The area (or number of tiles) of one surface - int SurfaceArea() const { + /// The number of tiles of one surface. + int TilesPerSurface() const { return SideLength() * SideLength(); } - /// Total area of all surfaces combined. - int TotalArea() const { - return 6 * SurfaceArea(); + /// Total number of tiles of all surfaces combined. + int TilesTotal() const { + return 6 * TilesPerSurface(); } + glm::dvec3 TileCenter(int surface, int x, int y) const noexcept; + + void BuildVAO(const Set &); + void Draw(app::Assets &, graphics::Viewport &) override; + private: - int radius; - std::unique_ptr tiles; + int sidelength; + std::vector tiles; + + struct Attributes { + glm::vec3 position; + glm::vec3 tex_coord; + }; + graphics::SimpleVAO vao; }; -void GenerateTest(Planet &); +void GenerateEarthlike(const Set &, Planet &) noexcept; +void GenerateTest(const Set &, Planet &) noexcept; } }