7 #ifndef CAFU_GAMESYS_INTERPOLATOR_HPP_INCLUDED
8 #define CAFU_GAMESYS_INTERPOLATOR_HPP_INCLUDED
10 #include "Math3D/Quaternion.hpp"
11 #include "Variables.hpp"
94 m_A = GetCurrentValue();
108 m_A = m_A + (m_Value.Get() - m_B);
119 m_Value.Set(GetCurrentValue());
132 T GetCurrentValue()
const
134 if (m_Total < 0.001f)
return m_B;
136 const float f = m_Time / m_Total;
138 return m_A * (1.0f - f) + m_B * f;
151 template<
class T>
inline bool VarInterpolatorT<T>::CanContinue(
const T& DeltaY)
const
156 template<>
inline bool VarInterpolatorT<Vector2fT>::CanContinue(
const Vector2fT& DeltaY)
const
158 return length(DeltaY) < 128;
161 template<>
inline bool VarInterpolatorT<Vector3fT>::CanContinue(
const Vector3fT& DeltaY)
const
163 return length(DeltaY) < 128;
166 template<>
inline bool VarInterpolatorT<Vector3dT>::CanContinue(
const Vector3dT& DeltaY)
const
168 return length(DeltaY) < 128;
185 assert(v.HasFlag(
"IsQuat"));
203 m_A = m_Total > 0.001f ? slerp(m_A, m_B, m_Time / m_Total) : m_B;
233 m_Value.Set(m_Total > 0.001f ? slerp(m_A, m_B, m_Time / m_Total).GetXYZ() : m_B.
GetXYZ());
238 m_Value.Set(m_B.
GetXYZ());
306 void ReInit()
override
308 m_LastValue = m_Value;
313 void UpdateTargetValue()
override
315 const T NewRef = m_Value;
316 m_Value = m_LastValue;
321 void AdvanceTime(
float Time)
override
323 m_Value += m_Gradient*Time;
326 m_LastValue = m_Value;
332 bool CanContinue(
const T& DeltaY)
const
334 return length(DeltaY) < 5000.0f;
338 void UpdateRef(
const T& Ref)
340 const T DeltaY = Ref - m_Value;
342 if (m_ExtTime < 0.0001f || !CanContinue(DeltaY))
350 m_Gradient = DeltaY/m_ExtTime;
375 class ExtrapolatorT :
public ApproxBaseT
389 void ReInit()
override
391 m_LastValue = m_Value;
398 void UpdateTargetValue()
override
400 const T NewRef = m_Value;
401 m_Value = m_LastValue;
407 void AdvanceTime(
float Time)
override
409 m_Value += m_Gradient*Time;
412 m_LastValue = m_Value;
418 bool CanContinue(
const T& DeltaY)
const
420 return length(DeltaY) < 5000.0f;
424 void UpdateRef(
const T& Ref)
433 const T DeltaY = Ref*2 - m_LastRef - m_Value;
435 if (m_ExtTime < 0.0001f || !CanContinue(DeltaY))
443 m_Gradient = DeltaY/m_ExtTime;
This is the base class for the visitors of VarTs.
Definition: Variables.hpp:266
void UpdateAfterReprediction() override
Updates the interpolator to account for the new target value after the local human player's repredict...
Definition: Interpolator.hpp:100
void UpdateTargetValue() override
Updates the interpolator to interpolate from the current interpolated value to the current value of t...
Definition: Interpolator.hpp:92
cf::TypeSys::VarBaseT * GetVar() const override
Returns the variable that this is an interpolator for.
Definition: Interpolator.hpp:79
virtual void SetTargetValue()=0
Assigns the interpolation's target value to the variable.
static QuaternionT FromXYZ(const Vector3T< float > &Vec)
Constructs a quaternion from the first three components (x, y, z) of a unit quaternion.
Definition: Quaternion.hpp:61
This is a "wrapper" around a normal C++ variable specifically of type ArrayT<T>.
Definition: SetCompVar.hpp:16
void SetTargetValue() override
Assigns the interpolation's target value to the variable.
Definition: Interpolator.hpp:122
This class is like VarInterpolatorT, but for Vector3fTs that represent quaternions.
Definition: Interpolator.hpp:174
This visitor is used to obtain an ApproxBaseT instance for a variable.
Definition: Interpolator.hpp:253
virtual void UpdateAfterReprediction()=0
Updates the interpolator to account for the new target value after the local human player's repredict...
This is a "wrapper" around a normal C++ variable.
Definition: SetCompVar.hpp:15
void SetCurrentValue() override
Assigns the interpolation's current value to the variable.
Definition: Interpolator.hpp:231
void SetTargetValue() override
Assigns the interpolation's target value to the variable.
Definition: Interpolator.hpp:236
This class represents a 2-dimensional vector.
Definition: Vector2.hpp:21
void UpdateAfterReprediction() override
Updates the interpolator to account for the new target value after the local human player's repredict...
Definition: Interpolator.hpp:209
void UpdateAfterPrediction() override
Updates the interpolator to account for the new target value after the local human player's predictio...
Definition: Interpolator.hpp:105
void SetCurrentValue() override
Assigns the interpolation's current value to the variable.
Definition: Interpolator.hpp:117
virtual void AdvanceTime(float Time)=0
Advances the interpolation over the given time.
cf::TypeSys::VarBaseT * GetVar() const override
Returns the variable that this is an interpolator for.
Definition: Interpolator.hpp:188
void UpdateAfterPrediction() override
Updates the interpolator to account for the new target value after the local human player's predictio...
Definition: Interpolator.hpp:214
void AdvanceTime(float Time) override
Advances the interpolation over the given time.
Definition: Interpolator.hpp:226
Vector3T< T > GetXYZ() const
Returns the x, y and z components as a Vector3T<T>.
Definition: Quaternion.hpp:81
virtual void UpdateAfterPrediction()=0
Updates the interpolator to account for the new target value after the local human player's predictio...
A common base class for "approximators" (interpolators and extrapolators), so that approximators of d...
Definition: Interpolator.hpp:24
void ReInit() override
Re-initializes this interpolator to the variable's current value.
Definition: Interpolator.hpp:193
virtual void UpdateTargetValue()=0
Updates the interpolator to interpolate from the current interpolated value to the current value of t...
void ReInit() override
Re-initializes this interpolator to the variable's current value.
Definition: Interpolator.hpp:84
This is the common base class for the VarT classes.
Definition: Variables.hpp:113
virtual void ReInit()=0
Re-initializes this interpolator to the variable's current value.
Linearly interpolates a value over a period of time.
Definition: Interpolator.hpp:66
void AdvanceTime(float Time) override
Advances the interpolation over the given time.
Definition: Interpolator.hpp:112
virtual void SetCurrentValue()=0
Assigns the interpolation's current value to the variable.
virtual cf::TypeSys::VarBaseT * GetVar() const =0
Returns the variable that this is an interpolator for.
const T & Get() const
Returns the value of this variable.
Definition: Variables.hpp:182
void UpdateTargetValue() override
Updates the interpolator to interpolate from the current interpolated value to the current value of t...
Definition: Interpolator.hpp:201