X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FPlanet.hpp;h=3677ca4c92aeccd29e950920bc7461ca6c7c964f;hb=HEAD;hp=a95238a914338851df9dee7120c494310c2c684a;hpb=02d5571eef7630c38968af264a441aa43e802d0f;p=blobs.git diff --git a/src/world/Planet.hpp b/src/world/Planet.hpp index a95238a..3677ca4 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 { -class TileSet; +class TileType; /// A planet has six surfaces, numbered 0 to 5, each filled with /// sidelength² tiles. @@ -33,25 +35,42 @@ public: Planet &operator =(Planet &&) = delete; public: + /// surface normal + glm::dvec3 NormalAt(const glm::dvec3 &p) const noexcept { return glm::normalize(p); } + /// height over surface + double ElevationAt(const glm::dvec3 &p) const noexcept { return glm::length(p) - Radius(); } + /// distance to planet center + double DistanceAt(const glm::dvec3 &p) const noexcept { return glm::length(p); } + /// acceleration due to gravity at given point + glm::dvec3 GravityAt(const glm::dvec3 &p) const noexcept { return NormalAt(p) * (-GravitationalParameter() / glm::length2(p)); } + + /// get ground tile + Tile &TileAt(const glm::dvec3 &) noexcept; + const Tile &TileAt(const glm::dvec3 &) const noexcept; + const TileType &TileTypeAt(const glm::dvec3 &) const noexcept; + /// Get the tile at given surface and coordinates. - Tile &TileAt(int surface, int x, int y) { - return tiles[IndexOf(surface, x, y)]; - } - const Tile &TileAt(int surface, int x, int y) const { - return tiles[IndexOf(surface, x, y)]; - } + Tile &TileAt(int surface, int x, int y) noexcept; + const Tile &TileAt(int surface, int x, int y) const noexcept; + const TileType &TypeAt(int surface, int x, int y) const noexcept; + + /// The length in tiles of the side of each surface. + int SideLength() const { return sidelength; } + + // center point of tile on surface at elevation + glm::dvec3 TileCenter(int surface, int x, int y, double elevation = 0.0) const noexcept; + + void BuildVAO(); + void Draw(app::Assets &, graphics::Viewport &) override; +private: /// 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. - int SideLength() const { - return sidelength; - } /// The number of tiles of one surface. int TilesPerSurface() const { return SideLength() * SideLength(); @@ -61,25 +80,24 @@ public: return 6 * TilesPerSurface(); } - glm::dvec3 TileCenter(int surface, int x, int y) const noexcept; - - void BuildVAOs(const TileSet &); - void Draw(app::Assets &, graphics::Viewport &) override; - private: int sidelength; - std::unique_ptr tiles; + std::vector tiles; struct Attributes { glm::vec3 position; + glm::vec3 normal; glm::vec3 tex_coord; + float shiny; + float glossy; + float metallic; }; - graphics::SimpleVAO vao; + std::unique_ptr> vao; }; -void GenerateEarthlike(const TileSet &, Planet &) noexcept; -void GenerateTest(const TileSet &, Planet &) noexcept; +void GenerateEarthlike(const Set &, Planet &) noexcept; +void GenerateTest(const Set &, Planet &) noexcept; } }