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

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

1#include "../Viewscreen/SparkoProp.h"
2#include "../Viewscreen/SparkoTrace.h"
3#include "../Rendering/ClientMath.h"
4#include <cstdio>
5#include <cstdlib>
6#include <limits>
7#include <fstream>
8using namespace RigidProp;
9static int failures=0;
10static void Check(bool condition,const char* message) { if(!condition) {std::printf("FAIL: %s\n",message);++failures;} }
11static Pose Authored() {return {{130,123,-122},Quat::Ypr(-1.570796,0,-1.308997)};}
12static Motion Gravity() {return {{0,0,-11.27/(SparkoGeometry::KmPerUnit*1000)},{},{}};}
13static Simulation Can() {return {SparkoGeometry::Can(),SparkoGeometry::Footwell(),Authored()};}
14static void Run(Simulation& s,double seconds,Motion m=Gravity(),int hz=60) {
15 for(double elapsed=0;elapsed<seconds-1e-10;elapsed+=1.0/hz) s.Update(std::min(1.0/hz,seconds-elapsed),m);
16}
17static void Dump(const char* label,const Simulation& s) {const auto&p=s.body.pose.position;std::printf("%s: xyz %.3f %.3f %.3f v %.3f spin %.3f sleep %d budget %u\n",label,p.x,p.y,p.z,Length(s.body.velocity),Length(s.body.omega),s.body.sleeping,s.sweepBudgetStops);}
18static void FloorClear(const Simulation&s) {Check(Support(s.Shape(),s.body.pose,{0,0,-1}).z>=-126.002,"whole hull clears floor");}
19static bool SamePose(const Pose& a,const Pose& b) {
20 return Length(a.position-b.position)<1e-9 && std::abs(a.rotation.x-b.rotation.x)+
21 std::abs(a.rotation.y-b.rotation.y)+std::abs(a.rotation.z-b.rotation.z)+std::abs(a.rotation.w-b.rotation.w)<1e-9;
22}
23static void TestPropAudio() {
24 PropAudio::State audio;
25 PropAudio::Input input{true,true,true,false,false,.2,.2,1};
26 Check(audio.Update(1.0/60,input).startRolling,"rolling starts one sound");
27 int starts=0;
28 for(int i=0;i<120;++i) {++input.frame;starts+=audio.Update(1.0/60,input).startRolling;}
29 Check(starts==0,"sustained rolling does not restart its recording each frame");
30 input.advanced=false;input.contact=false;++input.frame;
31 Check(!audio.Update(1.0/1000,input).stopRolling,"no-substep render frame keeps rolling episode");
32 input.advanced=true;
33 for(int i=0;i<3;++i) {++input.frame;Check(!audio.Update(1.0/60,input).stopRolling,"brief faceted-rim contact gap is quiet");}
34 input.contact=true;++input.frame;
35 Check(!audio.Update(1.0/60,input).startRolling,"contact gap does not retrigger rolling");
36 input.contact=false;
37 int stops=0;
38 for(int i=0;i<15;++i) {++input.frame;stops+=audio.Update(1.0/60,input).stopRolling;}
39 Check(stops==1,"airborne prop stops rolling sound");
40 input.contact=true;input.rotationSpeedMps=0;++input.frame;
41 Check(!audio.Update(1.0/60,input).startRolling,"sliding without rotation does not start a roll sound");
42 input.rotationSpeedMps=.2;input.impact=true;++input.frame;
43 auto events=audio.Update(1.0/60,input);
44 Check(events.startRolling && events.hit,"new rolling and edge impact can sound together");
45 Check(!audio.Update(.2,input).hit,"re-reading the same physics frame cannot replay an impact");
46 ++input.frame;Check(audio.Update(1.0/60,input).hit,"later impact can select another sample");
47 ++input.frame;Check(!audio.Update(1.0/60,input).hit,"adjacent solver impacts are debounced");
48 input.sleeping=true;input.impact=false;++input.frame;
49 Check(audio.Update(1.0/60,input).stopRolling,"sleep stops the rolling sample");
50 input.active=false;
51 Check(audio.Update(1.0/60,input).stopAll,"inactivity clears impact tails as well as rolling");
52 input.active=true;input.sleeping=false;++input.frame;
53 Check(audio.Update(1.0/60,input).startRolling,"resuming starts a fresh rolling episode");
54 Check(audio.Update(.3,input).stopAll,"hitch clears playing sounds");
55
56 // Actual controller/solver events: support impulses are not edge impacts.
57 SparkoProp::Controller prop(71,Authored().position*SparkoGeometry::KmPerUnit,{-1.570796,0,-1.308997});
58 SparkoProp::Sample force{{0,11.27,0},{},{0,3000,0},{},false,{}};
59 audio.Reset();int restHits=0,restRolls=0;
60 for(int i=0;i<180;++i) {
61 prop.Update(1.0/60,force);auto e=audio.Update(1.0/60,prop.AudioInput(true));
62 restHits+=e.hit;restRolls+=e.startRolling;
63 }
64 Check(restHits==0 && restRolls<=1,"initial settling has no impact chatter and at most one rolling start");
65 for(int i=0;i<120;++i) {
66 prop.Update(1.0/60,force);auto e=audio.Update(1.0/60,prop.AudioInput(true));
67 Check(!e.hit && !e.startRolling,"settled can remains silent under continuous support load");
68 }
69 force.specificForceMss.z=-5;
70 int driveHits=0,driveRolls=0;
71 for(int i=0;i<120;++i) {
72 prop.Update(1.0/60,force);auto e=audio.Update(1.0/60,prop.AudioInput(true));
73 driveHits+=e.hit;driveRolls+=e.startRolling;
74 }
75 Check(driveRolls>0,"actual reverse acceleration triggers rolling audio");
76 Check(driveHits>0,"actual footwell collision triggers impact audio");
77 Check(driveHits<20 && driveRolls<10,"sustained contact does not chatter each render frame");
78 force.suppressed=true;prop.Update(1.0/60,force);
79 events=audio.Update(1.0/60,prop.AudioInput(true));
80 Check(events.stopAll && !events.hit && !events.startRolling,"suppression clears audio without a spawn impact");
81 force.suppressed=false;prop.Update(1.0/60,force);
82 events=audio.Update(1.0/60,prop.AudioInput(true));
83 Check(!events.hit && !events.startRolling,"suppression exit primes quietly");
84 prop.Update(.3,force);
85 Check(!prop.AudioInput(true).active,"controller hitch recovery cannot generate audio");
86 std::printf("Prop audio: rest hits/rolls %d/%d; driving hits/rolls %d/%d\n",restHits,restRolls,driveHits,driveRolls);
87}
88int main(int argc,char** argv) {
89 TestPropAudio();
90 auto s=Can();
91 Check(s.Shape().vertices.size()==24,"actual can hull");
92 Check(s.Scene().size()>150,"dashboard and obstacle geometry present");
93 Check(std::abs(Length(Vec{3,3,0})-std::sqrt(18.0))<1e-10,"can radial bound includes diagonal vertices");
94 FloorClear(s);Run(s,3);Dump("rest",s);FloorClear(s);
95 Check(s.body.sleeping,"settled can sleeps");
96 Check(Length(s.body.pose.position-Authored().position)<1,"small initial overlap settles locally");
97 Motion brake=Gravity();brake.acceleration.y=800;
98 Run(s,.25,brake);Dump("brake",s);
99 Check(!s.body.sleeping && s.body.pose.position.y>124,"acceleration wakes and moves can");
100 Check(Length(s.body.omega)>1,"floor friction produces rolling spin");FloorClear(s);
101 s.Reset();Check(Length(s.body.velocity)==0 && Length(s.body.omega)==0,"reset clears motion");
102 s.body.pose.position={124,53,-121.9};Run(s,1);const Pose seatPose=s.body.pose;
103 s.body.velocity={20,30,40};s.body.omega={1,2,3};s.Update(1,Gravity());
104 Check(Length(s.body.velocity)==0 && Length(s.body.omega)==0 && SamePose(s.body.pose,seatPose),"long frame discards motion without respawning from under seat");
105 s.Update(.01,{{std::numeric_limits<double>::quiet_NaN(),0,0},{},{}});
106 Check(SamePose(s.body.pose,seatPose),"invalid force preserves current pose");
107 s.body.pose.rotation.x=std::numeric_limits<double>::quiet_NaN();s.Update(.01,Gravity());
108 Check(SamePose(s.body.pose,seatPose),"invalid body recovers last valid seat pose");
109 Run(s,.1);Check(Length(s.body.pose.position-seatPose.position)<1,"normal simulation resumes locally after hitch");
110 auto a=Can(),b=Can(),c=Can();Run(a,1,brake,30);Run(b,1,brake,60);Run(c,1,brake,144);
111 Check(Length(a.body.pose.position-b.body.pose.position)<1e-6 && Length(b.body.pose.position-c.body.pose.position)<1e-6,"fixed steps agree at 30/60/144 Hz");
112 for(Vec velocity:std::vector<Vec>{{0,4000,0},{0,-4000,0},{4000,0,0},{-4000,0,0},{0,0,-4000},{0,0,3000}}) {
113 auto fast=Can();fast.body.velocity=velocity;Run(fast,.5);Dump("swept",fast);FloorClear(fast);
114 Check(fast.body.pose.position.x>83 && fast.body.pose.position.x<171,"high-speed side containment");
115 Check(Support(fast.Shape(),fast.body.pose,{0,-1,0}).y>=47.998,"rear stop full shape");
116 Check(Support(fast.Shape(),fast.body.pose,{0,1,0}).y<=158.002,"front wall full shape");
117 Check(Support(fast.Shape(),fast.body.pose,{0,0,1}).z<=-33.998,"upper footwell containment");
118 }
119 // The lower monitor neck is a six-unit-wide solid, not a point exclusion.
120 auto post=Can();post.body.pose.position={113,75,-120};post.body.velocity={-2000,0,0};
121 Run(post,.025);Dump("post",post);
122 Check(Support(post.Shape(),post.body.pose,{-1,0,0}).x>=94.98,"swept rim cannot tunnel through monitor post");
123 // Impulse at an end of the can must generate torque; head-on central impact must bounce.
124 Body edge;edge.pose=Authored();std::vector<Contact> hit{{{0,0,1},{7,0,-4}}};edge.velocity={0,0,-100};
125 Solve(edge,hit,Material{},1.0/240);Check(Length(edge.omega)>1,"edge collision generates angular response");
126 Body centre;centre.velocity={0,0,-100};std::vector<Contact> middle{{{0,0,1},{0,0,-4}}};
127 Solve(centre,middle,Material{},1.0/240);Check(centre.velocity.z>0 && centre.velocity.z<100,"controlled bounce loses energy");
128 Body moving;moving.pose.position={100,100,-120};moving.velocity={0,10,0};
129 Motion turning{{},{0,0,1},{0,0,.5}};
130 Vec force=Acceleration(moving,turning);
131 Check(Length(force-Vec{170,50,0})<1e-8,"centrifugal Euler and Coriolis terms");
132 // Independent renderer matrix checks protect authored axes, quaternion order,
133 // and the metre/kilometre bridge rather than just re-testing the solver.
135 RiseMath::MatrixRotationYawPitchRoll(&renderer,-1.570796f,0,-1.308997f);
136 for(Vec v:s.Shape().vertices) {
137 RiseMath::Vector3 input(float(v.x),float(v.y),float(v.z)),output;
139 Check(Length(Authored().rotation.Rotate(v)-Vec{output.x,output.y,output.z})<1e-5,"authored quaternion matches production renderer");
140 }
142 RiseMath::Vector3 author(1,2,3),physics;
143 RiseMath::Vec3TransformNormal(&physics,&author,&renderer);
144 Check(Length(SparkoProp::FromPhysics({-physics.x,-physics.y,-physics.z})-Vec{1,2,3})<1e-6,"view-to-propulsion-to-ASM axis bridge");
145 Vec nominal=Authored().position*SparkoGeometry::KmPerUnit,ypr{-1.570796,0,-1.308997};
146 Check(SparkoProp::Matches(70,true,nominal,ypr,44),"type 70 matching can opts in");
147 Check(!SparkoProp::Matches(48,true,nominal,ypr,44) && !SparkoProp::Matches(0,true,nominal,ypr,44),"48 and static props never opt in");
148 Check(!SparkoProp::Matches(70,false,nominal,ypr,44) && !SparkoProp::Matches(70,true,nominal+Vec{.001,0,0},ypr,44),"unconfigured type 70 props remain static");
149 SparkoProp::Controller control(71,nominal,ypr);
150 SparkoProp::Sample sample{{0,11.27,0},{},{0,3000,0},{},false,{-.0002,.0002,-.0002}};
151 for(int i=0;i<180;++i)control.Update(1.0/60,sample);
152 Check(control.simulation.body.sleeping && control.simulation.body.pose.position.z<-117,"runtime positive support force gives downward Vieneo gravity");
153 sample.specificForceMss.z=-5;
154 for(int i=0;i<20;++i)control.Update(1.0/60,sample);
155 Check(control.simulation.body.pose.position.y>125,"runtime acceleration and units move can forward");
156 // Reverse acceleration must carry the can forward beyond the authored spawn,
157 // including a start under the seat. No spring or position limit at spawn.
158 for(double acceleration:{2.,5.,10.}) for(bool underSeat:{false,true}) {
159 SparkoProp::Controller reverse(71,nominal,ypr);
160 SparkoProp::Sample backing{{0,11.27,-acceleration},{},{0,3000,0},{},false,{}};
161 if(underSeat) reverse.simulation.body.pose=seatPose;
162 double furthest=reverse.simulation.body.pose.position.y;
163 for(int frame=0;frame<360;++frame) {
164 reverse.Update(1.0/60,backing);
165 furthest=std::max(furthest,reverse.simulation.body.pose.position.y);
166 }
167 std::printf("reverse %.1f m/s2 seat=%d furthestY=%.3f\n",acceleration,underSeat,furthest);
168 // A transverse can may stick at 2 m/s^2 under the existing dry-friction
169 // model (.38 * 11.27 = 4.28 m/s^2). Stronger loading must release it.
170 if(!underSeat || acceleration>=5) Check(furthest>128,"reverse acceleration passes spawn from floor and seat");
171 Check(reverse.resets==0,"steady reverse does not reset prop");
172 if(underSeat && acceleration==2) {
173 SparkoProp::Controller frictionless(71,nominal,ypr);
174 frictionless.simulation.body.pose=seatPose;
175 frictionless.simulation.material.friction=0;frictionless.simulation.material.rollingResistance=0;
176 double released=seatPose.position.y;
177 for(int frame=0;frame<360;++frame) {
178 frictionless.Update(1.0/60,backing);
179 released=std::max(released,frictionless.simulation.body.pose.position.y);
180 }
181 Check(released>128,"weak reverse seat hold comes from contact friction rather than spawn clamp");
182 }
183 }
184 // A cabin downward acceleration exceeding gravity permits lift-off. Once
185 // support returns, the free can falls and settles. No floor attachment.
186 auto airborne=Can();Run(airborne,1);
187 Motion lift;lift.acceleration={0,0,800};Run(airborne,.15,lift);
188 Check(Support(airborne.Shape(),airborne.body.pose,{0,0,-1}).z>-120,"entire can becomes airborne");
189 Check(airborne.body.velocity.z>0,"lift-off has upward velocity");
190 Run(airborne,3);FloorClear(airborne);
191 Check(airborne.body.sleeping,"airborne can lands and settles");
192 // Diagnostic balances must explain every solver delta, including impacts,
193 // positional repair and discarded motion.
194 auto accounting=Can();accounting.body.velocity={1400,-1800,650};accounting.body.omega={20,30,40};
195 for(int frame=0;frame<240;++frame) {
196 Body before=accounting.body;accounting.Update(1.0/60,Gravity());const auto& stats=accounting.stats;
197 Check(Length(accounting.body.velocity-before.velocity-stats.forceDeltaV-stats.contactDeltaV-stats.discardDeltaV)<1e-8,"trace balances linear velocity");
198 Check(Length(accounting.body.omega-before.omega-stats.forceDeltaOmega-stats.contactDeltaOmega-stats.discardDeltaOmega)<1e-8,"trace balances angular velocity");
199 Check(Length(accounting.body.pose.position-before.pose.position-stats.integratedPosition-stats.positionCorrection)<1e-8,"trace distinguishes integration from position repair");
200 }
201 // CSV rotation keeps a complete schema/geometry manifest, bounds disk use,
202 // permits live readers, and a bad output directory cannot affect physics.
203 const auto traceDir=std::filesystem::temp_directory_path()/L"RiseSparkoTraceTests";
204 std::filesystem::create_directories(traceDir);
205 {
206 SparkoProp::TraceFile trace(traceDir,65536);
207 SparkoProp::Controller capture(71,nominal,ypr);
208 capture.Reset("test, \"reset\"");
209 for(int frame=0;frame<240;++frame) {
210 capture.Update(1.0/60,sample);trace.Write(1.0/60,sample,capture,{});
211 }
212 trace.Flush();Check(!trace.Failed(),"bounded CSV capture succeeds");
213 for(const auto* name:{L"SparkoPhysics.csv",L"SparkoPhysics.previous.csv"}) {
214 const auto path=traceDir/name;
215 Check(std::filesystem::exists(path) && std::filesystem::file_size(path)<=65536,"trace rotates within byte limit");
216 std::ifstream recorded(path);std::string line;unsigned triangles=0;bool foundHeader=false,foundRow=false;
217 while(std::getline(recorded,line)) {
218 if(line.find("# triangle,")==0 && line.find("# triangle,id,")!=0) ++triangles;
219 if(line.find("frame,program_seconds,dt,action,")==0) foundHeader=true;
220 if(line.find("\"test, \"\"reset\"\"\"")!=std::string::npos) foundRow=true;
221 }
222 Check(triangles==185 && foundHeader && foundRow,"each trace segment has geometry schema and escaped reset reason");
223 }
224 SparkoProp::TraceFile unavailable(traceDir/L"SparkoPhysics.csv");
225 unavailable.Write(1.0/60,sample,capture,{});
226 Check(unavailable.Failed(),"unwritable trace is nonfatal");
227 }
228 std::filesystem::remove(traceDir/L"SparkoPhysics.csv");
229 std::filesystem::remove(traceDir/L"SparkoPhysics.previous.csv");
230 sample.suppressed=true;control.Update(1.0/60,sample);
231 Check(Length(control.simulation.body.velocity)==0 && Length(control.simulation.body.pose.position-Authored().position)<1,"simulator entry resets all transient state");
232 sample.specificForceMss={500,500,500};for(int i=0;i<10;++i)control.Update(1.0/60,sample);
233 Check(Length(control.simulation.body.velocity)==0,"simulator does not accumulate hidden motion");
234 sample.suppressed=false;control.Update(1.0/60,sample);
235 Check(Length(control.simulation.body.velocity)==0,"simulator exit primes history without replay");
236 sample.specificForceMss={0,11.27,0};sample.positionKm.x+=1;control.Update(1.0/60,sample);
237 Check(Length(control.simulation.body.velocity)==0,"teleport resets and primes force/rate history");
238 control.simulation.body.velocity={20,30,40};control.Reset();
239 Check(Length(control.simulation.body.velocity)==0,"explicit relocation/cockpit reset clears motion");
240 // Live capture 2026-10-10: inertial velocity includes ~355 m/s of planet
241 // rotation while position is planet-fixed. These four ordinary driving
242 // frames falsely crossed the old 10 m relocation threshold. Position deltas
243 // are the recorded float samples; the rotation component is from the
244 // stationary part of that same capture (sufficient to sub-metre accuracy).
245 struct RecordedRelocation {double dt;Vec delta,velocity,can;Quat rotation;};
246 const Vec surfaceVelocity{.3186473548412323,-.15561601519584656,0};
247 const RecordedRelocation recorded[] {
248 {.041927199810743332,{.0001220703125,0,.00018310546875},{.32389992475509644,-.1576732099056244,.00460659759119153},{160.462803982918,71.95972884059391,-121.86628699847955},{.70154572976729612,-.081745817497776069,-.2600635858167758,-.65842094567154597}},
249 {.028978999704122543,{0,0,.0001678466796875},{.31767502427101135,-.15470671653747559,.005578816868364811},{106.44007680701388,148.85551718191496,-121.82180873482312},{.066933354535684109,-.70402940721991403,-.69441376946876832,-.13286096715120363}},
250 {.029773600399494171,{0,0,.0001068115234375},{.3213927149772644,-.1565895527601242,.00363371754065156},{161.4932390421108,113.69113195807364,-121.70557527838132},{.54588268515617122,.45056420289940857,.1331674396430915,-.69373656825282937}},
251 {.048822298645973206,{0,0,.0000457763671875},{.31894993782043457,-.15570279955863953,.0007344036712311208},{130.63016855573338,153.74920653493854,-121.74261997647852},{-.2186397486828206,.67177714814860856,.21828070802455571,-.67325006945824684}}
252 };
253 for(const auto& frame:recorded) {
254 Check(Length(frame.delta-frame.velocity*frame.dt)>.01,"recorded driving frame reproduces old relocation threshold");
255 SparkoProp::Controller driven(71,nominal,ypr);
256 SparkoProp::Sample driving{{0,11.27,0},{},{},frame.velocity,false,{},surfaceVelocity};
257 driven.Update(1.0/60,driving);driven.simulation.body.pose={frame.can,frame.rotation};
258 driving.positionKm=frame.delta;driven.Update(frame.dt,driving);
259 Check(driven.resets==0 && std::string(driven.action)=="step","recorded driving frame must not respawn can");
260 Check(driven.relocationErrorKm<.001,"relocation residual uses planet-fixed velocity");
261 Check(Length(driven.simulation.body.pose.position-frame.can)<1,"recorded can stays local at seat and outer wall");
262 driving.positionKm.x+=1;driven.Update(1.0/60,driving);
263 Check(driven.resets==1 && driven.resetReason=="position_discontinuity","real teleport still resets with planet rotation present");
264 }
265 SparkoProp::Controller parked(71,nominal,ypr);
266 SparkoProp::Sample stationary{{0,11.27,0},{},{},surfaceVelocity,false,{},surfaceVelocity};
267 parked.Update(1.0/60,stationary);parked.simulation.body.pose=seatPose;
268 for(int frame=0;frame<90;++frame) parked.Update(frame%2?1.0/30:1.0/60,stationary);
269 Check(parked.resets==0 && Length(parked.simulation.body.pose.position-seatPose.position)<1,"stationary rotating-planet cabin does not reset at 30 Hz");
270 const Pose parkedPose=parked.simulation.body.pose;
271 stationary.barycentricKms.x=std::numeric_limits<double>::quiet_NaN();parked.Update(1.0/60,stationary);
272 Check(parked.resets==0 && SamePose(parked.simulation.body.pose,parkedPose) &&
273 std::string(parked.action)=="invalid_sample_hold","invalid rotation velocity preserves can pose");
274 SparkoProp::Controller hitch(71,nominal,ypr);
275 SparkoProp::Sample steady{{0,11.27,0},{},{0,3000,0},{},false,{}};
276 hitch.Update(1.0/60,steady);
277 hitch.simulation.body.pose=seatPose;
278 hitch.simulation.body.velocity={20,-30,40};hitch.simulation.body.omega={1,2,3};
279 hitch.Update(.3,steady);
280 Check(hitch.resets==0 && std::string(hitch.action)=="hitch_hold" && std::string(hitch.simulation.stats.recovery)=="hitch_hold","trace labels a hitch without reporting a reset");
281 Check(SamePose(hitch.simulation.body.pose,seatPose) && Length(hitch.simulation.body.velocity)==0 &&
282 Length(hitch.simulation.body.omega)==0,"controller 300 ms hitch cannot send can to other end of footwell");
283 steady.inverseOrientationRates={.1,.2,.3};hitch.Update(1.0/60,steady);
284 Check(SamePose(hitch.simulation.body.pose,seatPose),"first good sample after hitch primes rates without replay");
285 steady.cameraViewMountKm.x=std::numeric_limits<double>::quiet_NaN();hitch.Update(1.0/60,steady);
286 Check(SamePose(hitch.simulation.body.pose,seatPose),"invalid mount sample preserves seat position");
287 steady.cameraViewMountKm={};hitch.Update(1.0/60,steady);
288 Check(SamePose(hitch.simulation.body.pose,seatPose),"invalid sample recovery primes history");
289 steady.suppressed=true;hitch.Update(0,steady);
290 Check(Length(hitch.simulation.body.pose.position-Authored().position)<1,"simulator entry still resets during zero-length frame");
291 steady.suppressed=false;hitch.Update(1.0/60,steady);
292 Check(Length(hitch.simulation.body.velocity)==0,"simulator exit after pause does not replay motion");
293 auto door=Can();door.body.pose={{140,101,-105},{}};door.body.velocity={2000,0,0};
294 for(int i=0;i<6;++i) {
295 door.Update(1.0/240,Gravity());Dump("door step",door);
296 double gap=100;for(const auto&t:door.Scene()) if(Near(door.body,t,0)) gap=std::min(gap,Query(door.Shape(),door.body.pose,t).gap);
297 Check(gap>-.05,"door sweep leaves no hull/triangle penetration");
298 }
299 Check(door.body.velocity.x<1500 && door.body.velocity.z<-100,"inward door face deflects can down before outer sill");
300 auto seat=Can();seat.body.pose.position={124,55,-121.9};seat.body.velocity={0,0,1000};
301 Run(seat,.025);Dump("seat lip",seat);
302 Check(Support(seat.Shape(),seat.body.pose,{0,0,1}).z<-101,"real seat front underside blocks upward flight");
303 auto overhang=Can();overhang.body.pose.position={124,53,-121.9};Run(overhang,2);
304 Check(overhang.body.sleeping && Support(overhang.Shape(),overhang.body.pose,{0,-1,0}).y>=48 &&
305 Support(overhang.Shape(),overhang.body.pose,{0,1,0}).y<58,"whole can fits and rests under the front seat overhang");
306 for(double x:{105.,124.,140.}) for(double rearwardForce:{300.,800.}) {
307 auto entry=Can();entry.body.pose.position={x,100,-121.9};
308 Motion rearward=Gravity();rearward.acceleration.y=-rearwardForce;
309 for(int frame=0;frame<240;++frame) {
310 Vec before=entry.body.pose.position;entry.Update(1.0/60,rearward);
311 Check(Length(entry.body.pose.position-before)<5,"rolling into seat overhang never causes a large position jump");
312 Check(Support(entry.Shape(),entry.body.pose,{0,-1,0}).y>=47.998,"seat entry preserves rear stop");
313 FloorClear(entry);
314 }
315 Check(entry.body.pose.position.y<58,"rearward loading brings can under seat locally");
316 }
317 auto slide=Can(),grip=Can();slide.material.friction=0;slide.material.rollingResistance=0;
318 slide.body.velocity=grip.body.velocity={0,80,0};Run(slide,.1);Run(grip,.1);
319 Check(Length(slide.body.velocity)>Length(grip.body.velocity) && Length(grip.body.omega)>Length(slide.body.omega),"sliding friction trades translation for rolling");
320 auto tilt=Can();Motion slope=Gravity();slope.acceleration.y=400;Run(tilt,.5,slope);
321 Check(tilt.body.pose.position.y>124,"tilted gravity produces downhill motion");
322 unsigned seed=1048;
323 auto random=[&]() {seed=1664525*seed+1013904223;return (double(seed)/4294967295.0)*2-1;};
324 for(int scenario=0;scenario<16;++scenario) {
325 auto stress=Can();stress.body.velocity={random()*3000,random()*3000,random()*3000};
326 stress.body.omega={random()*80,random()*80,random()*80};
327 for(int tick=0;tick<90;++tick) {
328 stress.Update(1.0/240,Gravity());
329 FloorClear(stress);
330 Check(Support(stress.Shape(),stress.body.pose,{0,0,1}).z<=-33.998,"stress upper bound");
331 Check(Support(stress.Shape(),stress.body.pose,{0,-1,0}).y>=47.998,"stress rear bound");
332 Check(Support(stress.Shape(),stress.body.pose,{0,1,0}).y<=158.002,"stress forward bound");
333 Check(Support(stress.Shape(),stress.body.pose,{1,0,0}).x<=171.002,"stress sill bound");
334 Vec n{1,-11.0/113,0};
335 Check(Dot(Support(stress.Shape(),stress.body.pose,-n),n)>=83-45*11.0/113-.002,"stress tapered console bound");
336 }
337 }
338 if(argc==2) {
339 std::ofstream trace(argv[1]);
340 Check(bool(trace),"trace output opens");
341 trace<<"time,x,y,z,qx,qy,qz,qw\n";
342 auto preview=Can();
343 for(int frame=0;frame<121;++frame) {
344 const auto&p=preview.body.pose;const auto&q=p.rotation;
345 trace<<frame/60.0<<','<<p.position.x<<','<<p.position.y<<','<<p.position.z<<','<<q.x<<','<<q.y<<','<<q.z<<','<<q.w<<'\n';
346 Motion drive=Gravity();
347 drive.acceleration.y=frame<35?600:frame<70?-450:0;
348 drive.acceleration.x=frame>=70?450:0;
349 preview.Update(1.0/60,drive);
350 }
351 }
352 if(argc==3 && std::string(argv[1])=="--diagnostics") {
353 std::filesystem::create_directories(argv[2]);
354 SparkoProp::TraceFile trace(argv[2],65536);
355 SparkoProp::Controller capture(71,nominal,ypr);
356 SparkoProp::Sample input{{0,11.27,0},{},{0,3000,0},{},false,{}};
357 for(int frame=0;frame<360;++frame) {
358 input.specificForceMss.z=frame<100?5:-5;
359 if(frame==330) capture.Reset("diagnostic, \"reset\"");
360 double dt=frame==350?.3:1.0/60;
361 capture.Update(dt,input);trace.Write(dt,input,capture,{frame/60.0});
362 }
363 trace.Flush();Check(!trace.Failed(),"diagnostic fixture capture succeeds");
364 }
365 std::printf("Rigid prop tests: %d failures\n",failures);return failures?1:0;
366}
Events Update(double dt, const Input &input)
Definition PropAudio.h:21
void Update(double dt, const Motion &motion)
Definition RigidProp.h:332
const std::vector< Triangle > & Scene() const
Definition RigidProp.h:316
unsigned sweepBudgetStops
Definition RigidProp.h:313
const Hull & Shape() const
Definition RigidProp.h:315
Vec Gravity(Vec r, double gm)
Definition OrbitProfile.h:5
void Solve(Body &b, std::vector< Contact > &contacts, const Material &material, double dt)
Definition RigidProp.h:159
Vec Support(const Hull &h, const Pose &p, Vec d)
Definition RigidProp.h:63
bool Near(const Body &b, const Triangle &t, double extra)
Definition RigidProp.h:141
double Length(Vec a)
Definition RigidProp.h:24
Distance Query(const Hull &h, const Pose &p, const Triangle &t)
Definition RigidProp.h:116
double Dot(Vec a, Vec b)
Definition RigidProp.h:22
Vec Acceleration(const Body &b, const Motion &m)
Definition RigidProp.h:198
constexpr float Pi
Definition ClientMath.h:12
Matrix * MatrixRotationX(Matrix *out, float value)
Definition ClientMath.h:126
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
constexpr float HalfPi
Definition ClientMath.h:12
constexpr double KmPerUnit
std::vector< RigidProp::Triangle > Footwell()
RigidProp::Hull Can()
bool Matches(unsigned char type, bool c2a, Vec nominalKm, Vec ypr, unsigned primitives)
Definition SparkoProp.h:10
Vec FromPhysics(Vec v)
Definition SparkoProp.h:18
path
Definition erin.py:153
double rotationSpeedMps
Definition PropAudio.h:9
std::uint64_t frame
Definition PropAudio.h:10
std::vector< Vec > vertices
Definition RigidProp.h:44
static Quat Ypr(double yaw, double pitch, double roll)
Definition RigidProp.h:39