-glm::dvec3 Planet::TileCenter(int surface, int x, int y) const noexcept {
- glm::dvec3 center(0.0f);
- center[(surface + 0) % 3] = x + 0.5 - Radius();
- center[(surface + 1) % 3] = y + 0.5 - Radius();
- center[(surface + 2) % 3] = surface < 3 ? Radius() : -Radius();
- return center;
+Tile &Planet::TileAt(const glm::dvec3 &p) noexcept {
+ int srf = 0;
+ double u = 0.0;
+ double v = 0.0;
+ cubemap(p, srf, u, v);
+ int x = glm::clamp(int(u * Radius() + Radius()), 0, sidelength - 1);
+ int y = glm::clamp(int(v * Radius() + Radius()), 0, sidelength - 1);
+ return TileAt(srf, x, y);
+}
+
+const Tile &Planet::TileAt(const glm::dvec3 &p) const noexcept {
+ int srf = 0;
+ double u = 0.0;
+ double v = 0.0;
+ cubemap(p, srf, u, v);
+ int x = glm::clamp(int(u * Radius() + Radius()), 0, sidelength - 1);
+ int y = glm::clamp(int(v * Radius() + Radius()), 0, sidelength - 1);
+ return TileAt(srf, x, y);
+}
+
+const TileType &Planet::TileTypeAt(const glm::dvec3 &p) const noexcept {
+ return GetSimulation().TileTypes()[TileAt(p).type];
+}
+
+Tile &Planet::TileAt(int surface, int x, int y) noexcept {
+ return tiles[IndexOf(surface, x, y)];
+}
+
+const Tile &Planet::TileAt(int surface, int x, int y) const noexcept {
+ return tiles[IndexOf(surface, x, y)];
+}
+
+const TileType &Planet::TypeAt(int srf, int x, int y) const noexcept {
+ return GetSimulation().TileTypes()[TileAt(srf, x, y).type];
+}
+
+glm::dvec3 Planet::TileCenter(int srf, int x, int y, double e) const noexcept {
+ double u = (double(x) - Radius() + 0.5) / Radius();
+ double v = (double(y) - Radius() + 0.5) / Radius();
+ return normalize(cubeunmap(srf, u, v)) * (Radius() + e);