Rise
The Vieneo Province
Loading...
Searching...
No Matches
SparkoProp.h
Go to the documentation of this file.
1#pragma once
2#include "SparkoGeometry.h"
3#include "../PropAudio.h"
4#include <cstring>
5#include <string>
6
7namespace SparkoProp {
9constexpr unsigned char InstanceType=70; // Makeship label: Ragdoll; rigid prop, not a skeleton.
10inline bool Matches(unsigned char type,bool c2a,Vec nominalKm,Vec ypr,unsigned primitives) {
11 return type==InstanceType && c2a && primitives==44 &&
12 RigidProp::Length(nominalKm/SparkoGeometry::KmPerUnit-Vec{130,123,-122})<.01 &&
13 RigidProp::Length(ypr-Vec{-1.570796,0,-1.308997})<.00001;
14}
15// cockpit.cpp applies Rx(pi/2)*Ry(pi) into VIEW (-x,-z,-y), then the
16// view-to-propulsion half-turn/reflection is -I (WindshieldRain11::ToPhysicsTransform).
17// Propulsion is +Y up/+Z forward: authored (x,y,z) <-> physics (x,z,y).
18inline Vec FromPhysics(Vec v) {return {v.x,v.z,v.y};}
19struct Sample {
20 Vec specificForceMss; // CG support/thrust/impact force; gravity already accounted for.
21 Vec inverseOrientationRates; // (pitch,yaw,roll) from propulsion's world-to-body quaternion.
22 Vec positionKm,velocityKms; // planet-fixed position, inertial velocity
23 bool suppressed=false; // simulator, reset/terrain settling, or inactive vehicle
24 Vec cameraViewMountKm; // fixed interior camera translation, never head motion
25 Vec barycentricKms; // planet rotation component, as used by Viewscreen::Movement
26};
28 bool sampled=false,wasSuppressed=false;
30public:
31 int component=-1;
32 unsigned long long frames=0,resets=0;
33 unsigned long long externalResets=0;
34 std::string resetReason="load";
35 std::string externalResetReason="none";
36 const char* action="load";
43 Controller(int index,Vec xyzKm,Vec ypr):component(index),simulation(SparkoGeometry::Can(),SparkoGeometry::Footwell(),
44 {xyzKm/SparkoGeometry::KmPerUnit,RigidProp::Quat::Ypr(ypr.x,ypr.y,ypr.z)}) {}
45 PropAudio::Input AudioInput(bool active) const {
46 const auto& body=simulation.body;const auto& stats=simulation.stats;
47 constexpr double metresPerUnit=SparkoGeometry::KmPerUnit*1000;
48 return {active && std::strcmp(action,"step")==0 && std::strcmp(stats.recovery,"none")==0,
49 stats.steps>0,stats.lastContacts>0,body.sleeping,stats.maxImpactSpeed>simulation.material.bounceThreshold,
50 RigidProp::Length(body.velocity)*metresPerUnit,
51 RigidProp::Length(body.omega)*std::sqrt(18.0)*metresPerUnit,frames};
52 }
53 void Reset(const char* reason="explicit",bool internal=false) {
56 }
57 void Update(double dt,const Sample& input) {
59 // Simulator/reset suppression has priority even during a paused frame.
60 if(input.suppressed || wasSuppressed) Reset(input.suppressed?"suppressed":"suppression_exit",true);
62 if(input.suppressed) {action="suppressed";return;}
63 if(!std::isfinite(dt)||dt<0||dt>.25||!RigidProp::Finite(input.specificForceMss)||
67 action=std::isfinite(dt)&&dt>.25?"hitch_hold":"invalid_sample_hold";
69 }
70 if(dt==0) {action="zero_dt";return;}
71 // Match Viewscreen::Movement: planet-fixed positions advance by inertial
72 // velocity minus the planet's rotation component. Using raw velocity
73 // falsely respawns a stationary cabin prop on ~30 ms frames on Vieneo.
74 const Vec positionVelocity=previous.velocityKms-previous.barycentricKms;
76 bool relocated=sampled && relocationErrorKm>.01;
77 if(relocated) Reset("position_discontinuity",true);
78 if(!sampled) {action=relocated?"relocated":"prime";previous=input;sampled=true;return;}
79 // Rates rotate world -> body; the authored/physics axis swap reflects
80 // handedness. The two sign reversals cancel for this axial vector.
84 omega,(omega-oldOmega)/dt,-FromPhysics(input.cameraViewMountKm)/SparkoGeometry::KmPerUnit};
86 }
87};
88}
void Update(double dt, const Motion &motion)
Definition RigidProp.h:332
void DiscardMotion(const char *reason="discard")
Definition RigidProp.h:317
PropAudio::Input AudioInput(bool active) const
Definition SparkoProp.h:45
void Reset(const char *reason="explicit", bool internal=false)
Definition SparkoProp.h:53
std::string resetReason
Definition SparkoProp.h:34
std::string externalResetReason
Definition SparkoProp.h:35
RigidProp::Pose resetFrom
Definition SparkoProp.h:38
Controller(int index, Vec xyzKm, Vec ypr)
Definition SparkoProp.h:43
RigidProp::Pose externalResetFrom
Definition SparkoProp.h:39
RigidProp::Body before
Definition SparkoProp.h:37
void Update(double dt, const Sample &input)
Definition SparkoProp.h:57
RigidProp::Simulation simulation
Definition SparkoProp.h:42
unsigned long long resets
Definition SparkoProp.h:32
unsigned long long externalResets
Definition SparkoProp.h:33
const char * action
Definition SparkoProp.h:36
RigidProp::Motion frameMotion
Definition SparkoProp.h:40
unsigned long long frames
Definition SparkoProp.h:32
double Length(Vec a)
Definition RigidProp.h:24
bool Finite(Vec a)
Definition RigidProp.h:26
constexpr double KmPerUnit
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
constexpr unsigned char InstanceType
Definition SparkoProp.h:9
static Quat Ypr(double yaw, double pitch, double roll)
Definition RigidProp.h:39