80 float left,
float top,
float scale)
89 std::vector<Vertex> vertices;
90 vertices.reserve(9000);
91 const auto triangle = [&](Point a, Point b, Point c,
DWORD tint)
93 for (Point p : {a, b, c})
94 vertices.push_back({left + p.x * scale - 0.5f, top + p.y * scale - 0.5f, 0, 1, tint});
96 const auto line = [&](Point a, Point b,
float width,
DWORD tint)
98 const float dx = b.x - a.x, dy = b.y - a.y;
99 const float length = std::sqrt(dx * dx + dy * dy);
100 if (length < 0.001f)
return;
101 const float nx = -dy / length * width * 0.5f, ny = dx / length * width * 0.5f;
102 triangle({a.x + nx, a.y + ny}, {b.x + nx, b.y + ny}, {a.x - nx, a.y - ny}, tint);
103 triangle({a.x - nx, a.y - ny}, {b.x + nx, b.y + ny}, {b.x - nx, b.y - ny}, tint);
105 const auto arc = [&](
float x,
float y,
float radius,
float start,
float end,
float width,
DWORD tint)
107 const int steps = (std::max)(2,
static_cast<int>(std::fabs(end - start) * radius / 3.0f));
108 for (
int i = 0; i < steps; ++i)
109 line(Radial(x, y, radius, start + (end - start) * i / steps),
110 Radial(x, y, radius, start + (end - start) * (i + 1) / steps), width, tint);
114 line({208, 16}, {208, 92}, 1, lineColor);
120 const float start = pan - fov * 0.5f, end = pan + fov * 0.5f;
121 for (
int i = 0; i < 24; ++i)
122 triangle({63, 55}, Radial(63, 55, 32, start + fov * i / 24),
125 arc(63, 55, 32, start, end, 2, accent);
126 for (
int i = 0; i < 12; ++i)
129 line(Radial(63, 55, 35, angle), Radial(63, 55, i % 3 == 0 ? 40.0f : 38.0f, angle), 1, muted);
131 line({63, 13}, {63, 19}, 2, bright);
132 line({63, 55}, Radial(63, 55, 29, pan), 1.5f, accent);
137 const auto tilted = [tilt](
float x,
float y) -> Point
139 return {158 + x * std::cos(tilt) + y * std::sin(tilt),
140 51 - x * std::sin(tilt) + y * std::cos(tilt)};
143 line({131, 51}, {143, 51}, 1, muted);
144 line({173, 51}, {185, 51}, 1, muted);
145 line({158, 24}, {158, 29}, 1, muted);
146 line({158, 73}, {158, 78}, 1, muted);
147 line(tilted(-12, 0), tilted(11, 0), 2, accent);
148 triangle(tilted(16, 0), tilted(7, -5), tilted(7, 5), accent);
149 line(tilted(-11, -5), tilted(-11, 5), 2, accent);
153 constexpr float ballX = 256, ballY = 55, ballRadius = 32;
154 const auto screen = [=](BallPoint p) -> Point
156 return {ballX + ballRadius * p.x, ballY + ballRadius * p.y};
160 if (attitudeAvailable)
166 const float cr = std::cos(bankAngle), sr = std::sin(bankAngle);
167 const auto sphere = [&](
float latitude,
float longitude) -> BallPoint
169 const float x = std::cos(latitude) * std::sin(longitude);
170 const float y = std::sin(latitude), z = std::cos(latitude) * std::cos(longitude);
171 const float pitchedY = y * cp - z * sp;
174 return {x * cr + pitchedY * sr, x * sr - pitchedY * cr, y * sp + z * cp};
176 const auto limb = [](BallPoint a, BallPoint b) -> BallPoint
178 const float t = a.z / (a.z - b.z);
179 return {a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, 0};
181 const auto surface = [&](BallPoint a, BallPoint b, BallPoint c,
bool sky)
183 const BallPoint input[] = {a, b, c};
184 BallPoint clipped[4];
187 for (
int i = 0; i < 3; ++i)
189 const auto p = input[i], q = input[(i + 1) % 3];
190 if (p.z >= 0) clipped[count++] = p;
191 if ((p.z >= 0) != (q.z >= 0)) clipped[count++] = limb(p, q);
193 for (
int i = 1; i + 1 < count; ++i)
195 const float depth = (clipped[0].z + clipped[i].z + clipped[i + 1].z) / 3;
196 const int shade =
static_cast<int>((sky ? 198 : 24) + (sky ? 38 : 24) * depth);
197 triangle(screen(clipped[0]), screen(clipped[i]), screen(clipped[i + 1]),
202 for (
int latitude = -9; latitude < 9; ++latitude)
203 for (
int longitude = 0; longitude < 36; ++longitude)
205 const auto a = sphere(latitude * step, longitude * step);
206 const auto b = sphere((latitude + 1) * step, longitude * step);
207 const auto c = sphere((latitude + 1) * step, (longitude + 1) * step);
208 const auto d = sphere(latitude * step, (longitude + 1) * step);
209 surface(a, b, c, latitude >= 0);
210 surface(a, c, d, latitude >= 0);
212 const auto ballLine = [&](BallPoint a, BallPoint b,
float width,
DWORD tint)
214 if (a.z < 0 && b.z < 0)
return;
215 if ((a.z >= 0) != (b.z >= 0))
217 const auto intersection = limb(a, b);
218 if (a.z < 0) a = intersection;
else b = intersection;
220 line(screen(a), screen(b), width, tint);
222 for (
int latitude : {-60, -30, 0, 30, 60})
223 for (
int longitude = 0; longitude < 144; ++longitude)
228 const int shade = latitude > 0 ? 75 : 180;
231 for (
int longitude = 0; longitude < 6; ++longitude)
232 for (
int latitude = -36; latitude < 36; ++latitude)
236 const int shade = latitude >= 0 ? 75 : 140;
241 const Point craft[] = {{ballX - 17, ballY}, {ballX - 7, ballY},
242 {ballX, ballY + 4}, {ballX + 7, ballY}, {ballX + 17, ballY}};
243 for (
float width : {3.5f, 1.5f})
244 for (
int i = 0; i < 4; ++i)
247 triangle(Radial(ballX, ballY, 33, bankAngle), Radial(ballX, ballY, 38, bankAngle - 0.075f),
252 for (
int i = 0; i < 48; ++i)
253 triangle({ballX, ballY}, Radial(ballX, ballY, ballRadius, i *
RiseMath::Tau / 48),
255 line({ballX - 12, ballY - 12}, {ballX + 12, ballY + 12}, 1.5f, muted);
256 line({ballX - 12, ballY + 12}, {ballX + 12, ballY - 12}, 1.5f, muted);
259 for (
int angle : {-90, -60, -30, 0, 30, 60, 90})
262 line(Radial(ballX, ballY, 36, radians), Radial(ballX, ballY, angle % 60 == 0 ? 41.0f : 39.0f, radians),
269 if (FAILED(sprite->
End()))
return;
303 transform._41 = left;
308 RECT rect = {x, y, x + width, y + 30};
310 font->
DrawTextW(sprite, value, -1, &rect, DT_LEFT | DT_SINGLELINE, tint);
312 text(
labelFont, L
"PAN / FWD", 34, 96, 70, muted);
313 text(
labelFont, L
"TILT", 146, 10, 36, muted);
315 if (std::isfinite(data.
zoom) && data.
zoom > 0)
316 swprintf_s(buffer, L
"%.1f\x00d7", data.
zoom);
317 else wcscpy_s(buffer, L
"--");
318 text(
labelFont, buffer, 145, 85, 54, bright);
319 text(
labelFont, L
"ATTITUDE", 230, 96, 72, muted);
321 text(
labelFont, L
"HEADING", 314, 17, 54, muted);
324 else wcscpy_s(buffer, L
"--");
325 text(
valueFont, buffer, 312, 37, 56, bright);
326 text(
labelFont, L
"TRUE", 314, 78, 54, muted);
329 text(
labelFont, altitude.label, 378, 17, 70, muted);
330 text(
valueFont, altitude.value.c_str(), 376, 37, 72, bright);
331 text(
labelFont, altitude.units, 378, 78, 70, muted);
334 text(
labelFont, speed.label, 458, 17, 78, muted);
335 text(
valueFont, speed.value.c_str(), 456, 37, 80, bright);
336 text(
labelFont, speed.units, 458, 65, 78, muted);
339 else wcscpy_s(buffer, L
"V/S --");
340 text(
labelFont, buffer, 458, 86, 78, muted);