1#include "../Viewscreen/CloudBaseGeometry.h"
2
3#include <cstdlib>
4#include <iostream>
5
6struct Vector
7{
8 float x = 0, y = 0, z = 0;
9 Vector() = default;
10 Vector(float x, float y, float z) : x(x), y(y), z(z) {}
11 Vector operator+(Vector b) const { return {x + b.x, y + b.y, z + b.z}; }
12 Vector operator-(Vector b) const { return {x - b.x, y - b.y, z - b.z}; }
14};
15
16static int checks = 0;
17static void Check(bool condition, const char* message)
18{
19 ++checks;
20 if (!condition)
21 {
22 std::cerr << "FAIL: " << message << '\n';
23 std::exit(1);
24 }
25}
26
27static double Dot(Vector a, Vector b)
28{
29 return double(a.x) * b.x + double(a.y) * b.y + double(a.z) * b.z;
30}
31
33{
34 return {a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x};
35}
36
37static double Length(Vector a) {
return std::sqrt(
Dot(a, a)); }
38static constexpr float Radius = 2939.6f;
39
40
41
43{
44 static const Vector normals[] = {{0,-1,0}, {1,0,0}, {-1,0,0}, {0,1,0}, {0,0,-1}, {0,0,1}};
45 static const Vector east[] = {{1,0,0}, {0,1,0}, {0,-1,0}, {-1,0,0}, {1,0,0}, {1,0,0}};
46 static const Vector down[] = {{0,0,1}, {0,0,1}, {0,0,1}, {0,0,1}, {0,-1,0}, {0,1,0}};
47 static const int centerU[] = {1019, 3057, -1019, 5095, 1019, 1019};
48 static const int centerV[] = {1019, 1019, 1019, 1019, -1019, 3057};
49 const double uOffset = (u - centerU[face]) / 1019.0;
50 const double vOffset = (v - centerV[face]) / 1019.0;
51 const double x = normals[face].x + east[face].x * uOffset + down[face].x * vOffset;
52 const double y = normals[face].y + east[face].y * uOffset + down[face].y * vOffset;
53 const double z = normals[face].z + east[face].z * uOffset + down[face].z * vOffset;
54 const double scale = -Radius / std::sqrt(x*x + y*y + z*z);
55 return {float(x * scale), float(y * scale), float(z * scale)};
56}
57
59{
61}
62
63static void CheckTriangle(Vector a, Vector b, Vector c)
64{
66 Check(
Length(normal) > 0.5,
"cloud triangle collapsed at a face edge/corner");
67 Check(
Dot(normal, a) < 0,
"cloud triangle winding no longer faces the surface");
68}
69
70static void CheckPatch(int face, int centerU, int centerV)
71{
72
73 for (int t = 0; t < 64; ++t)
74 for (int s = 0; s < 64; ++s)
75 {
76 const int u = centerU + t - 31, v = centerV + s - 31;
78 Check(std::abs(
Length(p) - Radius) < 0.0006,
79 "cloud vertex left the sphere (terrain void placeholder)");
81 "cloud projection changed the face orientation or grid scale");
82 if (t < 63 && s < 63)
83 {
87 "cloud edge spans more than a local grid cell");
88 CheckTriangle(p, diagonal, down);
89 CheckTriangle(p, right, diagonal);
90 }
91 if (t > 0 && t < 63 && s > 0 && s < 63)
92 {
93
94
96 "cloud texture direction has a kink across the U seam");
98 "cloud texture direction has a kink across the V seam");
99 }
100 }
101}
102
104{
105 static const int originU[] = {0, 2038, -2038, 4076, 0, 0};
106 static const int originV[] = {0, 0, 0, 0, -2038, 2038};
107 for (int face = 0; face < 6; ++face)
108 for (int u : {0, 1019, 2038})
109 for (int v : {0, 1019, 2038})
110 CheckPatch(face, originU[face] + u, originV[face] + v);
111
112
113 const double radians = std::acos(-1.0) / 180.0;
114 const double latitude = 35.264 * radians, longitude = 44.998 * radians;
115 const int u =
int((std::tan(longitude) + 1.0) * 1019.0);
116 const int v =
int((1.0 - std::tan(latitude) / std::cos(longitude)) * 1019.0);
117 CheckPatch(0, u, v);
118 std::cout << "Passed " << checks << " cloud geometry checks across all 6 faces, "
119 "12 edges, 8 corners, and N35.264 E44.998 (grid " << u << ',' << v << ").\n";
120}
SCRIPT_CONTROL SCRIPT_STATE const void int
Vector Position(int cube, int u, int v, float radius)
float Dot(const Vector3 &a, const Vector3 &b)
Vec operator*(Vec a, double b)