Nebula
Loading...
Searching...
No Matches
Math::Extrapolator< TYPE > Class Template Reference

#include <extrapolator.h>

Detailed Description

template<class TYPE>
class Math::Extrapolator< TYPE >

Extrapolator maintains state about updates for remote entities, and will generate smooth guesses about where those entities will be based on previously received data.

This implementation is based on http://www.mindcontrol.org/~hplus/epic/ Its adapted for use with nebula classes.

You create one Extrapolator per quantity you want to interpolate.

You then feed it updates about where your entity was ("positions") at some point in time. Optionally, you can also give the Extrapolator information about the velocity at that point in time. After that, you can ask the Extrapolator for position values for some given real time. Optionally, you can also ask for the velocity at the same time.

The Extrapolator will assume that an entity stops in place if it hasn't received updates for some time about the entity. It will also keep a running estimate of the latency and frequency of updates.

Extrapolator requires a globally synchronized clock. It does not do any management to deal with clock skew.

Public Member Functions

 Extrapolator ()
 constructor
 
 ~Extrapolator ()=default
 destructor
 
bool AddSample (Timing::Time packetTime, Timing::Time curTime, const TYPE &pos)
 add sample without velocity, velocity is compute from positions
 
bool AddSample (Timing::Time packetTime, Timing::Time curTime, const TYPE &pos, const TYPE &vel)
 add sample with given velocity
 
void Reset (Timing::Time packetTime, Timing::Time curTime, const TYPE &pos)
 Re-set the Extrapolator's idea of time, velocity and position.
 
void Reset (Timing::Time packetTime, Timing::Time curTime, const TYPE &pos, const TYPE &vel)
 Re-set the Extrapolator's idea of time, velocity and position.
 
bool ReadValue (Timing::Time forTime, TYPE &oPos) const
 Return an estimate of the interpolated position at a given global time (which typically will be greater than the curTime passed into AddSample()).
 
bool ReadValue (Timing::Time forTime, TYPE &oPos, TYPE &oVel) const
 Return an estimate of the interpolated position at a given global time (which typically will be greater than the curTime passed into AddSample()).
 
Timing::Time EstimateLatency () const
 
Timing::Time EstimateUpdateTime () const
 
bool Estimates (Timing::Time packetTime, Timing::Time curTime)
 is this packet newer than already received
 

Public Attributes

TYPE snapPos
 
TYPE snapVel
 
TYPE aimPos
 
TYPE lastPacketPos
 
Timing::Time snapTime
 
Timing::Time aimTime
 
Timing::Time lastPacketTime
 
Timing::Time latency
 
Timing::Time updateTime
 

Constructor & Destructor Documentation

◆ Extrapolator()

template<class TYPE>
Math::Extrapolator< TYPE >::Extrapolator ( )

constructor

◆ ~Extrapolator()

template<class TYPE>
Math::Extrapolator< TYPE >::~Extrapolator ( )
default

destructor

Member Function Documentation

◆ AddSample() [1/2]

template<class TYPE>
bool Math::Extrapolator< TYPE >::AddSample ( Timing::Time packetTime,
Timing::Time curTime,
const TYPE & pos )

add sample without velocity, velocity is compute from positions

When you receive data about a remote entity, call AddSample() to tell the Extrapolator about it.

The Extrapolator will throw away a sample with a time that's before any other time it's already gotten, and return false; else it will use the sample to improve its interpolation guess, and return true.

Parameters
packetTimeThe globally synchronized time at which the packet was sent (and thus the data valid).
curTimeThe globally synchronized time at which you put the data into the Extrapolator (i e, "now").
posThe position sample valid for packetTime.
Returns
true if packetTime is strictly greater than the previous packetTime, else false.

◆ AddSample() [2/2]

template<class TYPE>
bool Math::Extrapolator< TYPE >::AddSample ( Timing::Time packetTime,
Timing::Time curTime,
const TYPE & pos,
const TYPE & vel )

add sample with given velocity

When you receive data about a remote entity, call AddSample() to tell the Extrapolator about it.

The Extrapolator will throw away a sample with a time that's before any other time it's already gotten, and return false; else it will use the sample to improve its interpolation guess, and return true.

If you get velocity information with your position updates, you can make the guess that Extrapolator makes better, by passing that information along with your position sample.

Parameters
packetTimeThe globally synchronized time at which the packet was sent (and thus the data valid).
curTimeThe globally synchronized time at which you put the data into the Extrapolator (i e, "now").
posThe position sample valid for packetTime.
Returns
true if packetTime is strictly greater than the previous packetTime, else false.
Parameters
velThe velocity of the entity at the time of packetTime. Used to improve the guess about entity position.

◆ EstimateLatency()

template<class TYPE>
Timing::Time Math::Extrapolator< TYPE >::EstimateLatency ( ) const
Returns
the current estimation of latency between the sender and this interpolator.
the current estimation of latency between the sender and this interpolator. This is updated after each AddSample(), and re-set on Reset().

◆ Estimates()

template<class TYPE>
bool Math::Extrapolator< TYPE >::Estimates ( Timing::Time packetTime,
Timing::Time curTime )

is this packet newer than already received

◆ EstimateUpdateTime()

template<class TYPE>
Timing::Time Math::Extrapolator< TYPE >::EstimateUpdateTime ( ) const
Returns
the current estimation of frequency of updates that the sender will send.
the current estimation of frequency of updates that the sender will send. This is updated after each AddSample(), and re-set on Reset().

◆ ReadValue() [1/2]

template<class TYPE>
bool Math::Extrapolator< TYPE >::ReadValue ( Timing::Time forTime,
TYPE & oPos ) const

Return an estimate of the interpolated position at a given global time (which typically will be greater than the curTime passed into AddSample()).

Return an estimate of the interpolated value at a given global time (which typically will be greater than the curTime passed into AddSample()).

Parameters
forTimeThe time at which to interpolate the entity. It should be greater than the last packetTime, and less than the last curTime plus some allowable slop (determined by EstimateFreqency()).
oPosThe interpolated value for the given time.
Returns
false if forTime is out of range (at which point the oPos will still make sense, but movement will be clamped); true when forTime is within range.

◆ ReadValue() [2/2]

template<class TYPE>
bool Math::Extrapolator< TYPE >::ReadValue ( Timing::Time forTime,
TYPE & oPos,
TYPE & oVel ) const

Return an estimate of the interpolated position at a given global time (which typically will be greater than the curTime passed into AddSample()).

Return an estimate of the interpolated value at a given global time (which typically will be greater than the curTime passed into AddSample()).

Parameters
forTimeThe time at which to interpolate the entity. It should be greater than the last packetTime, and less than the last curTime plus some allowable slop (determined by EstimateFreqency()).
oPosThe interpolated position for the given time.
oVelThe interpolated velocity for the given time.
Returns
false if forTime is out of range (at which point the oPos will still make sense, but velocity will be zero); true when forTime is within range.

◆ Reset() [1/2]

template<class TYPE>
void Math::Extrapolator< TYPE >::Reset ( Timing::Time packetTime,
Timing::Time curTime,
const TYPE & pos )

Re-set the Extrapolator's idea of time, velocity and position.

Parameters
packetTimeThe packet time to reset to.
curTimeThe current time to reset to.
posThe position to reset to.
Note
The velocity will be re-set to 0.

◆ Reset() [2/2]

template<class TYPE>
void Math::Extrapolator< TYPE >::Reset ( Timing::Time packetTime,
Timing::Time curTime,
const TYPE & pos,
const TYPE & vel )

Re-set the Extrapolator's idea of time, velocity and position.

Parameters
packetTimeThe packet time to reset to.
curTimeThe current time to reset to.
posThe position to reset to.
velThe velocity to reset to.

Member Data Documentation

◆ aimPos

template<class TYPE>
TYPE Math::Extrapolator< TYPE >::aimPos

◆ aimTime

template<class TYPE>
Timing::Time Math::Extrapolator< TYPE >::aimTime

◆ lastPacketPos

template<class TYPE>
TYPE Math::Extrapolator< TYPE >::lastPacketPos

◆ lastPacketTime

template<class TYPE>
Timing::Time Math::Extrapolator< TYPE >::lastPacketTime

◆ latency

template<class TYPE>
Timing::Time Math::Extrapolator< TYPE >::latency

◆ snapPos

template<class TYPE>
TYPE Math::Extrapolator< TYPE >::snapPos

◆ snapTime

template<class TYPE>
Timing::Time Math::Extrapolator< TYPE >::snapTime

◆ snapVel

template<class TYPE>
TYPE Math::Extrapolator< TYPE >::snapVel

◆ updateTime

template<class TYPE>
Timing::Time Math::Extrapolator< TYPE >::updateTime

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