-void Planet::BuildVAO(const TileSet &ts) {
- vao.Bind();
- vao.BindAttributes();
- vao.EnableAttribute(0);
- vao.EnableAttribute(1);
- vao.AttributePointer<glm::vec3>(0, false, offsetof(Attributes, position));
- vao.AttributePointer<glm::vec3>(1, false, offsetof(Attributes, tex_coord));
- vao.ReserveAttributes(TilesTotal() * 4, GL_STATIC_DRAW);
+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);
+}
+
+void Planet::BuildVAO(const Set<TileType> &ts) {
+ vao.reset(new graphics::SimpleVAO<Attributes, unsigned int>);
+ vao->Bind();
+ vao->BindAttributes();
+ vao->EnableAttribute(0);
+ vao->EnableAttribute(1);
+ vao->EnableAttribute(2);
+ vao->AttributePointer<glm::vec3>(0, false, offsetof(Attributes, position));
+ vao->AttributePointer<glm::vec3>(1, false, offsetof(Attributes, normal));
+ vao->AttributePointer<glm::vec3>(2, false, offsetof(Attributes, tex_coord));
+ vao->ReserveAttributes(TilesTotal() * 4, GL_STATIC_DRAW);