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

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

1#include "../Viewscreen/LandingLights.h"
2#include <fstream>
3#include <iostream>
4#include <limits>
5#include <stdexcept>
6#include <vector>
7#include "LandingLightFrameFixture.h"
8
9namespace
10{
11 struct Effect
12 {
13 RiseMath::Vector3 position{}, normal{0, 0, -1};
14 RiseMath::Color diffuse{1, 1, 1, 1};
15 float power = 2;
16 };
17 void Check(bool condition, const char* message)
18 {
19 if (!condition) throw std::runtime_error(message);
20 }
21 template<class T> T Read(std::ifstream& file)
22 {
23 T value{};
24 file.read(reinterpret_cast<char*>(&value), sizeof(value));
25 Check(bool(file), "truncated model");
26 return value;
27 }
28 std::vector<Effect> Model(const char* name, bool overlay)
29 {
30 std::ifstream file(name, std::ios::binary);
31 Check(bool(file), "model open");
32 const auto vertices = Read<uint16_t>(file);
33 file.seekg(2 + vertices * (overlay ? 40 : 32));
34 const auto count = Read<uint16_t>(file);
35 std::vector<Effect> effects;
36 for (unsigned i = 0; i < count; ++i)
37 {
38 Effect effect;
39 effect.position = Read<RiseMath::Vector3>(file);
40 effect.normal = Read<RiseMath::Vector3>(file);
41 effect.diffuse = RiseMath::Color(Read<uint32_t>(file));
42 Read<float>(file); Read<float>(file);
43 effect.power = Read<float>(file);
44 Read<int16_t>(file);
45 effects.push_back(effect);
46 }
47 return effects;
48 }
49 void CarOpticsCheck(const char* name, unsigned char type, float modelYaw)
50 {
51 std::array<LandingLights::Light,2> lights;
52 Check(LandingLights::FromModel(Model(name,true),lights)==2,"car optical fixture has two lamps");
53 RiseMath::Matrix pitch,yaw;
55 RiseMath::MatrixRotationY(&yaw,modelYaw);
56 const auto base=pitch*yaw;
57 float largestAimError=0;
58 for (auto& light:lights)
59 {
60 const auto origin=light.origin;
61 light=LandingLights::Configure(light,type,base);
62 Check(light.origin==origin,"beam configuration retains the authored lamp position");
63 }
64 for (float heading:{0.f,.7f,1.57f,3.14f})
65 {
66 RiseMath::Matrix attitude;
67 RiseMath::MatrixRotationYawPitchRoll(&attitude,heading,-.3f,.2f);
68 // This is the pre-dual-lamp headlightvec calculation from propulsion:
69 // vehicle-local (0,0,-1) transformed by the inverse orientation.
70 const RiseMath::Vector3 forward(0,0,-1),up(0,-1,0);
71 RiseMath::Vector3 legacyAim,physicalUp;
72 RiseMath::Vec3TransformNormal(&legacyAim,&forward,&attitude);
73 RiseMath::Vec3TransformNormal(&physicalUp,&up,&attitude);
74 for (const auto& source:lights)
75 {
76 const auto lamp=LandingLights::Transform(source,base*attitude);
77 const auto difference=lamp.direction-legacyAim;
78 largestAimError=(std::max)(largestAimError,RiseMath::Vec3Length(&difference));
79 // Use each model's lamp height at a nominal 0.4 m CG height.
80 // Vehicle +Y points down (projection rolls pi).
81 const float height=.0004f-LandingLights::Transform(source,base).origin.y;
82 const RiseMath::Vector3 roadDelta(0,height,-.02f),skyDelta(0,-height,-.02f);
83 RiseMath::Vector3 road,sky;
84 RiseMath::Vec3TransformNormal(&road,&roadDelta,&attitude);
85 RiseMath::Vec3TransformNormal(&sky,&skyDelta,&attitude);
86 const float roadLight=LandingLights::Intensity(lamp,road);
87 const float skyLight=LandingLights::Intensity(lamp,sky);
88 std::cout<<name<<" heading "<<heading<<": aim error "<<RiseMath::Vec3Length(&difference)
89 <<", road "<<roadLight<<", above cutoff "<<skyLight<<'\n';
90 Check(RiseMath::Vec3Length(&difference)<1e-6f,"car model-mounted aim matches old headlightvec");
91 Check(roadLight>.5f,"car low beams illuminate road 20 m ahead");
92 Check(skyLight==0,"car low-beam cutoff removes light above the lamps");
93 Check(RiseMath::Vec3Dot(&lamp.up,&physicalUp)>.99999f,"beam up follows physical vehicle up");
94 for(float metres:{1.f,2.f,4.f})
95 {
96 const RiseMath::Vector3 local(0,height,-metres*.001f);
97 RiseMath::Vector3 nearRoad;
98 RiseMath::Vec3TransformNormal(&nearRoad,&local,&attitude);
99 const float fill=LandingLights::Intensity(lamp,nearRoad);
100 Check(fill>(type==VehicleType::C2 ? .04f : .02f) && fill<.3f,"car has dim foreground spill 1-4 m ahead");
101 Check(fill<roadLight*.2f,"foreground spill stays weaker than the main beam");
102 }
103 const RiseMath::Vector3 sideLocal(.001f,height,-.002f);
104 RiseMath::Vector3 sideRoad;
105 RiseMath::Vec3TransformNormal(&sideRoad,&sideLocal,&attitude);
106 Check(LandingLights::Intensity(lamp,sideRoad)>.04f,"foreground spill covers the near road beside each lamp");
107 }
108 }
109 const auto mounted=LandingLights::Transform(lights[0],base);
110 std::cout<<"PASS: "<<name<<" old/new aim difference <= "<<largestAimError
111 <<"; mounted origin (m) "<<mounted.origin.x*1000<<", "<<mounted.origin.y*1000<<", "<<mounted.origin.z*1000
112 <<"; old centered origin (m) 0, 0.09, -1.472\n";
113 }
114 void FrameCheck(const char* name, bool overlay, float modelYaw, float spacing, unsigned char type)
115 {
116 const auto effects=Model(name,overlay);
117 playerships={};ourcockpit={};Rendering::lampDevice={};
118 auto& ship=playerships[0];
119 ship.type=type;
120 RiseMath::Matrix pitch,yaw;
122 RiseMath::MatrixRotationY(&yaw,modelYaw);
123 ship.matrixBase=pitch*yaw;
125 Check(ourcockpit.landingLightCount==2,"car model supplies two lamps");
126 for(auto& light:ourcockpit.landingLights) light=LandingLights::Configure(light,type,ship.matrixBase);
127 const auto a=LandingLights::Transform(ourcockpit.landingLights[0],ship.matrixBase);
128 const auto b=LandingLights::Transform(ourcockpit.landingLights[1],ship.matrixBase);
129 Check(a.origin.x*b.origin.x<0 && std::abs(std::abs(a.origin.x-b.origin.x)-spacing)<1e-6f,"car lamps have authored lateral spacing");
130 Check(a.origin.z<-.0014f && b.origin.z<-.0014f,"car lamps are at the nose");
131 LampMaterialFixture material;LampGameFixture game;LampWeatherFixture weather;
132 game.graphics->g_pEffect=&material;
133 Viewscreen view;view.gameclass=&game;view.ptrWeather=&weather;
134 for (float heading:{0.f,.7f,1.57f,3.14f})
135 {
136 RiseMath::QuaternionRotationYawPitchRoll(&ship.orientation,heading,-.3f,.2f);
137 BuildExteriorPoseFixture();
138 // Reproduce propulsion::Update clobbering matrixWorld later in the frame.
139 ship.matrixWorld=ship.matrixInvOrientation;
140 view.UpdateLandingLights();
141 Check(view.activeLandingLightCount==2 && material.count==2,"both car beams reach the renderer");
142 for(unsigned i=0;i<2;++i)
143 {
144 const auto authored=i==0 ? a : b;
145 RiseMath::Vector3 expectedOrigin,expectedAim,expectedUp;
146 RiseMath::Vec3TransformCoord(&expectedOrigin,&authored.origin,&ship.matrixInvOrientation);
147 // The road beams must point along the old vehicle-forward axis,
148 // independently of the model's raw lamp normals.
149 const RiseMath::Vector3 forward(0,0,-1);
150 RiseMath::Vec3TransformNormal(&expectedAim,&forward,&ship.matrixInvOrientation);
151 RiseMath::Vec3TransformNormal(&expectedUp,&authored.up,&ship.matrixInvOrientation);
152 const auto& actual=view.landingLights[i];
153 const auto delta=actual.origin-expectedOrigin;
154 Check(RiseMath::Vec3Length(&delta)<1e-7f,"lamp origin matches exterior after physics update");
155 Check(RiseMath::Vec3Dot(&actual.direction,&expectedAim)>.99999f,"lamp aim matches exterior after physics update");
156 const auto& uploaded=material.vectors.at("LandingLightDirection")[i];
157 Check(std::abs(uploaded.x-expectedAim.x)+std::abs(uploaded.y-expectedAim.y)+std::abs(uploaded.z-expectedAim.z)<1e-5f,"shader receives transformed aim for each lamp");
158 const auto& position=material.vectors.at("LandingLightPosition")[i];
159 Check(std::abs(position.x-expectedOrigin.x)+std::abs(position.y-expectedOrigin.y)+std::abs(position.z-expectedOrigin.z)<1e-7f,"shader receives separate lamp origins");
160 const auto& up=material.vectors.at("LandingLightUp")[i];
161 Check(std::abs(up.x-expectedUp.x)+std::abs(up.y-expectedUp.y)+std::abs(up.z-expectedUp.z)<1e-5f,"shader receives vehicle-aligned cutoff axis");
162 const auto slot=LandingLights::DeviceSlots[i];
163 Check(Rendering::lampDevice.enabled[slot],"both fixed-function lamp slots enabled");
164 const auto& fixed=Rendering::lampDevice.lights[slot];
165 Check(RiseMath::Vec3Dot(&fixed.Direction,&expectedAim)>.99999f,"fixed-function uses same exterior aim");
166 Check(RiseMath::Vec3Dot(&fixed.BeamUp,&expectedUp)>.99999f,"fixed-function uses same cutoff axis");
167 }
168 }
170 Check(material.count==1 && !Rendering::lampDevice.enabled[3],"one-lamp update disables second slot");
171 ship.headlight=false;view.UpdateLandingLights();
172 Check(material.count==0 && !Rendering::lampDevice.enabled[1],"switching lamps off clears renderer count");
173 }
174 void ModelCheck(const char* name, bool overlay, float yaw, bool angled)
175 {
176 const auto effects = Model(name, overlay);
177 std::array<LandingLights::Light, 2> lights;
178 Check(LandingLights::FromModel(effects, lights) == 2, "two authored landing lights");
179 RiseMath::Matrix pitch, turn;
181 RiseMath::MatrixRotationY(&turn, yaw);
182 const auto basis = pitch * turn;
183 const auto left = LandingLights::Transform(lights[0], basis);
184 const auto right = LandingLights::Transform(lights[1], basis);
185 Check(left.origin.x * right.origin.x < 0, "lamps remain on opposite sides");
186 for (const auto& light : {left, right})
187 {
188 Check(light.origin.z < -.015f && light.origin.z > -.016f, "lamp stays at model nose");
189 Check(light.origin.y > .0002f && light.origin.y < .0003f, "model height conversion");
190 Check(light.direction.z < -.999f, "beam points forward after model axis conversion");
191 Check(std::abs(RiseMath::Vec3Length(&light.direction) - 1) < 1e-6f, "unit aim");
192 if (angled) Check(std::abs(std::abs(light.direction.x) - .009f) < 1e-5f, "E-11 authored aim preserved");
193 }
194 RiseMath::Matrix attitude, translation;
195 RiseMath::MatrixRotationYawPitchRoll(&attitude, .7f, -.4f, .3f);
196 RiseMath::MatrixTranslation(&translation, 2, 3, 4);
197 const auto rotated = LandingLights::Transform(lights[0], basis * attitude);
198 const auto moved = LandingLights::Transform(lights[0], basis * attitude * translation);
199 Check(RiseMath::Vec3Dot(&rotated.direction, &moved.direction) > .99999f, "translation cannot change aim");
200 const auto delta = moved.origin - rotated.origin - RiseMath::Vector3(2, 3, 4);
201 Check(RiseMath::Vec3Length(&delta) < 1e-5f, "origin follows full world transform");
202 }
203 void ConditionCheck()
204 {
206 for(int health : {-1,0,63,95,127})
207 {
208 const float expected=health<=0 ? 0.f : health==63 ? .5f : health==95 ? .75f : 1.f;
209 for(double seconds : {0.,1.,1000.})
210 Check(state.Sample(health,seconds,123)==expected,"healthy lamps dim steadily; absent/dead lamps stay off");
211 }
212 // Exercise minutes of operation without sleeping. Compare all common
213 // samples at 120/30 FPS and verify the two circuits do not synchronize.
214 LandingLights::Condition fast,slow,other;
215 unsigned independent=0;
216 for(unsigned frame=0;frame<72000;++frame)
217 {
218 const double time=frame/120.0;
219 const float value=fast.Sample(31,time,123);
220 if(frame%4==0) Check(value==slow.Sample(31,time,123),"flicker is independent of frame rate");
221 if(value!=other.Sample(31,time,456)) ++independent;
222 }
223 Check(independent>1000,"two lamps have independent flicker timing");
224 for(int health : {1,31,62})
225 {
227 unsigned lit=0,edges=0; float previous=-1;
228 for(unsigned sample=0;sample<120000;++sample)
229 {
230 const float value=lamp.Sample(health,sample*.01,321);
231 Check(value==0 || value==.5f,"damaged contact alternates between off and half brightness");
232 if(value>0) ++lit;
233 if(previous>=0 && value!=previous) ++edges;
234 previous=value;
235 }
236 const float duty=lit/120000.f;
237 if(health==1) Check(duty>.04f && duty<.09f && edges>500,"health 1 flashes briefly every few seconds");
238 if(health==62) Check(duty>.91f && duty<.96f && edges>500,"health 62 visibly drops out every few seconds");
239 if(health==31) Check(duty>.3f && duty<.7f,"middle damage has substantial on and off periods");
240 std::cout<<"PASS: landing health "<<health<<" lit "<<duty*100<<"% over 20 minutes, "<<edges<<" transitions\n";
241 }
242 Check(state.Sample(1,1001,123)==0,"severely damaged lamp starts off");
243 Check(state.Sample(127,1002,123)==1,"repair restores full brightness immediately");
244 Check(state.Sample(0,1003,123)==0,"failure removes light immediately");
245 for (unsigned seed=1;seed<=64;++seed)
246 {
248 bool dark=false,lit=false;
249 for (unsigned frame=0;frame<300;++frame)
250 {
251 const float brightness=lamp.Sample(59,double(frame)/60,seed);
252 dark|=brightness==0;lit|=brightness==.5f;
253 }
254 Check(dark && lit,"the latest trace's health 59 has a visible interruption within five seconds");
255 }
257 const int peakHealth=single.Apply(127,0,14,0);
258 for(unsigned fps : {30u,60u,144u})
259 {
261 int health=127;
262 for(unsigned frame=0;frame<fps*2;++frame)
263 health=contact.Apply(health,0,frame<fps?7.f:14.f,double(frame)/fps);
264 Check(health==peakHealth,"contact charges only peak shock at 30/60/144 FPS");
265 Check(contact.Apply(health,0,14,3)<health,"separate impact causes further damage");
266 }
267 }
268#include "LandingLightCollisionChecks.h"
269 void DamageFrameCheck()
270 {
271 playerships={};ourcockpit={};Rendering::lampDevice={};lampLogger.errors.clear();
272 auto& ship=playerships[0];
273 RiseMath::MatrixIdentity(&ship.matrixExterior);
275 ourcockpit.landingLights[0].origin={-.001f,0,0};
276 ourcockpit.landingLights[1].origin={.001f,0,0};
277 ourcockpit.landingLights[0].color=ourcockpit.landingLights[1].color={1,1,1,1};
278 LampMaterialFixture material;LampGameFixture game;LampWeatherFixture weather;
279 game.graphics->g_pEffect=&material;
280 Viewscreen view;view.gameclass=&game;view.ptrWeather=&weather;
282 ourcockpit.vdat.landing[0]=-1;
283 view.UpdateLandingLights();
284 Check(material.count==0 && lampLogger.errors.empty(),"pending vdat cannot light lamps or report false mismatches");
285 ourcockpit.landingDamageVehicleId=ship.vehicleId;
287 ourcockpit.vdat.landing[1]=63;
288 view.UpdateLandingLights();
289 Check(material.count==1 && Rendering::lampDevice.enabled[1] && !Rendering::lampDevice.enabled[3],"dead first lamp leaves only the second beam active");
290 Check(view.landingLights[0].origin.x==.001f,"compacting live beams preserves the original vdat slot");
291 Check(material.vectors.at("LandingLightColor")[0].x==.5f && Rendering::lampDevice.lights[1].Diffuse.r==.5f,"shader and fixed lighting receive half brightness");
292 Check(ourcockpit.landingLightBrightness[0]==0 && ourcockpit.landingLightBrightness[1]==.5f,"sprite brightness retains per-model slot order");
293 const auto& emitters=material.vectors.at("HeadlightEmission");
294 Check(emitters[0].w==0 && emitters[1].w==.5f && emitters[0].x<0 && emitters[1].x>0,
295 "lens material retains dead emitter locations and shares the beam brightness");
296 Check(LandingLights::NearestLamp({.0009f,0,0},ourcockpit.landingLights,2)==1,"extra beam sprites share the nearest lamp circuit");
297 Check(lampLogger.errors.empty(),"installed but dead lamps are not model mismatches");
298 ourcockpit.vdat.landing[0]=-1;
300 Check(lampLogger.errors.size()==1 && lampLogger.errors[0].find("landing0=-1")!=std::string::npos,"absent vdat lamp with a model beam reports one descriptive error");
302 ourcockpit.vdat.landing[0]=127;
303 view.UpdateLandingLights(3);
304 Check(lampLogger.errors.size()==2,"installed second lamp without a model beam also reports a mismatch");
305 ourcockpit.vdat.landing[1]=-1;
306 view.UpdateLandingLights(4);
307 Check(material.count==1 && lampLogger.errors.size()==2,"one installed lamp plus one absent slot is valid");
308 ourcockpit.vdat.landing[0]=31;
309 bool sawOn=false,sawOff=false;
310 for(unsigned tick=0;tick<600;++tick)
311 {
312 view.UpdateLandingLights(4+tick*.1);
313 const bool lit=ourcockpit.landingLightBrightness[0]>0;
314 Check(material.count==int(lit) && Rendering::lampDevice.enabled[1]==lit,"flicker changes the shader count and fixed light together");
315 Check(material.vectors.at("HeadlightEmission")[0].w==ourcockpit.landingLightBrightness[0],
316 "lens, sprite and beam receive the same flicker sample");
317 if(lit)
318 {
319 sawOn=true;
320 Check(view.landingLights[0].color.r==.5f,"shared rain/cloud/fallback light receives flicker brightness");
321 }
322 else sawOff=true;
323 }
324 Check(sawOn && sawOff,"production frame update exercises both phases of a failing lamp");
325 ship.isSimulator=true;ourcockpit.vdat.landing[0]=59;
326 view.UpdateLandingLights(64);
328 "simulator retains legacy damaged-lamp timing");
329 ship.isSimulator=false;view.UpdateLandingLights(64.5);
330 Check(ourcockpit.landingLightCondition[0].meanOn<3 && ourcockpit.landingLightCondition[0].nextTransition<69,
331 "leaving simulator resets the long pending interval to real-world flicker");
332 ship.isSimulator=true;view.UpdateLandingLights(64.6);
333 Check(ourcockpit.landingLightCondition[0].nextTransition>100,
334 "entering simulator clears pending real-world flicker");
335 ship.isSimulator=false;
336 ourcockpit.vdat.landing[0]=127;
337 view.UpdateLandingLights(65);
338 Check(material.count==1 && material.vectors.at("LandingLightColor")[0].x==1,"repair restores the rendered beam immediately");
339 ship.headlight=false;view.UpdateLandingLights(66);
340 Check(material.count==0 && ourcockpit.landingLightBrightness[0]==0,"master switch also clears lamp sprite brightness");
341 Check(material.vectors.at("HeadlightEmission")[0].w==1,
342 "mesh damage state remains available to the separate parked-alarm light switch");
343 ship.headlight=true;ship.vehicleId=2;view.UpdateLandingLights(67);
344 Check(material.count==0 && lampLogger.errors.size()==2,"vehicle switch cannot reuse stale lamp damage");
345 std::cout<<"PASS: damage upload, independent slots, sprite mapping, readiness, mismatch deduplication and switches\n";
346 }
347}
348int main()
349{
350 try
351 {
352 ModelCheck("Meshes/E-10.daw", false, -RiseMath::HalfPi, false);
353 ModelCheck("Meshes/E-11.daw", true, -RiseMath::Pi, true);
354 CarOpticsCheck("Meshes/C-2 Dasher.daw",VehicleType::C2,-RiseMath::HalfPi);
355 CarOpticsCheck("Meshes/C-2A Dasher.daw",VehicleType::C2A,-RiseMath::Pi);
356 FrameCheck("Meshes/C-2 Dasher.daw",true,-RiseMath::HalfPi,.001198f,VehicleType::C2);
357 FrameCheck("Meshes/C-2A Dasher.daw",true,-RiseMath::Pi,.001343f,VehicleType::C2A);
358 ConditionCheck();
359 CrashTimingChecks();
360 StructuralCrushChecks();
361 LongFrameStructuralChecks();
362 ContactGeometryChecks();
363 DamageFrameCheck();
364 CollisionCheck("Meshes/C-2 Dasher.daw",true,-RiseMath::HalfPi);
365 CollisionCheck("Meshes/C-2A Dasher.daw",true,-RiseMath::Pi);
366 CollisionCheck("Meshes/E-10.daw",false,-RiseMath::HalfPi);
367 CollisionCheck("Meshes/E-11.daw",true,-RiseMath::Pi);
368 std::array<LandingLights::Light, 2> lights;
369 std::vector<Effect> effects(1);
370 effects[0].normal = {0, 0, -4};
371 Check(LandingLights::FromModel(effects, lights) == 1, "one-lamp craft");
372 Check(lights[0].direction.z == -1, "normalize imported aim");
373 effects[0].normal = {};
374 Check(LandingLights::FromModel(effects, lights) == 0, "reject zero aim");
375 effects[0].normal = {0, 0, -1};
376 effects[0].position.x = std::numeric_limits<float>::quiet_NaN();
377 Check(LandingLights::FromModel(effects, lights) == 0, "reject invalid origin");
378 auto truck = Model("Meshes/T-120 Steerhead-stock.daw", true);
379 Check(LandingLights::FromModel(truck, lights) == 2, "four lamps respect the two-beam cap");
380 Check(lights[0].origin.y * lights[1].origin.y < 0, "four-lamp model keeps both sides");
381 effects.clear();
382 Check(LandingLights::FromModel(effects, lights) == 0, "switching to no lamps clears count");
383 Check(lights[0].origin == RiseMath::Vector3(), "switching clears previous origins");
384 using namespace LandingLights;
385 for (const auto& item : {std::pair<Profile,float>{CarHigh,.2f}, {TruckDriving,.25f},
386 {AircraftLanding,.5f}, {Train,.3f}, {RoadLow,.08f}})
387 {
388 Check(std::abs(2*IlluminanceLux(item.first,item.second)-5) < .001f,"two-lamp 5 lux throw");
389 Check(std::abs(IlluminanceLux(item.first,item.second/std::sqrt(2.f))-5) < .001f,"one-lamp sqrt(2) throw");
390 Check(IlluminanceLux(item.first,item.first.rangeKm)==0,"range edge fades to zero");
391 Check(IlluminanceLux(item.first,item.second)>IlluminanceLux(item.first,item.second*1.1f),"inverse-square decay");
392 }
393 Check(Angular(RoadLow,0,0,.05f)==0,"road light cannot illuminate above cutoff");
394 Check(Angular(RoadLow,0,-.02f,.05f)>.5f,"road light illuminates below cutoff");
395 Check(Angular(RoadLow,.2f,-.02f,.05f)>0,"road light has a broad horizontal spread");
396 Check(Angular(RoadLow,0,-.2f,.05f)>.01f && Angular(RoadLow,0,-.2f,.05f)<.03f,"road light has weak downward spill beyond its shallow core");
397 Check(Angular(RoadLow,0,-1.f,.05f)==0,"road spill remains bounded below the lamp");
398 Check(Angular(AircraftLanding,0,0,.05f)>.999f,"landing light has no road cutoff");
399 Check(Angular(Train,.25f,0,.05f)<.005f,"train spill is weak outside its core");
400 auto uncut=RoadLow;uncut.cutoffSlope=1000;
401 float previousWidth=0;
402 for(float distance : {.002f,.01f,.05f})
403 {
404 float tenth=-1,ninetieth=-1;
405 for(unsigned mm=0;mm<=1000;++mm)
406 {
407 const float slope=RoadLow.cutoffSlope-mm*.000001f/distance;
408 const float fraction=Angular(RoadLow,0,slope,distance)/Angular(uncut,0,slope,distance);
409 if(tenth<0 && fraction>=.1f) tenth=float(mm);
410 if(fraction>=.9f) { ninetieth=float(mm);break; }
411 }
412 const float width=ninetieth-tenth;
413 Check(tenth>=0 && ninetieth>tenth && width>35,"near wall cutoff has a measurable soft transition");
414 Check(width>previousWidth,"cutoff feather grows in physical width with distance");
415 previousWidth=width;
416 std::cout<<"PASS: cutoff 10-90% transition at "<<distance*1000<<" m spans "<<width<<" mm\n";
417 }
418 RiseMath::Matrix identity,roll;
419 RiseMath::MatrixIdentity(&identity);
421 Light road; road.profile=RoadLow;
422 const RiseMath::Vector3 below(0,-.001f,-.05f);
423 RiseMath::Vector3 rotatedBelow;
424 RiseMath::Vec3TransformNormal(&rotatedBelow,&below,&roll);
425 const auto rolled=Transform(road,roll);
426 Check(std::abs(Intensity(road,below)-Intensity(rolled,rotatedBelow))<1e-5f,"cutoff rotates with vehicle attitude");
427 Check(Intensity(road,{0,0,.05f})==0,"nothing behind the lamp is lit");
428 auto foggy=road;foggy.extinctionPerKm=40;
429 Check(Intensity(foggy,below)<Intensity(road,below)*.2f,"fog attenuates light along the lamp path");
430 const auto verticalUp=OrthonormalUp(RiseMath::Vector3(0,1,0),RiseMath::Vector3(0,1,0));
431 Check(std::abs(RiseMath::Vec3Length(&verticalUp)-1)<1e-6f && verticalUp.y==0,"vertical lamp gets a finite orthogonal up axis");
432 struct FogVertex {float x,y,z;uint32_t diffuse;};
433 std::array<FogVertex,FogVertexCount> fog{};
434 FogMesh(road,fog.data(),true);
435 for (const auto& vertex:fog)
436 {
437 Check(std::isfinite(vertex.x) && vertex.z<0,"finite forward fog mesh");
438 Check(vertex.y<=-vertex.z*road.profile.cutoffSlope+1e-7f,"fog mesh respects low-beam cutoff");
439 if (std::abs(vertex.z+road.profile.rangeKm)<1e-6f) Check((vertex.diffuse>>24)==0,"fog beam fades at profile range");
440 }
441 std::cout << "PASS: vehicle profiles, photometric throw, low-beam cutoff, roll, fog attenuation and exterior mesh\n";
442 std::cout << "PASS: E-10/E-11 origins and aims, world transforms, 0/1/2 lamps, invalid data and four-lamp selection\n";
443 std::cout << "PASS: C-2/C-2A production frame update retains both exterior lamp poses after physics overwrites matrixWorld\n";
444 return 0;
445 }
446 catch (const std::exception& error) { std::cerr << "FAIL: " << error.what() << '\n'; return 1; }
447}
@ C2
Definition ServerTypes.h:66
@ C2A
Definition ServerTypes.h:81
unsigned activeLandingLightCount
Definition Viewscreen.h:330
std::array< LandingLights::Light, LandingLights::MaxLights > landingLights
Definition Viewscreen.h:329
GameClass * gameclass
Definition Viewscreen.h:439
std::unique_ptr< weather > ptrWeather
Definition Viewscreen.h:434
void UpdateLandingLights(double seconds)
Definition framemove.cpp:23
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
Scockpit ourcockpit
Definition globals.cpp:114
constexpr Profile AircraftLanding
Definition BeamProfile.h:38
Light Configure(Light light, unsigned char type, const RiseMath::Matrix &modelBase)
unsigned FromModel(const Effects &effects, std::array< Light, MaxLights > &lights)
float IlluminanceLux(const Profile &profile, float distanceKm)
Definition BeamProfile.h:81
float Intensity(const Light &light, const RiseMath::Vector3 &delta)
Vector OrthonormalUp(Vector up, const Vector &direction)
Definition BeamProfile.h:43
constexpr Profile RoadLow
Definition BeamProfile.h:35
constexpr unsigned DeviceSlots[MaxLights]
constexpr Profile CarHigh
Definition BeamProfile.h:36
constexpr Profile Train
Definition BeamProfile.h:40
float Angular(const Profile &profile, float horizontalSlope, float verticalSlope, float axialDistanceKm)
Definition BeamProfile.h:66
constexpr Profile TruckDriving
Definition BeamProfile.h:37
void FogMesh(const Light &light, Vertex *output, bool spill)
unsigned NearestLamp(const RiseMath::Vector3 &origin, const std::array< Light, MaxLights > &lights, unsigned count)
Light Transform(const Light &source, const RiseMath::Matrix &modelToWorld)
float Vec3Length(const Vector3 *a)
Definition ClientMath.h:95
constexpr float Pi
Definition ClientMath.h:12
Vector3 * Vec3TransformCoord(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:109
Matrix * MatrixRotationX(Matrix *out, float value)
Definition ClientMath.h:126
Quaternion * QuaternionRotationYawPitchRoll(Quaternion *out, float yaw, float pitch, float roll)
Definition ClientMath.h:169
Vector3 * Vec3TransformNormal(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:107
Matrix * MatrixRotationY(Matrix *out, float value)
Definition ClientMath.h:127
Matrix * MatrixRotationYawPitchRoll(Matrix *out, float yaw, float pitch, float roll)
Definition ClientMath.h:137
Matrix * MatrixIdentity(Matrix *out)
Definition ClientMath.h:115
float Vec3Dot(const Vector3 *a, const Vector3 *b)
Definition ClientMath.h:93
Matrix * MatrixRotationZ(Matrix *out, float value)
Definition ClientMath.h:128
Matrix * MatrixTranslation(Matrix *out, float x, float y, float z)
Definition ClientMath.h:125
constexpr float HalfPi
Definition ClientMath.h:12
type
Definition erin.py:143
float Sample(int health, double seconds, uint32_t lampSeed, bool simulator=false)
int Apply(int health, float clearanceKm, float closingMps, double seconds)
RiseMath::Vector3 origin
char landing[2]
int landingDamageVehicleId
Definition globals.h:606
SVesselDC vdat
Definition globals.h:664
std::array< LandingLights::Condition, LandingLights::MaxLights > landingLightCondition
Definition globals.h:607
std::array< float, LandingLights::MaxLights > landingLightBrightness
Definition globals.h:609
std::array< LandingLights::Light, LandingLights::MaxLights > landingLights
Definition globals.h:604
unsigned landingLightCount
Definition globals.h:605
unsigned char type
Definition globals.h:488