Rise
The Vieneo Province
Toggle main menu visibility
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
7
namespace
SparkoProp
{
8
using
RigidProp::Vec
;
9
constexpr
unsigned
char
InstanceType
=70;
// Makeship label: Ragdoll; rigid prop, not a skeleton.
10
inline
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).
18
inline
Vec
FromPhysics
(
Vec
v) {
return
{v.
x
,v.
z
,v.
y
};}
19
struct
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
};
27
class
Controller
{
28
bool
sampled
=
false
,
wasSuppressed
=
false
;
29
Sample
previous
{};
30
public
:
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"
;
37
RigidProp::Body
before
;
38
RigidProp::Pose
resetFrom
;
39
RigidProp::Pose
externalResetFrom
;
40
RigidProp::Motion
frameMotion
{};
41
double
relocationErrorKm
=0;
42
RigidProp::Simulation
simulation
;
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
) {
54
if
(!internal) {++
externalResets
;
externalResetReason
=reason;
externalResetFrom
=
simulation
.
body
.
pose
;}
55
++
resets
;
resetReason
=reason;
resetFrom
=
simulation
.
body
.
pose
;
sampled
=
false
;
simulation
.
Reset
();
56
}
57
void
Update
(
double
dt,
const
Sample
& input) {
58
++
frames
;
before
=
simulation
.
body
;
frameMotion
={};
relocationErrorKm
=0;
simulation
.
stats
={};
action
=
"step"
;
59
// Simulator/reset suppression has priority even during a paused frame.
60
if
(input.
suppressed
||
wasSuppressed
)
Reset
(input.
suppressed
?
"suppressed"
:
"suppression_exit"
,
true
);
61
wasSuppressed
=input.
suppressed
;
62
if
(input.
suppressed
) {
action
=
"suppressed"
;
return
;}
63
if
(!std::isfinite(dt)||dt<0||dt>.25||!
RigidProp::Finite
(input.
specificForceMss
)||
64
!
RigidProp::Finite
(input.
inverseOrientationRates
)||!
RigidProp::Finite
(input.
positionKm
)||
65
!
RigidProp::Finite
(input.
velocityKms
)||!
RigidProp::Finite
(input.
cameraViewMountKm
)||
66
!
RigidProp::Finite
(input.
barycentricKms
)) {
67
action
=std::isfinite(dt)&&dt>.25?
"hitch_hold"
:
"invalid_sample_hold"
;
68
simulation
.
DiscardMotion
(
action
);
sampled
=
false
;
return
;
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
;
75
relocationErrorKm
=
sampled
?
RigidProp::Length
(input.
positionKm
-
previous
.
positionKm
-positionVelocity*dt):0;
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.
81
Vec
omega=
FromPhysics
(input.
inverseOrientationRates
);
82
Vec
oldOmega=
FromPhysics
(
previous
.
inverseOrientationRates
);
83
frameMotion
={
FromPhysics
(-input.
specificForceMss
)/(
SparkoGeometry::KmPerUnit
*1000),
84
omega,(omega-oldOmega)/dt,-
FromPhysics
(input.
cameraViewMountKm
)/
SparkoGeometry::KmPerUnit
};
85
simulation
.
Update
(dt,
frameMotion
);
previous
=input;
86
}
87
};
88
}
PropAudio.h
SparkoGeometry.h
RigidProp::Simulation
Definition
RigidProp.h:204
RigidProp::Simulation::body
Body body
Definition
RigidProp.h:310
RigidProp::Simulation::material
Material material
Definition
RigidProp.h:311
RigidProp::Simulation::Update
void Update(double dt, const Motion &motion)
Definition
RigidProp.h:332
RigidProp::Simulation::stats
FrameStats stats
Definition
RigidProp.h:312
RigidProp::Simulation::DiscardMotion
void DiscardMotion(const char *reason="discard")
Definition
RigidProp.h:317
RigidProp::Simulation::Reset
void Reset()
Definition
RigidProp.h:325
SparkoProp::Controller::AudioInput
PropAudio::Input AudioInput(bool active) const
Definition
SparkoProp.h:45
SparkoProp::Controller::Reset
void Reset(const char *reason="explicit", bool internal=false)
Definition
SparkoProp.h:53
SparkoProp::Controller::sampled
bool sampled
Definition
SparkoProp.h:28
SparkoProp::Controller::resetReason
std::string resetReason
Definition
SparkoProp.h:34
SparkoProp::Controller::component
int component
Definition
SparkoProp.h:31
SparkoProp::Controller::relocationErrorKm
double relocationErrorKm
Definition
SparkoProp.h:41
SparkoProp::Controller::wasSuppressed
bool wasSuppressed
Definition
SparkoProp.h:28
SparkoProp::Controller::externalResetReason
std::string externalResetReason
Definition
SparkoProp.h:35
SparkoProp::Controller::resetFrom
RigidProp::Pose resetFrom
Definition
SparkoProp.h:38
SparkoProp::Controller::Controller
Controller(int index, Vec xyzKm, Vec ypr)
Definition
SparkoProp.h:43
SparkoProp::Controller::externalResetFrom
RigidProp::Pose externalResetFrom
Definition
SparkoProp.h:39
SparkoProp::Controller::before
RigidProp::Body before
Definition
SparkoProp.h:37
SparkoProp::Controller::Update
void Update(double dt, const Sample &input)
Definition
SparkoProp.h:57
SparkoProp::Controller::simulation
RigidProp::Simulation simulation
Definition
SparkoProp.h:42
SparkoProp::Controller::resets
unsigned long long resets
Definition
SparkoProp.h:32
SparkoProp::Controller::externalResets
unsigned long long externalResets
Definition
SparkoProp.h:33
SparkoProp::Controller::action
const char * action
Definition
SparkoProp.h:36
SparkoProp::Controller::previous
Sample previous
Definition
SparkoProp.h:29
SparkoProp::Controller::frameMotion
RigidProp::Motion frameMotion
Definition
SparkoProp.h:40
SparkoProp::Controller::frames
unsigned long long frames
Definition
SparkoProp.h:32
RigidProp::Length
double Length(Vec a)
Definition
RigidProp.h:24
RigidProp::Finite
bool Finite(Vec a)
Definition
RigidProp.h:26
SparkoGeometry
Definition
SparkoGeometry.h:7
SparkoGeometry::KmPerUnit
constexpr double KmPerUnit
Definition
SparkoGeometry.h:8
SparkoProp
Definition
SparkoProp.h:7
SparkoProp::Matches
bool Matches(unsigned char type, bool c2a, Vec nominalKm, Vec ypr, unsigned primitives)
Definition
SparkoProp.h:10
SparkoProp::FromPhysics
Vec FromPhysics(Vec v)
Definition
SparkoProp.h:18
SparkoProp::InstanceType
constexpr unsigned char InstanceType
Definition
SparkoProp.h:9
PropAudio::Input
Definition
PropAudio.h:7
RigidProp::Body
Definition
RigidProp.h:50
RigidProp::Body::pose
Pose pose
Definition
RigidProp.h:51
RigidProp::Material::bounceThreshold
double bounceThreshold
Definition
RigidProp.h:155
RigidProp::Motion
Definition
RigidProp.h:185
RigidProp::Pose
Definition
RigidProp.h:45
RigidProp::Quat::Ypr
static Quat Ypr(double yaw, double pitch, double roll)
Definition
RigidProp.h:39
RigidProp::Vec
Definition
RigidProp.h:12
RigidProp::Vec::y
double y
Definition
RigidProp.h:13
RigidProp::Vec::z
double z
Definition
RigidProp.h:13
RigidProp::Vec::x
double x
Definition
RigidProp.h:13
SparkoProp::Sample
Definition
SparkoProp.h:19
SparkoProp::Sample::positionKm
Vec positionKm
Definition
SparkoProp.h:22
SparkoProp::Sample::inverseOrientationRates
Vec inverseOrientationRates
Definition
SparkoProp.h:21
SparkoProp::Sample::cameraViewMountKm
Vec cameraViewMountKm
Definition
SparkoProp.h:24
SparkoProp::Sample::suppressed
bool suppressed
Definition
SparkoProp.h:23
SparkoProp::Sample::barycentricKms
Vec barycentricKms
Definition
SparkoProp.h:25
SparkoProp::Sample::velocityKms
Vec velocityKms
Definition
SparkoProp.h:22
SparkoProp::Sample::specificForceMss
Vec specificForceMss
Definition
SparkoProp.h:20
Viewscreen
SparkoProp.h
Generated on
for Rise by
1.18.0