Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/TerrainDisplayTests.cpp

Source at documentation-generation time. See Test catalog for fixture associations.

1#include "../Instruments/MFD/TerrainMapProjection.h"
2#include "../Viewscreen/GeometryBounds.h"
3#include "TerrainGeometry.generated.h"
4#include "NativeUiTest11.h"
5#include <array>
6#include <cstdlib>
7#include <iostream>
8#include <vector>
9
10static int checks = 0;
11static void Check(bool value, const char* message)
12{
13 ++checks;
14 if (!value) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
15}
16static constexpr float Radius = 2939.6f;
17static Viewscreen geometry;
18struct Vertex { RiseMath::Vector3 position = {0,0,0}; unsigned char pri_landform = 255; };
19static Vertex patch[64][64];
20static const int centerU[] = {1019,3057,-1019,5095,1019,1019};
21static const int centerV[] = {1019,1019,1019,1019,-1019,3057};
22
23// Independent face axes, including the otherwise ambiguous closing vertices.
24static RiseMath::Vector3 FacePosition(int face, float u, float v)
25{
26 static const RiseMath::Vector3 normal[] = {{0,-1,0},{1,0,0},{-1,0,0},{0,1,0},{0,0,-1},{0,0,1}};
27 static const RiseMath::Vector3 east[] = {{1,0,0},{0,1,0},{0,-1,0},{-1,0,0},{1,0,0},{1,0,0}};
28 static const RiseMath::Vector3 down[] = {{0,0,1},{0,0,1},{0,0,1},{0,0,1},{0,-1,0},{0,1,0}};
29 auto p = normal[face] + east[face] * ((u - centerU[face]) / 1019) + down[face] * ((v - centerV[face]) / 1019);
31 return p * -Radius;
32}
33
34static void MakePatch(int face, int u, int v)
35{
36 for (int x = 0; x < 64; ++x)
37 for (int y = 0; y < 64; ++y)
38 {
39 char rotation;
40 auto tcp = geometry.CalculateWrap(short(u+x-31), short(v+y-31), char(face), &rotation);
41 patch[x][y] = {};
42 if (tcp.u == 30000 || tcp.v == 30000) continue;
43 auto p = geometry.CalculatePlanar(tcp.u, tcp.v);
44 if (RiseMath::Vec3LengthSq(&p) < 0.5f) continue;
45 patch[x][y].position = p * -Radius;
46 patch[x][y].pri_landform = 0;
47 }
48}
49
50static RiseMath::Matrix MapView(RiseMath::Vector3 renderPosition, float heading)
51{
52 RiseMath::Vector3 ship = -renderPosition, up;
53 RiseMath::Vec3Normalize(&up, &ship);
54 const RiseMath::Vector3 north(0,0,1);
55 RiseMath::Matrix view, rotate;
56 RiseMath::MatrixLookAtLH(&view, &ship, &north, &up);
57 RiseMath::MatrixRotationZ(&rotate, heading);
58 return view * rotate;
59}
60
61static std::array<RiseMath::Vector2,4> TransformCorners(const RiseMath::Matrix& m)
62{
63 std::array<RiseMath::Vector2,4> result;
64 const RiseMath::Vector3 texture[] = {{0,0,.1f},{32,0,.1f},{32,32,.1f},{0,32,.1f}};
65 for (int i = 0; i < 4; ++i)
66 {
68 RiseMath::Vec3TransformCoord(&p, &texture[i], &m);
69 Check(std::fabs(p.z - .1f) < .000001f, "quad changed sprite depth");
70 result[i] = {p.x,p.y};
71 }
72 return result;
73}
74
76{ return (b.x-a.x)*(c.y-a.y) - (b.y-a.y)*(c.x-a.x); }
77static bool Contains(const std::array<RiseMath::Vector2,4>& q, RiseMath::Vector2 p)
78{
79 bool positive = false, negative = false;
80 for (int i = 0; i < 4; ++i)
81 {
82 float c = Cross(q[i], q[(i+1)%4], p);
83 positive |= c > .0001f; negative |= c < -.0001f;
84 }
85 return !(positive && negative);
86}
87
88static void CheckMap(int face, int u, int v, RiseMath::Vector3 ship, int knownMissingSamples = 0)
89{
90 MakePatch(face,u,v);
91 for (float heading : {0.0f, .907571f, 2.4f, 4.066617f, 6.1f})
92 {
93 auto view = MapView(ship,heading);
94 std::vector<std::array<RiseMath::Vector2,4>> quads;
95 for (int x = 0; x < 63; ++x)
96 for (int y = 0; y < 63; ++y)
97 {
98 if ((x-31)*(x-31)+(y-31)*(y-31) > 1024) continue;
100 if (!TerrainMapProjection::CellTransform(patch,x,y,Radius,view,1,1,{0,0},m)) continue;
101 auto quad = TransformCorners(m);
102 const int dx[] = {0,1,1,0}, dy[] = {0,0,1,1};
103 for (int k = 0; k < 4; ++k)
104 {
105 auto p = TerrainMapProjection::Project(patch[x+dx[k]][y+dy[k]].position, Radius,view,1,1,{0,0});
106 Check(RiseMath::Vec2Length(&(p -= quad[k])) < .0001f, "sprite corner missed its real terrain vertex");
107 }
108 quads.push_back(quad);
109 }
110 Check(!quads.empty() && quads.size() <= 3205, "invalid compacted tile count");
111 if (knownMissingSamples >= 0)
112 {
113 int missing = 0;
114 for (int angle = 0; angle < 720; ++angle)
115 {
116 float a = angle * RiseMath::Pi / 360;
117 RiseMath::Vector2 p(8*std::cos(a),8*std::sin(a));
118 bool found = false;
119 for (const auto& q : quads) if (Contains(q,p)) { found = true; break; }
120 if (!found) ++missing;
121 }
122 if (missing && heading == 0) std::cout << "KNOWN SOURCE GAP face=" << face << " tcp=" << u << ',' << v << " missing=" << missing << "/720\n";
123 Check(missing <= knownMissingSamples, "map coverage regressed beyond available source geometry");
124 }
125 }
126}
127
128// Independent polygon clipping checks actual triangles, not their box corners.
129static float Plane(const RiseMath::Vector4& p, int n)
130{
131 switch(n) { case 0:return p.w+p.x; case 1:return p.w-p.x; case 2:return p.w+p.y;
132 case 3:return p.w-p.y; case 4:return p.z; default:return p.w-p.z; }
133}
134static bool TriangleVisible(const RiseMath::Vector3* points, const RiseMath::Matrix& m)
135{
136 std::vector<RiseMath::Vector4> polygon;
137 for (int i = 0; i < 3; ++i) { RiseMath::Vector4 p; RiseMath::Vec3Transform(&p,&points[i],&m); polygon.push_back(p); }
138 for (int plane = 0; plane < 6 && !polygon.empty(); ++plane)
139 {
140 std::vector<RiseMath::Vector4> clipped;
141 auto previous = polygon.back(); float d0 = Plane(previous,plane);
142 for (auto current : polygon)
143 {
144 float d1 = Plane(current,plane);
145 if ((d0 >= 0) != (d1 >= 0)) clipped.push_back(previous + (current-previous)*(d0/(d0-d1)));
146 if (d1 >= 0) clipped.push_back(current);
147 previous = current; d0 = d1;
148 }
149 polygon = std::move(clipped);
150 }
151 return !polygon.empty();
152}
153
154static void CheckLightingRange()
155{
156 const RiseMath::Vector3 eye(10.0f, -20.0f, 30.0f);
157 GeometryBounds bounds;
158 Check(bounds.IsWithinDistance(eye, 4.0f), "unknown terrain bounds lost local lighting");
159 bounds.Include(eye + RiseMath::Vector3(-8, -1, -1));
160 bounds.Include(eye + RiseMath::Vector3(8, 1, 1));
161 Check(bounds.IsWithinDistance(eye, 4.0f), "tile enclosing the vehicle lost local lighting");
162 bounds = GeometryBounds();
163 bounds.Include(eye + RiseMath::Vector3(4, -1, -1));
164 bounds.Include(eye + RiseMath::Vector3(12, 1, 1));
165 Check(bounds.IsWithinDistance(eye, 4.0f), "near tile edge used the distant shader");
166 Check(!bounds.IsWithinDistance(eye - RiseMath::Vector3(.01f, 0, 0), 4.0f), "distant tile used the nearby shader");
167 bounds = GeometryBounds();
168 bounds.Include(eye + RiseMath::Vector3(3, 3, 0));
169 bounds.Include(eye + RiseMath::Vector3(4, 4, 1));
170 Check(!bounds.IsWithinDistance(eye, 4.0f), "diagonally distant tile used the nearby shader");
171
172 // The same physical ground must stay lit on all cube faces and at their
173 // corners, including after the vehicle moves relative to an uploaded tile.
174 for (int face = 0; face < 6; ++face)
175 for (int sideU : {-1, 0, 1}) for (int sideV : {-1, 0, 1})
176 {
177 const float u = float(centerU[face] + sideU * 1018);
178 const float v = float(centerV[face] + sideV * 1018);
179 const auto origin = FacePosition(face, u, v);
180 bounds = GeometryBounds();
181 for (int x = 0; x < 2; ++x) for (int y = 0; y < 2; ++y)
182 bounds.Include(FacePosition(face, u + x, v + y) - origin);
183 for (float fraction : {.05f, .5f, .95f})
184 {
185 const auto ground = FacePosition(face, u + fraction, v + fraction);
187 RiseMath::Vec3Normalize(&up, &ground);
188 const auto localEye = ground + up * .002f - origin;
189 Check(bounds.IsWithinDistance(localEye, 4.0f), "nearby ground lost lighting at a cube face or corner");
190 Check(!bounds.IsWithinDistance(localEye + up * 20.0f, 4.0f), "ground far below used the nearby shader");
191 }
192 }
193}
194
195static void CheckCulling()
196{
197 int visible = 0, culled = 0, intersectingWithOriginOutside = 0, oldFalseRejections = 0;
198 for (int face = 0; face < 6; ++face)
199 for (int sideU : {-1,1}) for (int sideV : {-1,1})
200 {
201 int u = centerU[face] + sideU*1018, v = centerV[face] + sideV*1018;
202 MakePatch(face,u,v);
203 auto origin = FacePosition(face,float(u)+.3f,float(v)+.6f);
204 RiseMath::Vector3 up, north, east;
205 RiseMath::Vec3Normalize(&up,&origin);
206 north = RiseMath::Vector3(0,0,-1) - up * -up.z;
207 RiseMath::Vec3Normalize(&north,&north); RiseMath::Vec3Cross(&east,&north,&up);
208 for (int heading = 0; heading < 360; heading += 30)
209 for (float pitch : {-.6f,0.0f,.6f}) for (float roll : {-.7f,.7f})
210 for (float fov : {.5f,1.1f,1.8f})
211 {
212 float a = RiseMath::ToRadian(float(heading));
213 auto forward = (north*std::cos(a)+east*std::sin(a))*std::cos(pitch)+up*std::sin(pitch);
214 RiseMath::Vector3 right, cameraUp;
215 RiseMath::Vec3Cross(&right,&up,&forward); RiseMath::Vec3Normalize(&right,&right);
216 RiseMath::Vec3Cross(&cameraUp,&forward,&right);
217 cameraUp = cameraUp*std::cos(roll)+right*std::sin(roll);
218 auto eye = up*.5f, target = eye+forward;
219 RiseMath::Matrix view, proj;
220 RiseMath::MatrixLookAtRH(&view,&eye,&target,&cameraUp);
221 RiseMath::MatrixPerspectiveFovRH(&proj,fov,1.6f,.001f,384);
222 auto m = view*proj;
223 // Reproduce the removed flat-index heading/FOV lookup. The game
224 // computes lookvec with -Z and adds it to planet (not render) coordinates.
225 auto tangent = [&](RiseMath::Vector3 p) {
226 p -= origin; RiseMath::Vec3Normalize(&p,&p); p=p*Radius+origin;
227 RiseMath::Vec3Normalize(&p,&p); return p;
228 };
229 auto plotNorth=tangent(patch[31][31].position-patch[31][32].position);
230 auto look=tangent(forward);
231 float cosine=RiseMath::Vec3Dot(&look,&plotNorth);
232 float oldHeading=std::acos((std::max)(-1.0f,(std::min)(1.0f,cosine)));
233 RiseMath::Vector3 cross; RiseMath::Vec3Cross(&cross,&look,&plotNorth);
234 if (RiseMath::Vec3Dot(&cross,&origin)<0) oldHeading=2*RiseMath::Pi-oldHeading;
235 RiseMath::Matrix oldRotation; RiseMath::MatrixRotationZ(&oldRotation,-oldHeading);
236 for (int x = 0; x < 63; x += 3) for (int y = 0; y < 63; y += 3)
237 {
238 if (patch[x][y].pri_landform == 255 || patch[x+1][y].pri_landform == 255 ||
239 patch[x+1][y+1].pri_landform == 255 || patch[x][y+1].pri_landform == 255) continue;
240 RiseMath::Vector3 p[] = {patch[x][y].position-origin,patch[x+1][y].position-origin,
241 patch[x][y+1].position-origin,patch[x+1][y].position-origin,
242 patch[x+1][y+1].position-origin,patch[x][y+1].position-origin};
243 GeometryBounds bounds; for (auto vertex : p) bounds.Include(vertex);
244 bool hit = bounds.IntersectsFrustum(m);
245 bool reference = TriangleVisible(p,m) || TriangleVisible(p+3,m);
246 Check(!reference || hit,"a triangle intersecting the current view was culled");
247 if (!hit) ++culled;
248 if (reference)
249 {
250 ++visible;
251 RiseMath::Vector2 index(float(x-31),float(y-31));
252 index={index.x*oldRotation._11+index.y*oldRotation._21,
253 index.x*oldRotation._12+index.y*oldRotation._22};
254 int ix=int(index.x),iy=int(index.y);
255 bool oldVisible=ix>=-31 && ix<32 && iy>=-31 && iy<32 &&
256 ((std::abs(ix)<std::fabs(std::tan(fov*.5f)*iy)+6.25f && iy<=0 && ix*ix+iy*iy<=1024) || ix*ix+iy*iy<4);
257 oldFalseRejections += !oldVisible;
258 RiseMath::Vector4 corner; RiseMath::Vec3Transform(&corner,&p[0],&m);
259 for (int n = 0; n < 6; ++n) if (Plane(corner,n) < 0) { ++intersectingWithOriginOutside; break; }
260 }
261 }
262 }
263 }
264 Check(culled > 10000 && visible > 10000 && intersectingWithOriginOutside > 1000,"culling sweep did not exercise its boundaries");
265 Check(oldFalseRejections>1000,"old flat-index cull did not reproduce premature disappearance");
266 std::cout << "Culling: " << visible << " visible triangles, " << culled << " boxes rejected, "
267 << intersectingWithOriginOutside << " visible plots with origin outside, " << oldFalseRejections << " old false rejections\n";
268}
269
270static void CheckBoundaryCases()
271{
272 MakePatch(0,1019,1019);
273 auto view = MapView(FacePosition(0,1019,1019),0);
275 for (int x : {-1,0,62,63}) for (int y : {-1,0,62,63})
276 Check(TerrainMapProjection::CellTransform(patch,x,y,Radius,view,1,1,{0,0},m) ==
277 (x>=0 && x<63 && y>=0 && y<63),"cell boundary validation failed");
278 patch[32][32].pri_landform = 255;
279 Check(!TerrainMapProjection::CellTransform(patch,31,31,Radius,view,1,1,{0,0},m),"missing diagonal was painted as data");
280 patch[32][32].pri_landform = 0; patch[32][32].position = {0,0,0};
281 Check(!TerrainMapProjection::CellTransform(patch,31,31,Radius,view,1,1,{0,0},m),"cleared tile was painted");
283 GeometryBounds bounds;
284 Check(bounds.IntersectsFrustum(m),"unknown bounds must fail open");
285 bounds.Include(RiseMath::Vector3(-2,-2,-1)); bounds.Include(RiseMath::Vector3(2,2,2));
286 Check(bounds.IntersectsFrustum(m),"box enclosing view with all corners outside was rejected");
287 bounds = {}; bounds.Include(RiseMath::Vector3(1.01f,0,.5f)); bounds.Include(RiseMath::Vector3(2,1,.6f));
288 Check(!bounds.IntersectsFrustum(m),"wholly outside geometry was retained");
289 bounds.Include(RiseMath::Vector3(.9f,0,.5f));
290 Check(bounds.IntersectsFrustum(m),"overhanging structure was culled using its origin");
291}
292
293static void CheckAlignment()
294{
295 for (int face=0;face<6;++face)
296 for (float offset : {0.05f,0.5f,1.5f,15.0f})
297 {
298 auto ship=FacePosition(face,centerU[face]+1019-offset,centerV[face]-1019+offset);
299 auto terrain=FacePosition(face,centerU[face]+1018-offset,centerV[face]-1017+offset);
300 for(float heading : {0.0f,1.0f,3.0f,5.0f}) for(float range : {1.0f,5.0f,20.0f,80.0f})
301 {
302 auto view=MapView(ship,heading);
303 float px=132.5f/range*.5f,py=132.5f/range*.75f;
304 auto point=TerrainMapProjection::Project(terrain,Radius,view,px,py,{137,201});
305 RiseMath::Vector3 waypoint=-terrain,result;
306 RiseMath::Vec3TransformCoord(&result,&waypoint,&view);
307 Check(std::fabs(point.x-(137-result.x*px))<.04f && std::fabs(point.y-(201+result.y*py))<.04f,
308 "terrain does not use waypoint bearing/zoom/nonuniform display scale");
309 auto raised=terrain*1.01f;
310 auto same=TerrainMapProjection::Project(raised,Radius,view,px,py,{137,201});
311 Check(RiseMath::Vec2Length(&(same-=point))<.04f,"terrain elevation displaced its map footprint");
312 // Construct a point exactly one range radius away along a great circle.
313 RiseMath::Vector3 normal,east;
314 RiseMath::Vec3Normalize(&normal,&ship);
315 const RiseMath::Vector3 north(0,0,1);
316 RiseMath::Vec3Cross(&east,&normal,&north); RiseMath::Vec3Normalize(&east,&east);
317 auto ring=ship*std::cos(range/Radius)+east*(Radius*std::sin(range/Radius));
318 auto ringPoint=TerrainMapProjection::Project(ring,Radius,view,132.5f/range,132.5f/range,{0,0});
319 Check(std::fabs(RiseMath::Vec2Length(&ringPoint)-132.5f)<.04f,"terrain range and ring scale disagree");
320 }
321 }
322}
323
324static void CheckSeamMovement()
325{
326 const auto corner=FacePosition(0,2038,0);
327 RiseMath::Vector3 normal,east,north;
328 RiseMath::Vec3Normalize(&normal,&corner);
329 const RiseMath::Vector3 axis(0,0,1);
330 RiseMath::Vec3Cross(&east,&normal,&axis); RiseMath::Vec3Normalize(&east,&east);
331 RiseMath::Vec3Cross(&north,&normal,&east);
332 RiseMath::Vector2 previous;
333 int faces=0;
334 for (int step=0;step<=72;++step)
335 {
336 float angle=step*RiseMath::Pi/36;
337 auto ship=corner+(east*std::cos(angle)+north*std::sin(angle))*2;
338 RiseMath::Vec3Normalize(&ship,&ship); ship*=Radius;
339 char face=geometry.CalculateCube(-ship),rotation;
340 auto tcp=geometry.CalculateCGC(-ship,face);
341 tcp=geometry.CalculateWrap(tcp.u,tcp.v,face,&rotation);
342 faces|=1<<face;
343 MakePatch(face,tcp.u,tcp.v);
344 float nearest=100;
345 for(int x=0;x<64;++x) for(int y=0;y<64;++y)
346 {
347 if(patch[x][y].pri_landform==255) continue;
348 auto delta=patch[x][y].position-corner;
349 nearest=(std::min)(nearest,RiseMath::Vec3Length(&delta));
350 }
351 Check(nearest<.001f,"face crossing lost the common corner vertex");
352 auto view=MapView(ship,.907571f);
353 auto point=TerrainMapProjection::Project(corner,Radius,view,1,1,{0,0});
354 if(step) {auto delta=point-previous;Check(RiseMath::Vec2Length(&delta)<.18f,"map jumped when the packet face changed");}
355 previous=point;
356 }
357 Check(faces==((1<<0)|(1<<1)|(1<<4)),"movement did not cross all three faces");
358}
359
360static void CheckSpriteRendering(const wchar_t* output)
361{
362 NativeUiTest11 fixture(1100,600); auto* device=&fixture.device;
363 Rendering::RenderSprite* sprite = nullptr;
364 Check(SUCCEEDED(Rendering::CreateSprite(device,&sprite)),"sprite creation failed");
365 Rendering::RenderTexture* texture = nullptr;
366 Check(SUCCEEDED(Rendering::LoadTexture(device,L"Textures/Instruments/colorBox.png",&texture,1)),"real terrain texture unavailable");
367 device->Clear(0,nullptr,Rendering::ClearFlags::TARGET,0xff10151d,1,0);
368 device->BeginScene(); device->SetRenderState(Rendering::RenderState::ZENABLE,FALSE);
369 device->SetRenderState(Rendering::RenderState::SCISSORTESTENABLE,TRUE);
371 MakePatch(0,2037,0);
372 auto ship = FacePosition(0,2037.8f,.05f);
373 auto view = MapView(ship,RiseMath::ToRadian(52));
374 const RECT rectangle = {0,0,32,32}; const RiseMath::Vector3 position(0,0,.1f);
375 for (int panel=0;panel<2;++panel)
376 {
377 const RECT clip = {panel*550,65,(panel+1)*550,540}; device->SetScissorRect(&clip);
378 for (int x=0;x<63;++x) for (int y=0;y<63;++y)
379 {
380 if ((x-31)*(x-31)+(y-31)*(y-31)>1024) continue;
382 if (!TerrainMapProjection::CellTransform(patch,x,y,Radius,view,10,10,{825,300},m)) continue;
383 auto p = patch[x][y].position;
384 DWORD color = std::fabs(p.z)>std::fabs(p.x) && std::fabs(p.z)>std::fabs(p.y) ? 0xffa7b19c :
385 (std::fabs(p.x)>std::fabs(p.y) ? 0xff92662e : 0xffc6a572);
386 if (panel==1) { sprite->SetTransform(&m); sprite->Draw(texture,&rectangle,nullptr,&position,color); continue; }
387 // Original flat TCP layout, using the same available tile set and colors.
388 const float size=20, angle=-RiseMath::ToRadian(52), c=std::cos(angle), s=std::sin(angle);
389 RiseMath::Vector2 q[4]; const int dx[]={0,1,1,0},dy[]={0,0,1,1};
390 for(int k=0;k<4;++k)
391 {
392 float a=(x-31-.8f+dx[k])*size,b=(y-31-.05f+dy[k])*size;
393 q[k]={275+a*c-b*s,300+a*s+b*c};
394 }
396 sprite->SetTransform(&m); sprite->Draw(texture,&rectangle,nullptr,&position,color);
397 }
398 sprite->Flush();
399 }
400 sprite->End();
401 device->SetRenderState(Rendering::RenderState::SCISSORTESTENABLE,FALSE);
402 device->EndScene();
403 const auto pixels=fixture.Pixels();
404 int oldMissing=0,newMissing=0;
405 for(int x=-180;x<=180;++x) for(int y=-180;y<=180;++y)
406 {
407 if(x*x+y*y>180*180) continue;
408 const auto row=pixels.data()+(300+y)*1100;
409 oldMissing += (row[275+x]&0xffffff)==0x10151d;
410 newMissing += (row[825+x]&0xffffff)==0x10151d;
411 }
412 std::cout << "Native D3D11 sprite coverage: before=" << oldMissing << " uncovered pixels, after=" << newMissing << '\n';
413 Check(oldMissing>10000,"flat-net visual did not reproduce the quadrant");
414 Check(newMissing==0,"native D3D11 sprite left cracks in projected cells");
415 // Add range rings after measuring pixels; this is a synthetic data fixture.
416 device->BeginScene();
417 struct LineVertex {float x,y,z,rhw;DWORD color;};
418 device->SetTexture(0,nullptr);
420 for(float center : {275.0f,825.0f}) for(float radius : {100.0f,200.0f})
421 {
422 LineVertex points[181];
423 for(int i=0;i<=180;++i) {float a=i*RiseMath::Pi/90;points[i]={center+radius*std::cos(a),300+radius*std::sin(a),0,1,0xffeeeeee};}
424 Check(SUCCEEDED(device->DrawPrimitiveUP(Rendering::Primitive::LineStrip,180,points,sizeof(LineVertex))),"range rings failed");
425 }
426 Rendering::RenderFont* font=nullptr;
427 Check(SUCCEEDED(Rendering::CreateFontW(device,22,0,FW_NORMAL,1,FALSE,DEFAULT_CHARSET,OUT_DEFAULT_PRECIS,DEFAULT_QUALITY,DEFAULT_PITCH,L"Segoe UI",&font)),"font creation failed");
428 RECT title={25,12,540,60}; font->DrawTextW(nullptr,L"Before: flat cube grid",-1,&title,DT_LEFT,0xffffffff);
429 title={575,12,1090,60};font->DrawTextW(nullptr,L"After: actual terrain footprints",-1,&title,DT_LEFT,0xffffffff);
430 title={25,552,1090,598};font->DrawTextW(nullptr,L"PM / EP / NP corner | heading 052 | rings 10 / 20 km | synthetic face colors",-1,&title,DT_LEFT,0xffffffff);
431 for(int center : {275,825}) {title={center-8,285,center+20,320};font->DrawTextW(nullptr,L"+",-1,&title,DT_LEFT,0xffffffff);}
432 font->Release(); device->EndScene();
433 fixture.Save(output);texture->Release();sprite->Release();fixture.DebugClean();
434}
435
436int wmain(int argc, wchar_t** argv)
437{
438 if (argc == 2) { CheckSpriteRendering(argv[1]); return 0; }
439 CheckBoundaryCases();
440 CheckAlignment();
441 CheckSeamMovement();
442 for (int face = 0; face < 6; ++face)
443 {
444 // Avoid the singular exact geographic pole for the existing waypoint view.
445 CheckMap(face,centerU[face]+10,centerV[face]+10,FacePosition(face,float(centerU[face]+10.3f),float(centerV[face]+10.7f)));
446 for (int x : {-1,1}) for (int y : {-1,1})
447 {
448 int u=centerU[face]+x*1018, v=centerV[face]+y*1018;
449 // Existing wrapping omits strips at some OTHER corners. Explicitly
450 // record this upstream limitation, rather than manufacture colors.
451 static const int missing[6][4] = {{17,17,0,33},{0,0,16,0},{0,17,16,33},
452 {0,0,0,17},{17,0,0,0},{17,50,0,49}};
453 int corner = (x+1)+(y+1)/2;
454 CheckMap(face,u,v,FacePosition(face,float(centerU[face]+x*1019),float(centerV[face]+y*1019)),missing[face][corner]);
455 }
456 }
457 // Reported approach and neighboring face viewpoints, including the seam
458 // sentinel requested by the server task. Invalid vertices remain absent.
459 CheckMap(0,2037,0,FacePosition(0,2037.8f,.05f));
460 CheckMap(1,2038,0,FacePosition(1,2038.05f,.1f));
461 CheckMap(4,2037,-1,FacePosition(4,2037.9f,-.1f));
462 char rotation;
463 auto tcp=geometry.CalculateWrap(2038,-1,0,&rotation);
464 Check(tcp.u==2039 && tcp.v==0,"PM closing adjacency regressed at (2038,-1)");
465 tcp=geometry.CalculateWrap(2039,0,4,&rotation);
466 Check(tcp.u==2038 && tcp.v==1,"NP closing edge regression");
467 CheckLightingRange();
468 CheckCulling();
469 std::cout << "PASS " << checks << " terrain display checks\n";
470}
SCRIPT_CONTROL SCRIPT_STATE const void int
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
INT DrawTextW(RenderSprite *sprite, const wchar_t *text, INT count, RECT *rectangle, DWORD flags, PackedColor color)
HRESULT Begin(DWORD flags)
HRESULT SetTransform(const RiseMath::Matrix *value)
HRESULT Draw(RenderTexture *image, const RECT *rectangle, const RiseMath::Vector3 *center, const RiseMath::Vector3 *position, PackedColor color)
VECTOR2SHORT CalculateCGC(RiseMath::Vector3 position, char cube) const
VECTOR2SHORT CalculateWrap(short u, short v, char cube, char *rotate) const
RiseMath::Vector3 CalculatePlanar(short u, short v)
char CalculateCube(RiseMath::Vector3 position) const
Vec Cross(Vec a, Vec b)
Definition OrbitMath.h:17
constexpr uint32_t TARGET
constexpr uint32_t SCISSORTESTENABLE
constexpr uint32_t ZENABLE
constexpr DWORD AlphaBlend
constexpr DWORD SortTexture
constexpr DWORD SortBackToFront
constexpr uint32_t XYZRHW
constexpr uint32_t DIFFUSE
HRESULT CreateFontW(RenderDevice *owner, INT height, UINT width, UINT weight, UINT mipLevels, BOOL italic, DWORD charset, DWORD precision, DWORD quality, DWORD pitch, const wchar_t *face, RenderFont **result)
HRESULT CreateSprite(RenderDevice *owner, RenderSprite **result)
HRESULT LoadTexture(RenderDevice *owner, const wchar_t *path, RenderTexture **result, UINT levels=0, UINT width=0, UINT height=0)
auto ToRadian(T value)
Definition ClientMath.h:13
float Vec3Length(const Vector3 *a)
Definition ClientMath.h:95
constexpr float Pi
Definition ClientMath.h:12
Vector3 * Vec3Cross(Vector3 *out, const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:105
Matrix * MatrixLookAtRH(Matrix *out, const Vector3 *eye, const Vector3 *at, const Vector3 *up)
Definition ClientMath.h:141
Vector3 * Vec3TransformCoord(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:109
float Vec2Length(const Vector2 *a)
Definition ClientMath.h:92
float Vec3LengthSq(const Vector3 *a)
Definition ClientMath.h:94
Matrix * MatrixLookAtLH(Matrix *out, const Vector3 *eye, const Vector3 *at, const Vector3 *up)
Definition ClientMath.h:139
Matrix * MatrixPerspectiveFovRH(Matrix *out, float fov, float aspect, float nearZ, float farZ)
Definition ClientMath.h:151
Matrix * MatrixIdentity(Matrix *out)
Definition ClientMath.h:115
float Vec3Dot(const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:93
Vector4 * Vec3Transform(Vector4 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:113
Vector3 * Vec3Normalize(Vector3 *out, const Vector3 *a)
Definition ClientMath.h:103
Matrix * MatrixRotationZ(Matrix *out, float value)
Definition ClientMath.h:128
RiseMath::Vector2 Project(const RiseMath::Vector3 &terrainPosition, float radius, const RiseMath::Matrix &mapView, float pixelsPerKmX, float pixelsPerKmY, RiseMath::Vector2 center)
bool QuadTransform(const RiseMath::Vector2(&p)[4], float width, float height, float depth, RiseMath::Matrix &transform)
bool CellTransform(const Vertex(&grid)[64][64], int u, int v, float radius, const RiseMath::Matrix &mapView, float pixelsPerKmX, float pixelsPerKmY, RiseMath::Vector2 center, RiseMath::Matrix &transform, float minimumPixels=0)
bool IsWithinDistance(const Vector &point, float distance) const
void Include(const Vector &p)
bool IntersectsFrustum(const Matrix &m, float guardX=0, float guardY=0) const