29 #ifndef __MATH_INTERPOLATE_H__
30 #define __MATH_INTERPOLATE_H__
40 template<
class type >
52 bool IsDone(
float time )
const {
return ( time >= startTime + duration ); }
74 template<
class type >
76 currentTime = startTime = duration = 0;
77 memset( ¤tValue, 0,
sizeof( currentValue ) );
78 startValue = endValue = currentValue;
86 template<
class type >
88 this->startTime = startTime;
89 this->duration = duration;
90 this->startValue = startValue;
91 this->endValue = endValue;
92 this->currentTime = startTime - 1;
93 this->currentValue = startValue;
101 template<
class type >
105 deltaTime = time - startTime;
106 if ( time != currentTime ) {
108 if ( deltaTime <= 0 ) {
109 currentValue = startValue;
110 }
else if ( deltaTime >= duration ) {
111 currentValue = endValue;
113 currentValue = startValue + ( endValue - startValue ) * ( (
float) deltaTime / duration );
129 template<
class type >
141 bool IsDone(
float time )
const {
return ( time >= startTime + accelTime +
linearTime + decelTime ); }
169 template<
class type >
171 startTime = accelTime = linearTime = decelTime = 0;
172 memset( &startValue, 0,
sizeof( startValue ) );
173 endValue = startValue;
181 template<
class type >
185 this->startTime = startTime;
186 this->accelTime = accelTime;
187 this->decelTime = decelTime;
188 this->startValue = startValue;
189 this->endValue = endValue;
191 if ( duration <= 0.0
f ) {
195 if ( this->accelTime + this->decelTime > duration ) {
196 this->accelTime = this->accelTime * duration / ( this->accelTime + this->decelTime );
197 this->decelTime = duration - this->accelTime;
199 this->linearTime = duration - this->accelTime - this->decelTime;
200 speed = ( endValue - startValue ) * ( 1000.0
f / ( (
float) this->linearTime + ( this->accelTime + this->decelTime ) * 0.5
f ) );
202 if ( this->accelTime ) {
203 extrapolate.Init( startTime, this->accelTime, startValue, ( startValue - startValue ), speed,
EXTRAPOLATION_ACCELLINEAR );
204 }
else if ( this->linearTime ) {
205 extrapolate.Init( startTime, this->linearTime, startValue, ( startValue - startValue ), speed,
EXTRAPOLATION_LINEAR );
207 extrapolate.Init( startTime, this->decelTime, startValue, ( startValue - startValue ), speed,
EXTRAPOLATION_DECELLINEAR );
216 template<
class type >
218 extrapolate.Init( 0, 0, extrapolate.GetStartValue(), extrapolate.GetBaseSpeed(), extrapolate.GetSpeed(),
EXTRAPOLATION_NONE );
226 template<
class type >
230 deltaTime = time - startTime;
231 if ( deltaTime < accelTime ) {
233 extrapolate.Init( startTime, accelTime, startValue, extrapolate.GetBaseSpeed(), extrapolate.GetSpeed(),
EXTRAPOLATION_ACCELLINEAR );
235 }
else if ( deltaTime < accelTime + linearTime ) {
237 extrapolate.Init( startTime + accelTime, linearTime, startValue + extrapolate.GetSpeed() * ( accelTime * 0.001f * 0.5f ), extrapolate.GetBaseSpeed(), extrapolate.GetSpeed(),
EXTRAPOLATION_LINEAR );
241 extrapolate.Init( startTime + accelTime + linearTime, decelTime, endValue - ( extrapolate.GetSpeed() * ( decelTime * 0.001f * 0.5f ) ), extrapolate.GetBaseSpeed(), extrapolate.GetSpeed(),
EXTRAPOLATION_DECELLINEAR );
251 template<
class type >
254 return extrapolate.GetCurrentValue( time );
262 template<
class type >
265 return extrapolate.GetCurrentSpeed( time );
278 template<
class type >
290 bool IsDone(
float time )
const {
return ( time >= startTime + accelTime +
linearTime + decelTime ); }
318 template<
class type >
320 startTime = accelTime = linearTime = decelTime = 0;
321 memset( &startValue, 0,
sizeof( startValue ) );
322 endValue = startValue;
330 template<
class type >
334 this->startTime = startTime;
335 this->accelTime = accelTime;
336 this->decelTime = decelTime;
337 this->startValue = startValue;
338 this->endValue = endValue;
340 if ( duration <= 0.0
f ) {
344 if ( this->accelTime + this->decelTime > duration ) {
345 this->accelTime = this->accelTime * duration / ( this->accelTime + this->decelTime );
346 this->decelTime = duration - this->accelTime;
348 this->linearTime = duration - this->accelTime - this->decelTime;
349 speed = ( endValue - startValue ) * ( 1000.0
f / ( (
float) this->linearTime + ( this->accelTime + this->decelTime ) *
idMath::SQRT_1OVER2 ) );
351 if ( this->accelTime ) {
352 extrapolate.Init( startTime, this->accelTime, startValue, ( startValue - startValue ), speed,
EXTRAPOLATION_ACCELSINE );
353 }
else if ( this->linearTime ) {
354 extrapolate.Init( startTime, this->linearTime, startValue, ( startValue - startValue ), speed,
EXTRAPOLATION_LINEAR );
356 extrapolate.Init( startTime, this->decelTime, startValue, ( startValue - startValue ), speed,
EXTRAPOLATION_DECELSINE );
365 template<
class type >
367 extrapolate.Init( 0, 0, extrapolate.GetStartValue(), extrapolate.GetBaseSpeed(), extrapolate.GetSpeed(),
EXTRAPOLATION_NONE );
375 template<
class type >
379 deltaTime = time - startTime;
380 if ( deltaTime < accelTime ) {
382 extrapolate.Init( startTime, accelTime, startValue, extrapolate.GetBaseSpeed(), extrapolate.GetSpeed(),
EXTRAPOLATION_ACCELSINE );
384 }
else if ( deltaTime < accelTime + linearTime ) {
386 extrapolate.Init( startTime + accelTime, linearTime, startValue + extrapolate.GetSpeed() * ( accelTime * 0.001f *
idMath::SQRT_1OVER2 ), extrapolate.GetBaseSpeed(), extrapolate.GetSpeed(),
EXTRAPOLATION_LINEAR );
390 extrapolate.Init( startTime + accelTime + linearTime, decelTime, endValue - ( extrapolate.GetSpeed() * ( decelTime * 0.001f *
idMath::SQRT_1OVER2 ) ), extrapolate.GetBaseSpeed(), extrapolate.GetSpeed(),
EXTRAPOLATION_DECELSINE );
400 template<
class type >
403 return extrapolate.GetCurrentValue( time );
411 template<
class type >
414 return extrapolate.GetCurrentSpeed( time );
type GetCurrentValue(float time) const
const type & GetEndValue(void) const
float GetEndTime(void) const
idInterpolateAccelDecelLinear()
const type & GetStartValue(void) const
idExtrapolate< type > extrapolate
float GetDeceleration(void) const
GLuint GLuint GLsizei GLenum type
float GetDuration(void) const
float GetDuration(void) const
float GetAcceleration(void) const
const type & GetEndValue(void) const
const type & GetEndValue(void) const
void SetPhase(float time) const
const type & GetStartValue(void) const
void Init(const float startTime, const float accelTime, const float decelTime, const float duration, const type &startValue, const type &endValue)
float GetDeceleration(void) const
void SetStartTime(float time)
bool IsDone(float time) const
static const float SQRT_1OVER2
float GetStartTime(void) const
void SetStartValue(const type &startValue)
bool IsDone(float time) const
float GetStartTime(void) const
void SetStartTime(float time)
idInterpolateAccelDecelSine()
void SetEndValue(const type &endValue)
void SetStartValue(const type &startValue)
void Init(const float startTime, const float duration, const type &startValue, const type &endValue)
float GetAcceleration(void) const
type GetCurrentValue(float time) const
void SetEndValue(const type &endValue)
float GetEndTime(void) const
idExtrapolate< type > extrapolate
float GetDuration(void) const
const type & GetStartValue(void) const
float GetEndTime(void) const
void SetStartTime(float time)
void SetPhase(float time) const
float GetStartTime(void) const
void SetEndValue(const type &endValue)
type GetCurrentSpeed(float time) const
bool IsDone(float time) const
type GetCurrentSpeed(float time) const
void SetDuration(float duration)
type GetCurrentValue(float time) const
void Init(const float startTime, const float accelTime, const float decelTime, const float duration, const type &startValue, const type &endValue)
void SetStartValue(const type &startValue)