The ground, its stands, facilities and periphery are built as bodies from the stadium overview, seen through an axonometric camera, sorted by depth and drawn as a vector picture. A click chooses the bowl, a stand, the floodlights or a house; the camera flies there in 0.6 seconds (reduced motion jumps) and a card shows what stands there and leads to the builder's offer. Stands are as deep as they have places, seats take the club's colour, a roof and scaffolding show, and what may still be built is a dashed footprint. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
340 lines
20 KiB
C++
340 lines
20 KiB
C++
// SPDX-License-Identifier: GPL-3.0-only
|
|
#pragma once
|
|
// The stadium and its surroundings as a card model: bodies built from the blocks,
|
|
// facilities and periphery of the stadium overview, seen through a camera, sorted by depth
|
|
// and drawn as a vector picture. No renderer is involved: the same picture comes out on
|
|
// every platform, and the same input always gives the same picture.
|
|
//
|
|
// World: x east, y north, z up, the centre spot at the origin; lengths roughly in metres.
|
|
// Camera: an axonometric view (no perspective) turned by `yaw` around the vertical axis and
|
|
// raised by `pitch` above the ground, both in degrees.
|
|
#include "modern/ui/catalog.hpp"
|
|
#include <algorithm>
|
|
#include <array>
|
|
#include <cmath>
|
|
#include <map>
|
|
#include <sstream>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace bmh::modern_ui::stadium3d {
|
|
struct Vec { double x = 0, y = 0, z = 0; };
|
|
struct Camera { double yaw = 28, pitch = 40, zoom = 1, tx = 0, ty = 0; };
|
|
struct Face {
|
|
std::vector<Vec> points;
|
|
std::string fill; // "#rrggbb"; empty for an outline
|
|
std::string part; // the selectable part it belongs to, e.g. "block:3"
|
|
bool dashed = false, open = false, flat = false; // flat: keep the fill as it is (no shading)
|
|
double stroke = 2, opacity = 1;
|
|
std::string ink; // stroke colour; empty: the scene's ink
|
|
std::vector<std::vector<Vec>> lines; // drawn on the face, in its ink at 40 %
|
|
double bias = 0; // moves the face towards the viewer in the depth order
|
|
};
|
|
struct Part { std::string id; Vec centre; double x0 = 0, y0 = 0, x1 = 0, y1 = 0, cx = 0, cy = 0; bool seen = false; };
|
|
struct Anchor { std::string id; double x = 0, y = 0; };
|
|
// centres: where a part's name stands and the camera flies to; anchors: every spot a click
|
|
// may choose the part at (the four masts of the floodlights are four anchors of one part)
|
|
struct Scene { std::vector<Face> faces; std::map<std::string, Vec> centres; std::vector<std::pair<std::string, Vec>> anchors; std::string ink = "#3d362a", accent = "#25617a"; };
|
|
struct Drawing { std::string svg; std::vector<Part> parts; std::vector<Anchor> anchors; };
|
|
|
|
inline std::string num(double value) {
|
|
std::ostringstream out;
|
|
out.imbue(std::locale::classic());
|
|
out << std::round(value * 10) / 10;
|
|
return out.str();
|
|
}
|
|
inline std::string shade(const std::string &colour, double factor) {
|
|
if (colour.size() != 7 || colour[0] != '#') return colour;
|
|
std::string out = "#";
|
|
for (size_t at = 1; at < 7; at += 2) {
|
|
const int value = std::clamp(int(std::lround(std::stoi(colour.substr(at, 2), nullptr, 16) * factor)), 0, 255);
|
|
static constexpr char digits[] = "0123456789abcdef";
|
|
out += digits[value / 16];
|
|
out += digits[value % 16];
|
|
}
|
|
return out;
|
|
}
|
|
inline Camera mix(const Camera &a, const Camera &b, double t) {
|
|
const double s = t * t * (3 - 2 * t); // ease in and out
|
|
double turn = std::fmod(b.yaw - a.yaw, 360.0);
|
|
if (turn > 180) turn -= 360;
|
|
if (turn < -180) turn += 360;
|
|
return {a.yaw + turn * s, a.pitch + (b.pitch - a.pitch) * s, a.zoom + (b.zoom - a.zoom) * s, a.tx + (b.tx - a.tx) * s, a.ty + (b.ty - a.ty) * s};
|
|
}
|
|
|
|
// The eight stands lie on a ring around the pitch; angles in degrees, counted from the east
|
|
// towards the south (as on the plan: A north-west, B north, ... H west).
|
|
constexpr std::array<std::array<double, 2>, 8> spans{{{{205, 245}}, {{245, 295}}, {{295, 335}}, {{-25, 25}}, {{25, 65}}, {{65, 115}}, {{115, 155}}, {{155, 205}}}};
|
|
inline Vec ring(double degrees, double offset, double z) {
|
|
const double a = degrees * 3.14159265358979 / 180;
|
|
return {(74 + offset) * std::cos(a), -(52 + offset) * std::sin(a), z};
|
|
}
|
|
inline double stand_depth(int64_t places, int64_t greatest) { return 12 + 44.0 * double(std::max<int64_t>(0, places)) / double(std::max<int64_t>(1, greatest)); }
|
|
|
|
inline void box(Scene &scene, const std::string &part, double x, double y, double w, double d, double h, const std::string &fill, bool planned = false, double z = 0) {
|
|
const Vec a{x - w / 2, y - d / 2, z}, b{x + w / 2, y - d / 2, z}, c{x + w / 2, y + d / 2, z}, e{x - w / 2, y + d / 2, z};
|
|
if (planned) { // not built: its footprint only
|
|
scene.faces.push_back({{a, b, c, e}, "", part, true, false, false, 2.5, .8, "", {}, 2});
|
|
return;
|
|
}
|
|
const auto up = [&](Vec v) { v.z = z + h; return v; };
|
|
for (const auto &[p, q] : std::array<std::pair<Vec, Vec>, 4>{{{a, b}, {b, c}, {c, e}, {e, a}}})
|
|
scene.faces.push_back({{p, q, up(q), up(p)}, fill, part});
|
|
scene.faces.push_back({{up(a), up(b), up(c), up(e)}, fill, part});
|
|
}
|
|
|
|
// Builds the model. `seats` is the club's colour; `paper` selects the light skin's tones.
|
|
inline Scene build(const Json &overview, const std::string &seats, bool paper) {
|
|
Scene scene;
|
|
scene.ink = paper ? "#3d362a" : "#d5dde3";
|
|
scene.accent = paper ? "#25617a" : "#9ac7d8";
|
|
const std::string plate = paper ? "#efe4c8" : "#27323c", wall = paper ? "#f6efdc" : "#55616c", terrace = paper ? "#d6ccb4" : "#6a7680",
|
|
roof = paper ? "#5a646e" : "#161d24", glass = "#9fc4d6", gold = "#c9962e", lamp = "#f3d778";
|
|
const auto level_of = [](const Json &row) { return row.value("display_level", row.value("level", 0)); };
|
|
const auto building = [](const Json &row) { return row.value("building", false); };
|
|
// the plate everything stands on
|
|
scene.faces.push_back({{{-350, -262, 0}, {350, -262, 0}, {350, 262, 0}, {-350, 262, 0}}, plate, "", false, false, true, 3, 1, "", {}, -1000});
|
|
// the pitch: its colour tells the state of the turf (facility 4)
|
|
const auto &facilities = overview.value("facilities", Json::array());
|
|
const auto facility = [&](size_t index) -> const Json & { static const Json none = Json::object(); return index < facilities.size() ? facilities[index] : none; };
|
|
const int turf = facilities.size() > 4 ? level_of(facility(4)) : 3;
|
|
const std::array<std::array<const char *, 2>, 5> greens{{{"#a39a5c", "#b3a868"}, {"#8f9e58", "#9dab62"}, {"#6fa25c", "#7bae66"}, {"#4f9a5c", "#57a765"}, {"#3f9456", "#49a260"}}};
|
|
const auto &green = greens[size_t(std::clamp(turf, 0, 4))];
|
|
{
|
|
std::vector<Vec> oval;
|
|
for (int a = 0; a < 360; a += 10) oval.push_back(ring(a, -4, 0));
|
|
scene.faces.push_back({oval, paper ? "#e2d6b8" : "#323e49", "", false, false, true, 2.5, 1, "", {}, -900});
|
|
for (int stripe = 0; stripe < 10; ++stripe) {
|
|
const double x0 = -52.5 + stripe * 10.5;
|
|
Face f{{{x0, -34, 0}, {x0 + 10.5, -34, 0}, {x0 + 10.5, 34, 0}, {x0, 34, 0}}, green[size_t(stripe % 2)], "facility:4", false, false, true, 0, 1, "", {}, -800};
|
|
scene.faces.push_back(f);
|
|
}
|
|
Face lines{{{-52.5, -34, 0}, {52.5, -34, 0}, {52.5, 34, 0}, {-52.5, 34, 0}}, "", "facility:4", false, false, true, 3, 1, "#f4f7ef", {}, -700};
|
|
scene.faces.push_back(lines);
|
|
scene.faces.push_back({{{0, -34, 0}, {0, 34, 0}}, "", "", false, true, true, 3, 1, "#f4f7ef", {}, -700});
|
|
std::vector<Vec> circle;
|
|
for (int a = 0; a <= 360; a += 20) circle.push_back({9.15 * std::cos(a * 3.14159265 / 180), 9.15 * std::sin(a * 3.14159265 / 180), 0});
|
|
scene.faces.push_back({circle, "", "", false, true, true, 3, 1, "#f4f7ef", {}, -700});
|
|
for (const double side : {-1.0, 1.0})
|
|
scene.faces.push_back({{{side * 52.5, -20, 0}, {side * 36, -20, 0}, {side * 36, 20, 0}, {side * 52.5, 20, 0}}, "", "", false, true, true, 3, 1, "#f4f7ef", {}, -700});
|
|
// turf heating (facility 2): pipes under the grass show through
|
|
if (facilities.size() > 2 && level_of(facility(2)) > 1)
|
|
for (double y = -28; y <= 28; y += 8)
|
|
scene.faces.push_back({{{-48, y, 0}, {48, y, 0}}, "", "facility:2", true, true, true, 2.5, .7, "#c8553d", {}, -650});
|
|
scene.centres["facility:4"] = {0, 0, 0};
|
|
}
|
|
// the stands
|
|
const auto &blocks = overview.at("blocks");
|
|
int64_t greatest = 1;
|
|
for (const auto &b : blocks) greatest = std::max(greatest, b.at("max_places").get<int64_t>());
|
|
double deepest = 0;
|
|
for (size_t i = 0; i < 8 && i < blocks.size(); ++i) {
|
|
const auto &b = blocks[i];
|
|
const std::string part = "block:" + std::to_string(i);
|
|
const double from = spans[i][0] + 1.6, to = spans[i][1] - 1.6, inner = 5;
|
|
const double depth = stand_depth(b.at("display_places").get<int64_t>(), greatest), most = stand_depth(b.at("max_places").get<int64_t>(), greatest);
|
|
const double top = 3 + depth * .58, outer = inner + depth;
|
|
deepest = std::max(deepest, inner + most);
|
|
const bool seated = b.at("display_seats").get<bool>(), roofed = b.at("display_roof").get<bool>();
|
|
const std::string tread = seated ? seats : terrace;
|
|
const int steps = 4;
|
|
for (int s = 0; s < steps; ++s) {
|
|
const double a0 = from + (to - from) * s / steps, a1 = from + (to - from) * (s + 1) / steps;
|
|
Face slope{{ring(a0, inner, 2), ring(a1, inner, 2), ring(a1, outer, top), ring(a0, outer, top)}, tread, part};
|
|
for (int row = 1; row < 5; ++row) { // rows of seats, or the steps of a terrace
|
|
const double t = row / 5.0;
|
|
slope.lines.push_back({ring(a0, inner + depth * t, 2 + (top - 2) * t), ring(a1, inner + depth * t, 2 + (top - 2) * t)});
|
|
}
|
|
scene.faces.push_back(slope);
|
|
scene.faces.push_back({{ring(a0, outer, 0), ring(a1, outer, 0), ring(a1, outer, top), ring(a0, outer, top)}, wall, part});
|
|
scene.faces.push_back({{ring(a0, inner, 0), ring(a1, inner, 0), ring(a1, inner, 2), ring(a0, inner, 2)}, wall, part});
|
|
if (roofed) {
|
|
const double edge = inner + depth * .45, height = top + 7;
|
|
Face slab{{ring(a0, edge, height + 2), ring(a1, edge, height + 2), ring(a1, outer + 3, height), ring(a0, outer + 3, height)}, roof, part};
|
|
slab.bias = 6;
|
|
slab.lines.push_back({ring(a0, outer, top), ring(a0, outer + 1, height)}); // a post
|
|
scene.faces.push_back(slab);
|
|
}
|
|
}
|
|
for (const double a : {from, to})
|
|
scene.faces.push_back({{ring(a, inner, 0), ring(a, inner, 2), ring(a, outer, top), ring(a, outer, 0)}, wall, part});
|
|
// how far the stand may grow: its footprint as a dashed line
|
|
std::vector<Vec> limit;
|
|
for (int s = 0; s <= steps; ++s) limit.push_back(ring(from + (to - from) * s / steps, inner + most, 0));
|
|
limit.push_back(ring(to, outer, 0));
|
|
limit.insert(limit.begin(), ring(from, outer, 0));
|
|
scene.faces.push_back({limit, "", part, true, true, true, 2.5, .55, "", {}, 0});
|
|
if (building(b)) { // a frame of scaffolding at the size being built
|
|
const double target = inner + stand_depth(b.at("job").value("places", b.at("display_places").get<int64_t>()), greatest);
|
|
const double height = 3 + (target - inner) * .58;
|
|
for (int s = 0; s < steps; ++s) {
|
|
const double a0 = from + (to - from) * s / steps, a1 = from + (to - from) * (s + 1) / steps;
|
|
Face frame{{ring(a0, target + 2, 0), ring(a1, target + 2, 0), ring(a1, target + 2, height + 9), ring(a0, target + 2, height + 9)}, gold, part, true, false, true, 3, .28, gold, {}, 4};
|
|
scene.faces.push_back(frame);
|
|
}
|
|
}
|
|
scene.centres[part] = ring((from + to) / 2, inner + depth / 2, top / 2);
|
|
}
|
|
// facility 0: four floodlight masts, taller and brighter with every level
|
|
if (!facilities.empty()) {
|
|
const int level = level_of(facility(0));
|
|
for (const double a : {45.0, 135.0, 225.0, 315.0}) {
|
|
const Vec foot = ring(a, deepest + 16, 0);
|
|
const double height = 34 + 9 * level;
|
|
if (level <= 0) { box(scene, "facility:0", foot.x, foot.y, 8, 8, 1, wall, true); continue; }
|
|
scene.faces.push_back({{foot, {foot.x, foot.y, height}}, "", "facility:0", false, true, true, 5, 1, "", {}, 3});
|
|
const double w = 7 + 2 * level, h = 4 + 1.5 * level;
|
|
const double nx = -foot.y / std::hypot(foot.x, foot.y), ny = foot.x / std::hypot(foot.x, foot.y);
|
|
Face panel{{{foot.x - nx * w, foot.y - ny * w, height - h}, {foot.x + nx * w, foot.y + ny * w, height - h}, {foot.x + nx * w, foot.y + ny * w, height + h}, {foot.x - nx * w, foot.y - ny * w, height + h}},
|
|
lamp, "facility:0", false, false, true, 2.5, 1, "", {}, 5};
|
|
for (int row = 1; row <= level; ++row) panel.lines.push_back({{foot.x - nx * w, foot.y - ny * w, height - h + 2 * h * row / (level + 1)}, {foot.x + nx * w, foot.y + ny * w, height - h + 2 * h * row / (level + 1)}});
|
|
scene.faces.push_back(panel);
|
|
scene.anchors.push_back({"facility:0", {foot.x, foot.y, height}});
|
|
}
|
|
scene.centres["facility:0"] = ring(45, deepest + 16, 30);
|
|
}
|
|
// facility 1: the score board behind the east curve
|
|
if (facilities.size() > 1) {
|
|
const int level = level_of(facility(1));
|
|
const Vec at = ring(0, deepest + 14, 0);
|
|
if (level <= 0) box(scene, "facility:1", at.x, at.y, 6, 30, 1, wall, true);
|
|
else {
|
|
box(scene, "facility:1", at.x, at.y - 12, 2, 2, 14, wall);
|
|
box(scene, "facility:1", at.x, at.y + 12, 2, 2, 14, wall);
|
|
box(scene, "facility:1", at.x, at.y, 4, 26 + 4 * level, 8 + 3 * level, "#2c3640", false, 14);
|
|
}
|
|
scene.centres["facility:1"] = {at.x, at.y, 16};
|
|
}
|
|
// facility 3: the lounge, a glass box on the south stand
|
|
if (facilities.size() > 3 && blocks.size() > 5) {
|
|
const int level = level_of(facility(3)) - 1;
|
|
const Vec at = ring(90, 5 + stand_depth(blocks[5].at("display_places").get<int64_t>(), greatest) + 9, 0);
|
|
if (level <= 0) box(scene, "facility:3", at.x, at.y, 40, 10, 1, wall, true);
|
|
else box(scene, "facility:3", at.x, at.y, 34 + 8 * level, 10, 6 + 4 * level, glass);
|
|
scene.centres["facility:3"] = {at.x, at.y, 8};
|
|
}
|
|
// facilities 2, 5, 6, 7 as small houses beside the ground: boiler, kiosks, workshop, gate
|
|
const std::array<std::tuple<size_t, double, double, const char *>, 4> houses{{{2, -150, -150, "#c8a58a"}, {5, 150, -150, "#d9c38a"}, {6, -150, 150, "#b9b3a2"}, {7, 150, 150, "#a9b7a0"}}};
|
|
for (const auto &[index, x, y, colour] : houses) {
|
|
if (index >= facilities.size()) continue;
|
|
const std::string part = "facility:" + std::to_string(index);
|
|
const int level = level_of(facility(index)) - (index == 2 || index == 5 ? 1 : 0);
|
|
if (level <= 0) box(scene, part, x, y, 26, 18, 1, wall, true);
|
|
else
|
|
for (int n = 0; n < std::min(level, 4); ++n) box(scene, part, x + (n - (std::min(level, 4) - 1) / 2.0) * 20, y, 16, 16, 7 + 2 * level, colour);
|
|
scene.centres[part] = {x, y, 6};
|
|
}
|
|
// the periphery on an outer ring: a house per object, growing with its level
|
|
const auto &periphery = overview.value("periphery", Json::array());
|
|
for (size_t i = 0; i < periphery.size(); ++i) {
|
|
const std::string part = "periphery:" + std::to_string(i);
|
|
const double a = (360.0 * double(i) / double(std::max<size_t>(1, periphery.size())) + 20) * 3.14159265358979 / 180;
|
|
const double x = 292 * std::cos(a), y = 214 * std::sin(a);
|
|
const int level = periphery[i].value("level", 0);
|
|
static constexpr std::array<const char *, 6> tones{"#c9b48c", "#b7c4a8", "#c8a79a", "#a9bccb", "#d2c08f", "#bfb2c4"};
|
|
if (level <= 0) box(scene, part, x, y, 44, 30, 1, wall, true);
|
|
else {
|
|
box(scene, part, x, y, 30 + 6 * level, 22 + 3 * level, 6 + 5 * level, tones[i % tones.size()]);
|
|
if (building(periphery[i])) box(scene, part, x, y, 40 + 6 * level, 30 + 3 * level, 1, gold, true);
|
|
}
|
|
scene.centres[part] = {x, y, 6};
|
|
}
|
|
scene.centres["stadium"] = {0, 0, 0};
|
|
for (const auto &[id, centre] : scene.centres)
|
|
if (id != "stadium" && id != "facility:0") scene.anchors.push_back({id, centre});
|
|
return scene;
|
|
}
|
|
|
|
// Draws the scene. Faces of `highlight` get an accented outline; `parts` lists where every
|
|
// selectable part lies in the picture (in its own units, 0..width and 0..height).
|
|
inline Drawing draw(const Scene &scene, const Camera &camera, double width, double height, const std::string &highlight = {}) {
|
|
const double yaw = camera.yaw * 3.14159265358979 / 180, pitch = camera.pitch * 3.14159265358979 / 180;
|
|
const double cs = std::cos(yaw), sn = std::sin(yaw), sp = std::sin(pitch), cp = std::cos(pitch);
|
|
const double scale = camera.zoom * height / 620.0;
|
|
struct Flat { double x, y, depth; };
|
|
const auto project = [&](const Vec &v) {
|
|
const double x = (v.x - camera.tx) * cs - (v.y - camera.ty) * sn, y = (v.x - camera.tx) * sn + (v.y - camera.ty) * cs;
|
|
return Flat{width / 2 + x * scale, height / 2 - (y * sp + v.z * cp) * scale, y * cp - v.z * sp};
|
|
};
|
|
struct Item { const Face *face; double depth; };
|
|
std::vector<Item> order;
|
|
order.reserve(scene.faces.size());
|
|
for (const auto &face : scene.faces) {
|
|
double depth = 0;
|
|
for (const auto &p : face.points) depth += project(p).depth;
|
|
order.push_back({&face, depth / double(std::max<size_t>(1, face.points.size())) - face.bias});
|
|
}
|
|
std::stable_sort(order.begin(), order.end(), [](const Item &a, const Item &b) { return a.depth > b.depth; });
|
|
std::map<std::string, Part> parts;
|
|
Drawing out;
|
|
out.svg = "<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 " + num(width) + " " + num(height) + "\">";
|
|
const Vec light{-0.42, -0.5, 0.76};
|
|
for (const auto &item : order) {
|
|
const auto &face = *item.face;
|
|
std::string path;
|
|
for (size_t i = 0; i < face.points.size(); ++i) {
|
|
const auto p = project(face.points[i]);
|
|
path += (i ? "L" : "M") + num(p.x) + " " + num(p.y);
|
|
if (!face.part.empty()) {
|
|
auto &part = parts[face.part];
|
|
if (!part.seen) { part.id = face.part; part.x0 = part.x1 = p.x; part.y0 = part.y1 = p.y; part.seen = true; }
|
|
part.x0 = std::min(part.x0, p.x); part.x1 = std::max(part.x1, p.x); part.y0 = std::min(part.y0, p.y); part.y1 = std::max(part.y1, p.y);
|
|
}
|
|
}
|
|
if (!face.open) path += "Z";
|
|
std::string fill = "none";
|
|
if (!face.fill.empty()) {
|
|
double factor = 1;
|
|
if (!face.flat && face.points.size() >= 3) {
|
|
const Vec &a = face.points[0], &b = face.points[1], &c = face.points[2];
|
|
Vec n{(b.y - a.y) * (c.z - a.z) - (b.z - a.z) * (c.y - a.y), (b.z - a.z) * (c.x - a.x) - (b.x - a.x) * (c.z - a.z), (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x)};
|
|
const double length = std::sqrt(n.x * n.x + n.y * n.y + n.z * n.z);
|
|
if (length > 0) factor = .74 + .26 * std::abs((n.x * light.x + n.y * light.y + n.z * light.z) / length);
|
|
}
|
|
fill = shade(face.fill, factor);
|
|
}
|
|
const bool lit = !highlight.empty() && face.part == highlight;
|
|
const std::string ink = lit ? scene.accent : face.ink.empty() ? scene.ink : face.ink;
|
|
out.svg += "<path d=\"" + path + "\" fill=\"" + fill + "\" fill-opacity=\"" + (face.fill.empty() ? std::string("1") : num(face.opacity)) + "\"" +
|
|
(face.stroke > 0 || lit ? " stroke=\"" + ink + "\" stroke-width=\"" + num((lit ? std::max(face.stroke, 2.0) + 2 : face.stroke) * std::sqrt(camera.zoom)) + "\" stroke-linejoin=\"round\" stroke-linecap=\"round\"" : std::string()) +
|
|
(face.dashed ? " stroke-dasharray=\"" + num(9 * std::sqrt(camera.zoom)) + " " + num(7 * std::sqrt(camera.zoom)) + "\"" : std::string()) +
|
|
(face.fill.empty() && face.opacity < 1 ? " stroke-opacity=\"" + num(face.opacity) + "\"" : std::string()) + "/>";
|
|
for (const auto &line : face.lines) {
|
|
std::string d;
|
|
for (size_t i = 0; i < line.size(); ++i) { const auto p = project(line[i]); d += (i ? "L" : "M") + num(p.x) + " " + num(p.y); }
|
|
out.svg += "<path d=\"" + d + "\" fill=\"none\" stroke=\"" + (face.fill == "" ? ink : std::string("#ffffff")) + "\" stroke-opacity=\".45\" stroke-width=\"" + num(1.6 * std::sqrt(camera.zoom)) + "\"/>";
|
|
}
|
|
}
|
|
out.svg += "</svg>";
|
|
for (auto &[id, part] : parts) {
|
|
if (const auto found = scene.centres.find(id); found != scene.centres.end()) {
|
|
part.centre = found->second;
|
|
const auto p = project(found->second);
|
|
part.cx = p.x; part.cy = p.y;
|
|
} else { part.cx = (part.x0 + part.x1) / 2; part.cy = (part.y0 + part.y1) / 2; }
|
|
out.parts.push_back(part);
|
|
}
|
|
for (const auto &[id, at] : scene.anchors) {
|
|
const auto p = project(at);
|
|
out.anchors.push_back({id, p.x, p.y});
|
|
}
|
|
return out;
|
|
}
|
|
|
|
// Where the camera stands for a focus: "" the whole ground with its surroundings, "stadium"
|
|
// the bowl, a part id that part, turned so that it lies in front.
|
|
inline Camera camera_for(const Scene &scene, const std::string &focus) {
|
|
if (focus.empty()) return {28, 42, 1.32, 0, 0};
|
|
if (focus == "stadium") return {28, 44, 2.0, 0, 0};
|
|
if (focus == "periphery") return {28, 52, 1.15, 0, 0};
|
|
const auto found = scene.centres.find(focus);
|
|
if (found == scene.centres.end()) return {28, 44, 2.0, 0, 0};
|
|
const Vec c = found->second;
|
|
if (std::hypot(c.x, c.y) < 1) return {28, 50, 3.0, 0, 0};
|
|
// turn the part to the near side, a little off the axis so that its flank shows
|
|
const double towards = std::atan2(c.y, c.x) * 180 / 3.14159265358979;
|
|
const bool outer = focus.starts_with("periphery:");
|
|
return {-90 - towards + 22, 38, outer ? 2.6 : focus.starts_with("block:") ? 3.0 : 3.2, c.x * .82, c.y * .82};
|
|
}
|
|
} // namespace bmh::modern_ui::stadium3d
|