X-Git-Url: http://git.localhorst.tv/?p=blobs.git;a=blobdiff_plain;f=src%2Fworld%2FPlanet.hpp;h=237159994c47da1c9dbd1e23bd235ffd2214cbb0;hp=7ac6b570256f7b256679b067ca8887489a4c3c59;hb=cd80d7cfcac3c58d601db2ab4e0381dd77c06f44;hpb=215c77b9d61ed635176edb86e54c6e87a1315dcf diff --git a/src/world/Planet.hpp b/src/world/Planet.hpp index 7ac6b57..2371599 100644 --- a/src/world/Planet.hpp +++ b/src/world/Planet.hpp @@ -35,16 +35,33 @@ public: Planet &operator =(Planet &&) = delete; public: + /// surface normal + glm::dvec3 NormalAt(const glm::dvec3 &p) const noexcept { return normalize(p); } + /// height over surface + double ElevationAt(const glm::dvec3 &p) const noexcept { return length(p) - Radius(); } + /// distance to planet center + double DistanceAt(const glm::dvec3 &p) const noexcept { return length(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; - const TileType &TypeAt(int surface, int x, int y) const; + /// 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(const Set &); + 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); @@ -52,10 +69,6 @@ public: 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(); @@ -65,38 +78,13 @@ public: return 6 * TilesPerSurface(); } - 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; - - 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; - private: int sidelength; std::vector tiles; struct Attributes { glm::vec3 position; + glm::vec3 normal; glm::vec3 tex_coord; }; std::unique_ptr> vao;