X-Git-Url: http://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fworld%2FPlanet.hpp;h=c109934d40e012989cfc6b806610df8821213327;hb=dd8b3145a03ed676b0ae6311c29fc3d68f666b15;hp=991985f968173e2eb98f0ddac4b4e3fcdaa9984f;hpb=b795a1df619349d45c3b0ca73e61e68ff483221c;p=blobs.git diff --git a/src/world/Planet.hpp b/src/world/Planet.hpp index 991985f..c109934 100644 --- a/src/world/Planet.hpp +++ b/src/world/Planet.hpp @@ -5,10 +5,11 @@ #include "Set.hpp" #include "Tile.hpp" -#include "../graphics/glm.hpp" #include "../graphics/SimpleVAO.hpp" +#include "../math/glm.hpp" #include +#include #include #include @@ -42,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. @@ -62,11 +65,28 @@ 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()); } - void Atmosphere(int a) noexcept { atmosphere = a; } - int Atmosphere() const noexcept { return atmosphere; } - bool HasAtmosphere() const noexcept { return atmosphere >= 0; } + // 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; + + static glm::dvec3 SurfaceNormal(int srf) noexcept { + glm::dvec3 nrm(0.0); + nrm[(srf + 2) % 3] = srf < 3 ? 1.0 : -1.0; + return nrm; + } + static glm::dmat3 SurfaceOrientation(int srf) noexcept { + glm::dmat3 mat(0.0); + mat[(srf + 0) % 3][0] = 1.0; + mat[(srf + 2) % 3][1] = srf < 3 ? 1.0 : -1.0; + mat[(srf + 1) % 3][2] = srf < 3 ? 1.0 : -1.0; + return mat; + } void BuildVAO(const Set &); void Draw(app::Assets &, graphics::Viewport &) override; @@ -75,13 +95,11 @@ private: int sidelength; std::vector tiles; - int atmosphere; - struct Attributes { glm::vec3 position; glm::vec3 tex_coord; }; - graphics::SimpleVAO vao; + std::unique_ptr> vao; };