Gravity Engine 12.0
Unity Asset for Gravity
Loading...
Searching...
No Matches
GravityState Class Reference

Gravity state. Hold "most" of the information for gravitational evolution of the system. More...

Classes

struct  NbodyState
 

Public Types

enum  Evolvers { MASSIVE , FIXED , PARTICLES }
 physical time per evolver since start OR last timescale change
 

Public Member Functions

 GravityState (int size)
 New Gravity state. Also need to call SetAlgorithmAndForce to fully configure.
 
 GravityState (GravityState fromState)
 Clone constructor.
 
NbodyState[] GetNbodyStates ()
 
void SetAlgorithmAndForce (GravityEngine.Algorithm algorithm, IForceDelegate forceDelegate)
 Set the integrator required for the chosen algorithm.
 
void InitArrays (int arraySize)
 
bool GrowArrays (int growBy)
 
void Clear ()
 
void ResetPhysicalTime ()
 
void AddFixedBody (GravityEngine ge, int index, GravityEngine.FixedBody fixedBody, IFixedOrbit fixedOrbit)
 
void RemoveFixedBody (NBody nbody)
 
void UpdateKeplerDepth (NBody nbody, OrbitUniversal orbitU)
 Recompute and update the kepler depth of a fixed body.
 
void AddNBody (NBody nbody, float massScale, float physToWorldFactor, bool isFixed)
 
void RemoveNBody (NBody nbody)
 Remove the body at index and shuffle up the rest. Ensure the integrator does the same to stay in alignment.
 
void UpdateOnRails ()
 Check if all bodies are on rails.
 
void PreEvolve (GravityEngine ge)
 
bool IsOnRails ()
 Are all bodies in the world state "on-rails"?
 
bool Evolve (GravityEngine ge, double timeStep)
 Evolve the objects subject to gravity.
 
bool EvolveReversed (GravityEngine ge, double timeStep)
 
void MoveFixedBodies (double time)
 
void EvolveForTimestepReversed (GravityEngine ge, double physicsDt, bool exactTime=false)
 Evolve backwards.
 
Vector3 GetPhysicsPosition (NBody nbody)
 Get the internal position used by the physics engine.
 
Vector3d GetPhysicsPositionDoubleV3 (NBody nbody)
 
Vector3d GetPhysicsPositionDouble (NBody nbody)
 Get the internal position used by the physics engine.
 
void GetVelocityDouble (NBody nbody, ref double[] vel)
 Get the physics velocity for an NBody as a double[].
 
Vector3d GetVelocity3d (NBody nbody)
 
void UpdatePositionAndVelocity (NBody nbody, Vector3d pos, Vector3d vel, Maneuver m=null)
 
void SetVelocityDouble (NBody nbody, ref double[] velocity)
 Set the physics velocity from a double array.
 
void SetVelocity3d (NBody nbody, Vector3d velocity)
 
void UpdateInternalDouble (NBody nbody, Vector3d pos, Vector3d velocity)
 Internal use only from OrbitUniversal InitFromRVT Ensures cached state is current so can use info prior to the next Evolve call.
 
void SetPosition3d (NBody nbody, Vector3d pos)
 Set the physics velocity from a double array.
 
double GetMass (NBody nbody)
 Return the internal physics engine mass.
 
double GetPhysicsTime ()
 Get the internal physics time for massive bodies.
 
void SetTime (double newTime, bool force)
 
void EvolveToTime (double newTime)
 Evolve all bodies to the new time (past or future). This will trigger a integration sequence when there is at least one body off rails and this may cause a burst of CPU activity if the time delta is large.
 
void ApplyChangeAtTime (NBody nbody, double atTime, Vector3d r, Vector3d v)
 Apply a change in R,V to an NBody object in the past or future.
 
void ReverseVelocities ()
 
GERewindMgr GetGERewindMgr ()
 
bool NbodyIsActive (NBody nbody)
 
bool NbodyIndexIsActive (int index)
 
void NbodySetIsActive (NBody nbody, bool state)
 
void NbodySetNoUpdateFlag (NBody nbody, bool state)
 
bool NbodyGetNoUpdateFlag (NBody nbody)
 
bool NbodyGetNoUpdateFlag (int index)
 
bool NbodyIsFixed (NBody nbody)
 
void NbodySetIsFixed (NBody nbody, bool state)
 
void SetMass (NBody nbody, double mass)
 
void SetSize2 (NBody nbody, double size)
 
void AddTrigger (GETriggerMgr.Trigger t)
 
void RemoveTrigger (GETriggerMgr.Trigger t)
 
void ClearTriggers ()
 
string DumpAll (NBody[] gameNBodies, GravityEngine ge)
 
Vector3d ComputeCenterOfMass ()
 Deterimine the center of mass.
 
Vector3d ComputeCenterOfMassVelocity ()
 Compute the velocity of the CM. Consider only massive bodies. If there are any FixedObject elements they will be weighted with a velocity of zero.
 
void SetCenterOfMass (GravityEngine ge, Vector3d pos, Vector3d vel)
 Set the CM to the specified postion and velocity.
 
void MoveAll (Vector3d moveBy)
 

Public Attributes

int numBodies
 
List< GravityEngine.FixedBodyfixedBodies
 
int arraySize
 size of the arrays (may exceed the number of bodies due to pre-allocation)
 
double time
 time of current state (in the engine physics time)
 
bool hasTrajectories
 State has trajectories that require updating.
 
double[] physicalTime
 
bool isAsync
 Flag to indicate running async (on a non-main thread). If true, cannot do debug logging or access scene.
 
INBodyIntegrator integrator
 
List< GravityParticlesgravityParticles
 
ManeuverMgr maneuverMgr
 
bool isCopy
 

Static Public Attributes

const int NDIM = 3
 

Protected Attributes

NbodyState[] nbodyStates
 

Detailed Description

Gravity state. Hold "most" of the information for gravitational evolution of the system.

The NBody objects added can be massive or massless. They can independently be in normal gravitational motion or have their motion FIXED in some way (either by a Kepler/on-rail evolution mode or simply being not movable).

Massive bodies are tracked here by the arrays m[] and r[]. These arrays are then updated by passing to the selected numerical integrator. This allows a central object manager to compute the mutual gravitational interactions in the most effecient way. Each fixed frame the r[] value are copied back to the transform positions of the associated game objects (this is done in the GE class).

A parallel list of FixedBodies is maintained BUT they are also in the r[] list, since their masses may affect non-fixed bodies.

Massless bodies are evolved seperately using a simple Leapfrog integrator (unless Optimize Massless has been set to false).

Particles are always evolved seperately using a simpe Leapfrog integrator.

A scene may have more than one gravity state. Additional copies may be used for trajectory prediction, to determine future paths objects will take.

Constructor & Destructor Documentation

◆ GravityState() [1/2]

GravityState.GravityState ( int  size)

New Gravity state. Also need to call SetAlgorithmAndForce to fully configure.

Parameters
size

◆ GravityState() [2/2]

GravityState.GravityState ( GravityState  fromState)

Clone constructor.

Creates a deep copy suitable for independent evolution as a trajectory or for maneuver iterations. Maneuvers will be executed but the callback to motify the owner of the maneuver will be skipped (only the real evolution will notify).

Parameters
fromState

Member Function Documentation

◆ ApplyChangeAtTime()

void GravityState.ApplyChangeAtTime ( NBody  nbody,
double  atTime,
Vector3d  r,
Vector3d  v 
)

Apply a change in R,V to an NBody object in the past or future.

The intended use is to allow an update that has experienced network delay to be applied at an earlier point in the simulation to facilitate a distributed lockstep mode for multiplayer games.

Parameters
rewindTime
r
v

◆ ComputeCenterOfMass()

Vector3d GravityState.ComputeCenterOfMass ( )

Deterimine the center of mass.

Returns

◆ ComputeCenterOfMassVelocity()

Vector3d GravityState.ComputeCenterOfMassVelocity ( )

Compute the velocity of the CM. Consider only massive bodies. If there are any FixedObject elements they will be weighted with a velocity of zero.

Returns

◆ Evolve()

bool GravityState.Evolve ( GravityEngine  ge,
double  timeStep 
)

Evolve the objects subject to gravity.

Normal evolution is done by passing in worldState with a time interval corresponding to the frame advance time multiplied by the time zoom.

For trajectory updates in the case where the trajectory is up to date, this will be for the same interval but starting at a future time.

In order for trajectory computation to "catch up", there are times when the interval may be longer (but limited by the re-compute factor to avoid a huge recomputation on a single frame).

Maneuvers are ONLY added to the world state, so code in the trajectory state will not encounter maneuvers.

Parameters
geThe Gravity engine
timeStepThe amount of physics DT to be evolved

◆ EvolveForTimestepReversed()

void GravityState.EvolveForTimestepReversed ( GravityEngine  ge,
double  physicsDt,
bool  exactTime = false 
)

Evolve backwards.

  • when there are fixed bodies, these are evolved based on absolute time, so cannot just fake it by reversing velocities and running forward
  • DO let the integrators just run forrward
  • do not evolve particles
  • do not run triggers
Parameters
ge
physicsDtAmount of time to be reversed (positive number!)

◆ EvolveToTime()

void GravityState.EvolveToTime ( double  newTime)

Evolve all bodies to the new time (past or future). This will trigger a integration sequence when there is at least one body off rails and this may cause a burst of CPU activity if the time delta is large.

Generally called through the GE wrapper for game logic.

Parameters
newTime

◆ GetMass()

double GravityState.GetMass ( NBody  nbody)

Return the internal physics engine mass.

Parameters
nbody
Returns

◆ GetPhysicsPosition()

Vector3 GravityState.GetPhysicsPosition ( NBody  nbody)

Get the internal position used by the physics engine.

Parameters
nbody
Returns

◆ GetPhysicsPositionDouble()

Vector3d GravityState.GetPhysicsPositionDouble ( NBody  nbody)

Get the internal position used by the physics engine.

Parameters
nbody
Returns

◆ GetPhysicsTime()

double GravityState.GetPhysicsTime ( )

Get the internal physics time for massive bodies.

Returns
physics time for massive body integrator

◆ GetVelocityDouble()

void GravityState.GetVelocityDouble ( NBody  nbody,
ref double[]  vel 
)

Get the physics velocity for an NBody as a double[].

Parameters
nbody
vel

◆ IsOnRails()

bool GravityState.IsOnRails ( )

Are all bodies in the world state "on-rails"?

Returns

◆ RemoveNBody()

void GravityState.RemoveNBody ( NBody  nbody)

Remove the body at index and shuffle up the rest. Ensure the integrator does the same to stay in alignment.

Parameters
index

◆ SetAlgorithmAndForce()

void GravityState.SetAlgorithmAndForce ( GravityEngine::Algorithm  algorithm,
IForceDelegate  forceDelegate 
)

Set the integrator required for the chosen algorithm.

Parameters
algorithm

◆ SetCenterOfMass()

void GravityState.SetCenterOfMass ( GravityEngine  ge,
Vector3d  pos,
Vector3d  vel 
)

Set the CM to the specified postion and velocity.

Parameters
pos
vel

◆ SetPosition3d()

void GravityState.SetPosition3d ( NBody  nbody,
Vector3d  pos 
)

Set the physics velocity from a double array.

Parameters
nbody
velocity

◆ SetTime()

void GravityState.SetTime ( double  newTime,
bool  force 
)
See also
GravityEngine::SetPhysicalTime for restrictions.
Parameters
newTime

◆ SetVelocityDouble()

void GravityState.SetVelocityDouble ( NBody  nbody,
ref double[]  velocity 
)

Set the physics velocity from a double array.

Parameters
nbody
velocity

◆ UpdateInternalDouble()

void GravityState.UpdateInternalDouble ( NBody  nbody,
Vector3d  pos,
Vector3d  velocity 
)

Internal use only from OrbitUniversal InitFromRVT Ensures cached state is current so can use info prior to the next Evolve call.

Parameters
nbody
pos
velocity

◆ UpdateKeplerDepth()

void GravityState.UpdateKeplerDepth ( NBody  nbody,
OrbitUniversal  orbitU 
)

Recompute and update the kepler depth of a fixed body.

Parameters
nbody

◆ UpdateOnRails()

void GravityState.UpdateOnRails ( )

Check if all bodies are on rails.

Called after a RemoveBody in GE. Need to move to a single state RemoveBody() but wait until do masslessEngine refactor into integrator.

internal use only.


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