X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FPlanet.hpp;h=28ecaa03cd206a0e254685928dabeb398203af07;hb=8f6530c75730f901efd6708e4fde7e68a178adf1;hp=efc804dae6a88e91cbbacafcbfd2c3cd38798bab;hpb=592c7e6d616f2cfacfd4948e17a4bb72f6444488;p=blobs.git diff --git a/src/world/Planet.hpp b/src/world/Planet.hpp index efc804d..28ecaa0 100644 --- a/src/world/Planet.hpp +++ b/src/world/Planet.hpp @@ -3,19 +3,21 @@ #include "Body.hpp" +#include "Set.hpp" #include "Tile.hpp" -#include "../graphics/glm.hpp" #include "../graphics/SimpleVAO.hpp" +#include "../math/glm.hpp" #include #include +#include #include namespace blobs { namespace world { -struct Tile; +class TileType; /// A planet has six surfaces, numbered 0 to 5, each filled with /// sidelength² tiles. @@ -41,11 +43,13 @@ public: return tiles[IndexOf(surface, x, y)]; } + const TileType &TypeAt(int surface, int x, int y) const; + /// Convert coordinates into a tile index. int IndexOf(int surface, int x, int y) const { assert(0 <= surface && surface <= 5); - assert(0 <= x && x <= sidelength); - assert(0 <= y && y <= sidelength); + assert(0 <= x && x < sidelength); + assert(0 <= y && y < sidelength); return surface * TilesPerSurface() + y * SideLength() + x; } /// The length of the side of each surface. @@ -61,25 +65,33 @@ public: return 6 * TilesPerSurface(); } - glm::dvec3 TileCenter(int surface, int x, int y) const noexcept; + double TileToPosition(int t) const noexcept { return double(t) - Radius(); } + int PositionToTile(double p) const noexcept { return int(p + Radius()); } + + // tile coordinates of position on surface + glm::ivec2 SurfacePosition(int surface, const glm::dvec3 &) const noexcept; + // height of point over surface + double SurfaceElevation(int surface, const glm::dvec3 &) const noexcept; + // center point of tile on surface at elevation + glm::dvec3 TileCenter(int surface, int x, int y, double elevation = 0.0) const noexcept; - void BuildVAOs(); + void BuildVAO(const Set &); void Draw(app::Assets &, graphics::Viewport &) override; private: int sidelength; - std::unique_ptr tiles; + std::vector tiles; struct Attributes { glm::vec3 position; glm::vec3 tex_coord; }; - graphics::SimpleVAO vao; + std::unique_ptr> vao; }; -void GenerateEarthlike(Planet &) noexcept; -void GenerateTest(Planet &) noexcept; +void GenerateEarthlike(const Set &, Planet &) noexcept; +void GenerateTest(const Set &, Planet &) noexcept; } }