Kerbal Space Program  1.12.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | Properties | List of all members
VesselPrecalculate Class Reference

This is the counterpart to FlightIntegrator. As FI runs after most other FixedUpdate things run and finally applies all physics changes for the frame prior to passing off to the integrator, this runs at the start of the frame and precalculates the values for the fixed frame, like CoM, vessel velocity and angular velocity, the force of gravity (and any drift compensation), vessel acceleration/G forces, and the like. It also will set position and rotation when on rails, or if off rails recompute the orbit based on those stats calculated. It handles being off rails specially: it will do its final update for any given UT in Update() rather than FixedUpdate() so the calculated pos/vel/etc stats for the vessel are correct for visual display. When on rails, nothing changes in PhysX integration so there is no need to run later. Note that so long as this is running, it tells the vessel's OrbitDriver not to do anything, and instead directly calls OrbitDriver's Update methods. This is because when off rails, orbit updating needs to occur after we determine vessel CoM and velocity, whereas when on rails, we need to update from the orbit before we calculate CoM and velocity. More...

Inheritance diagram for VesselPrecalculate:

Public Member Functions

virtual void ApplyVelocityCorrection ()
 Applies the velocity correction from drift compensation (if any). More...
 
virtual void Awake ()
 
virtual void CalculateGravity ()
 Calculate the force of gravity, using drift compensation if in orbit and the compensation is better than not. Ease gravity coming off rails while landed/splashed. More...
 
virtual void CalculatePhysicsStats ()
 Will calculate center of mass and total mass, mass-weighted average linear and angular velocity, moment of inertia, and angular momentum Depends on FlightIntegrator setting part.physicsMass. If vessel is unloaded, use traditional calculations based off stored values and root part. More...
 
void FixedUpdate ()
 
virtual void GoOffRails ()
 Called by Vessel.GoOffRails More...
 
virtual void GoOnRails ()
 Called by Vessel.GoOnRails. Clears any post-integration velocity offset. More...
 
virtual void MainPhysics (bool doKillChecks)
 Does the main physics calls. Run from fixed update. Bits run in Update. More...
 
virtual void OnDestroy ()
 
virtual void RunFirst ()
 Run when a vessel initializes in flight More...
 
virtual void SetLandedPosRot ()
 This will update pos/rot if landed/splashed and on rails More...
 
virtual void Update ()
 Used for loaded/unpacked vessels so display matches physics. Runs most of what FixedUpdate does. However, it does so with zero time offset and does not calc gravity (that happens in next fixed frame). Finally, it signals to next fixed frame it doesn't have to rerun this stuff More...
 

Public Attributes

bool calculateGravity = true
 
Vector3d coriolis
 The fictitious forces for when in a rotating frame More...
 
double easingFrameIncrease = (1d / 16d)
 The proportional increase in g each tick. Default: 1/16th, so 16 frames of easing. More...
 
double fDeltaTime
 
Vector3d gAccel
 Acceleration passed to Vessel for calculating perturbation/g force More...
 
Vector3d gAccelTrue
 The true acceleration of gravity at this instant, minus any fictitious or drift-correcting force More...
 
Vector3d integrationAccel
 The acceleration passed to PhysX (when not correcting drift) More...
 
OrbitDriver.UpdateMode lastMode
 
bool packedInFixed = true
 Was the vessel packed in the last fixed frame? More...
 
bool physStatsNotDoneInUpdate = true
 If true, runs phys calcs in FixedUpdate, if false we already did them in Update (post-integration) and don't need to rerun. More...
 
Vector3d postIntegrationVelocityCorrection = Vector3d.zero
 The velocity changes to apply, pre and post integration (if correcting drift) More...
 
bool railsSetPosRot = true
 
bool ranFixedThisFrame = true
 The reverse: did we do them in Fixed this frame? More...
 
bool updateOrbit = true
 
bool wasCorrectingDrift = false
 Were we correcting drift? More...
 
Vector3d worldSurfacePos
 
QuaternionD worldSurfaceRot
 

Static Public Attributes

static bool allowDriftCompensation = true
 
static bool disableRunInUpdate = false
 
static bool driftAlwaysPassThreshChecks = false
 

Protected Member Functions

virtual void StartEasing ()
 
virtual void StopEasing ()
 

Protected Attributes

bool correctDriftThisFrame = false
 Tell Pre to correct velocity on the next frame (or in Update) More...
 
bool easing = false
 Are we easing? More...
 
bool easingLockOn = false
 Did we set a control lock? More...
 
int framesUntilCorrect = 0
 
double lastUT
 The last UT the Update() update ran in. For detecting pause. More...
 
Vector3d railsPosNext
 
Vessel vessel
 

Properties

virtual bool isEasingGravity [get, set]
 publicly accessible Easing property More...
 
Vessel Vessel [get]
 

Detailed Description

This is the counterpart to FlightIntegrator. As FI runs after most other FixedUpdate things run and finally applies all physics changes for the frame prior to passing off to the integrator, this runs at the start of the frame and precalculates the values for the fixed frame, like CoM, vessel velocity and angular velocity, the force of gravity (and any drift compensation), vessel acceleration/G forces, and the like. It also will set position and rotation when on rails, or if off rails recompute the orbit based on those stats calculated. It handles being off rails specially: it will do its final update for any given UT in Update() rather than FixedUpdate() so the calculated pos/vel/etc stats for the vessel are correct for visual display. When on rails, nothing changes in PhysX integration so there is no need to run later. Note that so long as this is running, it tells the vessel's OrbitDriver not to do anything, and instead directly calls OrbitDriver's Update methods. This is because when off rails, orbit updating needs to occur after we determine vessel CoM and velocity, whereas when on rails, we need to update from the orbit before we calculate CoM and velocity.

Member Function Documentation

virtual void VesselPrecalculate.ApplyVelocityCorrection ( )
inlinevirtual

Applies the velocity correction from drift compensation (if any).

virtual void VesselPrecalculate.Awake ( )
inlinevirtual
virtual void VesselPrecalculate.CalculateGravity ( )
inlinevirtual

Calculate the force of gravity, using drift compensation if in orbit and the compensation is better than not. Ease gravity coming off rails while landed/splashed.

< convert inertial to rotational reference frame

< Calculate gravitic acceleration as difference between current velocity and velocity after integration (i.e. at start of next fixed frame).

< for use in GotRotFrameVel

virtual void VesselPrecalculate.CalculatePhysicsStats ( )
inlinevirtual

Will calculate center of mass and total mass, mass-weighted average linear and angular velocity, moment of inertia, and angular momentum Depends on FlightIntegrator setting part.physicsMass. If vessel is unloaded, use traditional calculations based off stored values and root part.

< set by FI based on physicsless children

< add the part inertiaTensor to the ship inertiaTensor

< add the part mass to the ship inertiaTensor

< add the part distance offset to the ship inertiaTensor

< was just set before.

< was set at start of our run

void VesselPrecalculate.FixedUpdate ( )
inline
virtual void VesselPrecalculate.GoOffRails ( )
inlinevirtual

Called by Vessel.GoOffRails

virtual void VesselPrecalculate.GoOnRails ( )
inlinevirtual

Called by Vessel.GoOnRails. Clears any post-integration velocity offset.

virtual void VesselPrecalculate.MainPhysics ( bool  doKillChecks)
inlinevirtual

Does the main physics calls. Run from fixed update. Bits run in Update.

Parameters
doKillChecksDo we check if the vessel should be killed?

< if it's already queued, don't worry about it

< Handle orbit fixups and rails positioning and anything from the prior frame

< Clean up state from the prior frame

< assume we don't have to correct

< Calculate vessel COM and velocity for the current pos and rb velocities.

< Calculate the gravity that will be integrated (or just stored if on rails) this frame.

< Calculate the gravity that will be integrated (or just stored if on rails) this frame.

< Run Vessel's fixedupdate code that checks if we should die

< reset so if >1 fixed frame per update loop we don't skip the above!

virtual void VesselPrecalculate.OnDestroy ( )
inlinevirtual

< in case we set this and we die but orbitdriver doesn't.

virtual void VesselPrecalculate.RunFirst ( )
inlinevirtual

Run when a vessel initializes in flight

virtual void VesselPrecalculate.SetLandedPosRot ( )
inlinevirtual

This will update pos/rot if landed/splashed and on rails

< don't set pos here since we set pos right after.

virtual void VesselPrecalculate.StartEasing ( )
inlineprotectedvirtual
virtual void VesselPrecalculate.StopEasing ( )
inlineprotectedvirtual
virtual void VesselPrecalculate.Update ( )
inlinevirtual

Used for loaded/unpacked vessels so display matches physics. Runs most of what FixedUpdate does. However, it does so with zero time offset and does not calc gravity (that happens in next fixed frame). Finally, it signals to next fixed frame it doesn't have to rerun this stuff

Member Data Documentation

bool VesselPrecalculate.allowDriftCompensation = true
static
bool VesselPrecalculate.calculateGravity = true
Vector3d VesselPrecalculate.coriolis

The fictitious forces for when in a rotating frame

bool VesselPrecalculate.correctDriftThisFrame = false
protected

Tell Pre to correct velocity on the next frame (or in Update)

bool VesselPrecalculate.disableRunInUpdate = false
static
bool VesselPrecalculate.driftAlwaysPassThreshChecks = false
static
bool VesselPrecalculate.easing = false
protected

Are we easing?

double VesselPrecalculate.easingFrameIncrease = (1d / 16d)

The proportional increase in g each tick. Default: 1/16th, so 16 frames of easing.

bool VesselPrecalculate.easingLockOn = false
protected

Did we set a control lock?

double VesselPrecalculate.fDeltaTime
int VesselPrecalculate.framesUntilCorrect = 0
protected
Vector3d VesselPrecalculate.gAccel

Acceleration passed to Vessel for calculating perturbation/g force

Vector3d VesselPrecalculate.gAccelTrue

The true acceleration of gravity at this instant, minus any fictitious or drift-correcting force

Vector3d VesselPrecalculate.integrationAccel

The acceleration passed to PhysX (when not correcting drift)

OrbitDriver.UpdateMode VesselPrecalculate.lastMode
double VesselPrecalculate.lastUT
protected

The last UT the Update() update ran in. For detecting pause.

bool VesselPrecalculate.packedInFixed = true

Was the vessel packed in the last fixed frame?

bool VesselPrecalculate.physStatsNotDoneInUpdate = true

If true, runs phys calcs in FixedUpdate, if false we already did them in Update (post-integration) and don't need to rerun.

Vector3d VesselPrecalculate.postIntegrationVelocityCorrection = Vector3d.zero

The velocity changes to apply, pre and post integration (if correcting drift)

Vector3d VesselPrecalculate.railsPosNext
protected
bool VesselPrecalculate.railsSetPosRot = true
bool VesselPrecalculate.ranFixedThisFrame = true

The reverse: did we do them in Fixed this frame?

bool VesselPrecalculate.updateOrbit = true
Vessel VesselPrecalculate.vessel
protected
bool VesselPrecalculate.wasCorrectingDrift = false

Were we correcting drift?

Vector3d VesselPrecalculate.worldSurfacePos
QuaternionD VesselPrecalculate.worldSurfaceRot

Property Documentation

virtual bool VesselPrecalculate.isEasingGravity
getset

publicly accessible Easing property

Vessel VesselPrecalculate.Vessel
get

The documentation for this class was generated from the following file: