41 #ifndef INCLUDED_GLS_KEYFRAME_H
42 #define INCLUDED_GLS_KEYFRAME_H
53 #if defined(LINUX) && (__GNUC__ >= 4) && !defined(QNX)
54 # include <tr1/memory>
57 #include "disti_assert.h"
58 #include "gls_color.h"
61 #include "gls_quaternion.h"
65 #ifdef GLS_ANIMATION_USE_STD_SHARED_PTR
66 namespace stdortr1 = std;
68 namespace stdortr1 = std::tr1;
100 typedef unsigned int ID;
103 const float g_glsAnimationFloatTolerance = 1e-5f;
106 const double g_pi = 3.14159265358979323846;
116 inline unsigned char ToColorElement(
const double d )
118 const unsigned int trunc =
static_cast<unsigned int>( d + 0.5 );
120 return static_cast<unsigned char>( (std::min)( (std::max)( trunc, 0u ), 255u ) );
128 inline bool FloatGreaterThan(
const double lhs,
const double rhs,
const float tolerance = g_glsAnimationFloatTolerance )
130 return lhs > rhs && !Equal( lhs, rhs, tolerance );
137 inline bool FloatLessThan(
const double lhs,
const double rhs,
const float tolerance = g_glsAnimationFloatTolerance )
139 return lhs < rhs && !Equal( lhs, rhs, tolerance );
146 inline bool FloatGreaterThanOrEqualTo(
const double lhs,
const double rhs,
const float tolerance = g_glsAnimationFloatTolerance )
148 return lhs > rhs || Equal( lhs, rhs, tolerance );
155 inline bool FloatLessThanOrEqualTo(
const double lhs,
const double rhs,
const float tolerance = g_glsAnimationFloatTolerance )
157 return lhs < rhs || Equal( lhs, rhs, tolerance );
166 typedef stdortr1::shared_ptr< GlsKeyframeInterpolator>
Ptr;
167 typedef stdortr1::shared_ptr<const GlsKeyframeInterpolator>
PtrConst;
184 const Key& lowerKey,
const Key& upperKey,
185 const Value& lowerValue,
const Value& upperValue )
const = 0;
191 template<
class Value>
201 const Key& lowerKey,
const Key& upperKey,
202 const Value& lowerValue,
const Value& upperValue )
const
204 const Float percent =
static_cast<Float
>( (key - lowerKey) / (upperKey - lowerKey) );
205 const Value interpVal = (upperValue - lowerValue) * percent + lowerValue;
217 : _interpolator( CreateDefaultInterpolator() )
223 : _interpolator( interpolator ? interpolator : CreateDefaultInterpolator() )
236 const Key& lowerKey,
const Key& upperKey,
237 const glsColor& lowerValue,
const glsColor& upperValue )
const
240 struct {
double r, g, b, a; } lower, upper, interpVal;
241 lowerValue.GetRGBA4d( lower.r, lower.g, lower.b, lower.a );
242 upperValue.GetRGBA4d( upper.r, upper.g, upper.b, upper.a );
245 interpVal.r = (*_interpolator)( key, lowerKey, upperKey, lower.r, upper.r );
246 interpVal.g = (*_interpolator)( key, lowerKey, upperKey, lower.g, upper.g );
247 interpVal.b = (*_interpolator)( key, lowerKey, upperKey, lower.b, upper.b );
248 interpVal.a = (*_interpolator)( key, lowerKey, upperKey, lower.a, upper.a );
252 Detail::ToColorElement( interpVal.r * 255 ),
253 Detail::ToColorElement( interpVal.g * 255 ),
254 Detail::ToColorElement( interpVal.b * 255 ),
255 Detail::ToColorElement( interpVal.a * 255 ) );
269 template<
class Value>
278 const Key& ,
const Key& upperKey,
279 const Value& lowerValue,
const Value& upperValue )
const
282 if( Equal( key, upperKey, Detail::g_glsAnimationFloatTolerance ) )
313 const Key& lowerKey,
const Key& upperKey,
314 const Value& lowerValue,
const Value& upperValue )
const
316 const float interpPercent =
static_cast<float>( (key - lowerKey) / (upperKey - lowerKey) );
318 interpVal.SetFromSlerp( interpPercent, lowerValue, upperValue );
339 for( Size n = 0; n < s_cacheSize; ++n )
341 _cache[n].second = GlsQuaternionD( _cache[n].first );
350 const Key& lowerKey,
const Key& upperKey,
351 const Value& lowerValue,
const Value& upperValue )
const
353 const LowerUpperQuaternions quaternions = GetQuaternionsFromCache( lowerValue, upperValue );
354 const float interpPercent =
static_cast<float>( (key - lowerKey) / (upperKey - lowerKey) );
355 GlsQuaternionD interpVal;
356 interpVal.SetFromSlerp( interpPercent, quaternions.first, quaternions.second );
357 return interpVal.GetEulerAngles() * float(RAD_TO_DEG);
360 #if GLS_DEBUG // For testing
361 static Size GetCacheSize() {
return s_cacheSize; }
363 const std::pair<Vector, GlsQuaternionD>* GetCache()
const {
return _cache; }
369 typedef std::pair<GlsQuaternionD, GlsQuaternionD> LowerUpperQuaternions;
373 std::pair<GlsQuaternionD, GlsQuaternionD> GetQuaternionsFromCache(
const Value& lowerValue,
const Value& upperValue )
const
375 GlsQuaternionD lowerQuat;
376 GlsQuaternionD upperQuat;
379 Size lowerNdx = s_cacheSize;
380 Size upperNdx = s_cacheSize;
383 for( Size n = 0; n < s_cacheSize && (lowerNdx == s_cacheSize || upperNdx == s_cacheSize); ++n )
385 if( lowerNdx == s_cacheSize && lowerValue.CloseTo( _cache[n].first ) )
387 lowerQuat = _cache[n].second;
390 else if( upperNdx == s_cacheSize && upperValue.CloseTo( _cache[n].first ) )
392 upperQuat = _cache[n].second;
398 if( lowerNdx == s_cacheSize )
400 const Vector anglesInRadians = lowerValue * float(DEG_TO_RAD);
401 lowerQuat.SetFromEulerAngles( anglesInRadians.x, anglesInRadians.y, anglesInRadians.z );
403 lowerNdx = SaveInCache( lowerValue, lowerQuat, lowerNdx, upperNdx );
406 if( upperNdx == s_cacheSize )
408 const Vector anglesInRadians = upperValue * float(DEG_TO_RAD);
409 upperQuat.SetFromEulerAngles( anglesInRadians.x, anglesInRadians.y, anglesInRadians.z );
410 SaveInCache( upperValue, upperQuat, lowerNdx, upperNdx );
413 return std::make_pair( lowerQuat, upperQuat );
417 Size SaveInCache(
const Value& value,
const GlsQuaternionD& quat,
const Size lowerNdx,
const Size upperNdx )
const
419 for( Size n = 0; n < s_cacheSize; ++n )
421 if( n == lowerNdx || n == upperNdx )
425 _cache[n] = std::make_pair( value, quat );
428 DistiAssert( !
"GlsAnimation: GlsSphericalLinearInterpolator<Vector> cache logic is broken." );
434 static const Size s_cacheSize = 2;
435 mutable std::pair< Vector, GlsQuaternionD > _cache[ s_cacheSize ];
442 template<
class Value>
452 const Key& lowerKey,
const Key& upperKey,
453 const Value& lowerValue,
const Value& upperValue)
const
455 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
456 const Value interpVal = (upperValue - lowerValue) * percent * percent + lowerValue;
464 template<
class Value>
474 const Key& lowerKey,
const Key& upperKey,
475 const Value& lowerValue,
const Value& upperValue)
const
477 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
478 const Value interpVal = (-(upperValue - lowerValue)) * percent * ( percent - 2 ) + lowerValue;
486 template<
class Value>
496 const Key& lowerKey,
const Key& upperKey,
497 const Value& lowerValue,
const Value& upperValue)
const
499 Float percent =
static_cast<Float
>((key - lowerKey) / ((upperKey - lowerKey) /2));
503 interpVal = ((upperValue - lowerValue)/2) * percent * percent + lowerValue;
508 interpVal = (-(upperValue - lowerValue) / 2) * (percent * (percent - 2) - 1) + lowerValue;
517 template<
class Value>
527 const Key& lowerKey,
const Key& upperKey,
528 const Value& lowerValue,
const Value& upperValue)
const
530 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
531 const Value interpVal = (upperValue - lowerValue) * percent * percent * percent + lowerValue;
539 template<
class Value>
549 const Key& lowerKey,
const Key& upperKey,
550 const Value& lowerValue,
const Value& upperValue)
const
552 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey)) - 1;
553 const Value interpVal = (upperValue - lowerValue) * (percent * percent * percent + 1) + lowerValue;
561 template<
class Value>
571 const Key& lowerKey,
const Key& upperKey,
572 const Value& lowerValue,
const Value& upperValue)
const
574 Float percent =
static_cast<Float
>((key - lowerKey) / ((upperKey - lowerKey) /2));
578 interpVal = ((upperValue - lowerValue) / 2) * percent * percent * percent + lowerValue;
583 interpVal = ((upperValue - lowerValue) / 2) * (percent * percent * percent + 2) + lowerValue;
592 template<
class Value>
602 const Key& lowerKey,
const Key& upperKey,
603 const Value& lowerValue,
const Value& upperValue)
const
605 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
606 const Value interpVal = (upperValue - lowerValue) * percent * percent * percent * percent + lowerValue;
614 template<
class Value>
624 const Key& lowerKey,
const Key& upperKey,
625 const Value& lowerValue,
const Value& upperValue)
const
627 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey)) - 1;
628 const Value interpVal = -(upperValue - lowerValue) * (percent * percent * percent * percent - 1) + lowerValue;
636 template<
class Value>
646 const Key& lowerKey,
const Key& upperKey,
647 const Value& lowerValue,
const Value& upperValue)
const
649 Float percent =
static_cast<Float
>((key - lowerKey) / ((upperKey - lowerKey) /2));
653 interpVal = ((upperValue - lowerValue) / 2) * percent * percent * percent * percent + lowerValue;
658 interpVal = -((upperValue - lowerValue) / 2) * (percent * percent * percent * percent - 2) + lowerValue;
667 template<
class Value>
677 const Key& lowerKey,
const Key& upperKey,
678 const Value& lowerValue,
const Value& upperValue)
const
680 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
681 const Value interpVal = (upperValue - lowerValue) * percent * percent * percent * percent * percent + lowerValue;
689 template<
class Value>
699 const Key& lowerKey,
const Key& upperKey,
700 const Value& lowerValue,
const Value& upperValue)
const
702 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey)) - 1;
703 const Value interpVal = (upperValue - lowerValue) * (percent * percent * percent * percent * percent + 1) + lowerValue;
711 template<
class Value>
721 const Key& lowerKey,
const Key& upperKey,
722 const Value& lowerValue,
const Value& upperValue)
const
724 Float percent =
static_cast<Float
>((key - lowerKey) / ((upperKey - lowerKey) /2));
728 interpVal = ((upperValue - lowerValue) / 2) * percent * percent * percent * percent * percent + lowerValue;
733 interpVal = ((upperValue - lowerValue) / 2) * (percent * percent * percent * percent * percent + 2) + lowerValue;
742 template<
class Value>
752 const Key& lowerKey,
const Key& upperKey,
753 const Value& lowerValue,
const Value& upperValue)
const
755 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
756 const Value interpVal = -(upperValue - lowerValue) * std::cos(percent * (
Float(Detail::g_pi) / 2)) + (upperValue - lowerValue) + lowerValue;
764 template<
class Value>
774 const Key& lowerKey,
const Key& upperKey,
775 const Value& lowerValue,
const Value& upperValue)
const
777 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
778 const Value interpVal = (upperValue - lowerValue) * std::sin(percent * (
Float(Detail::g_pi) / 2)) + lowerValue;
786 template<
class Value>
796 const Key& lowerKey,
const Key& upperKey,
797 const Value& lowerValue,
const Value& upperValue)
const
799 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
800 const Value interpVal = -((upperValue - lowerValue) / 2) * (std::cos(
Float(Detail::g_pi)*percent) - 1) + lowerValue;
808 template<
class Value>
818 const Key& lowerKey,
const Key& upperKey,
819 const Value& lowerValue,
const Value& upperValue)
const
821 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
822 const Value interpVal = (upperValue - lowerValue) * ( std::pow(
Float(2.0), 10 * ( percent - 1 ) ) ) + lowerValue;
830 template<
class Value>
840 const Key& lowerKey,
const Key& upperKey,
841 const Value& lowerValue,
const Value& upperValue)
const
843 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
844 const Value interpVal = (upperValue - lowerValue) * ( -std::pow(
Float(2.0), -10 * percent ) + 1 ) + lowerValue;
852 template<
class Value>
862 const Key& lowerKey,
const Key& upperKey,
863 const Value& lowerValue,
const Value& upperValue)
const
865 Float percent =
static_cast<Float
>((key - lowerKey) / ((upperKey - lowerKey) /2));
869 interpVal = ((upperValue - lowerValue) / 2) * std::pow(
Float(2.0), 10*(percent - 1) ) + lowerValue;
874 interpVal = ((upperValue - lowerValue) / 2) * (-std::pow(
Float(2.0), -10 * percent) + 2) + lowerValue;
883 template<
class Value>
893 const Key& lowerKey,
const Key& upperKey,
894 const Value& lowerValue,
const Value& upperValue)
const
896 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
897 const Value interpVal = -(upperValue - lowerValue) * (std::sqrt(1 - percent*percent) - 1) + lowerValue;
905 template<
class Value>
915 const Key& lowerKey,
const Key& upperKey,
916 const Value& lowerValue,
const Value& upperValue)
const
918 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey)) - 1;
919 const Value interpVal = (upperValue - lowerValue) * std::sqrt(1 - percent*percent) + lowerValue;
927 template<
class Value>
937 const Key& lowerKey,
const Key& upperKey,
938 const Value& lowerValue,
const Value& upperValue)
const
940 Float percent =
static_cast<Float
>((key - lowerKey) / ((upperKey - lowerKey) /2));
944 interpVal = -((upperValue - lowerValue) / 2) * (std::sqrt(1 - percent*percent) - 1) + lowerValue;
949 interpVal = ((upperValue - lowerValue) / 2) * (std::sqrt(1 - percent*percent) + 1) + lowerValue;
958 template<
class Value>
968 const Key& lowerKey,
const Key& upperKey,
969 const Value& lowerValue,
const Value& upperValue)
const
971 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey)) - 1;
972 const Value interpVal = (-((upperValue - lowerValue) * std::pow(
Float(2.0),10*percent) * std::sin( (percent-.075f)*(
Float(2.0) *
Float(Detail::g_pi))/0.3f)) + lowerValue );
980 template<
class Value>
990 const Key& lowerKey,
const Key& upperKey,
991 const Value& lowerValue,
const Value& upperValue)
const
993 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
994 const Value interpVal = ((upperValue - lowerValue) * std::pow(
Float(2.0),-10*(percent)) * std::sin( (percent-.075f)*(
Float(2.0) *
Float(Detail::g_pi))/0.3f) + upperValue );
1002 template<
class Value>
1012 const Key& lowerKey,
const Key& upperKey,
1013 const Value& lowerValue,
const Value& upperValue)
const
1015 const Float percent =
static_cast<Float
>((key - lowerKey) / ((upperKey - lowerKey) /2)) - 1;
1019 interpVal = ((upperValue - lowerValue) * std::pow(
Float(2.0), 10*percent) * std::sin( (percent-.1125f)*(
Float(2.0) *
Float(Detail::g_pi))/.45f )) * -0.5f + lowerValue;
1023 interpVal = (upperValue - lowerValue) * std::pow(
Float(2.0),-10*(percent)) * std::sin( (percent-.1125f)*(
Float(2.0) *
Float(Detail::g_pi))/.45f )*.5f + upperValue;
1032 template<
class Value>
1042 const Key& lowerKey,
const Key& upperKey,
1043 const Value& lowerValue,
const Value& upperValue)
const
1045 const Float percent =
static_cast<Float
>(((upperKey - lowerKey) - (key - lowerKey)) / (upperKey - lowerKey));
1047 if( percent < (1/2.75) )
1049 interpVal = (upperValue - lowerValue)*( 7.5625f*percent*percent) + lowerValue;
1051 else if( percent < (2/2.75) )
1053 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-1.500f/2.75f)*(percent-1.500f/2.75f) ) + .75f) + lowerValue) ;
1055 else if( (percent < (2.5/2.75)) )
1057 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-2.250f/2.75f)*(percent-2.250f/2.75f) ) + .9375f) + lowerValue);
1061 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-2.625f/2.75f)*(percent-2.625f/2.75f) ) + .984375f) + lowerValue);
1063 return (upperValue - lowerValue) - interpVal + lowerValue;
1070 template<
class Value>
1080 const Key& lowerKey,
const Key& upperKey,
1081 const Value& lowerValue,
const Value& upperValue)
const
1083 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
1085 if( percent < (1/2.75) )
1087 interpVal = (upperValue - lowerValue)*( 7.5625f*percent*percent) + lowerValue;
1089 else if( percent < (2/2.75) )
1091 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-1.500f/2.75f)*(percent-1.500f/2.75f) ) + .75f) + lowerValue) ;
1093 else if( (percent < (2.5/2.75)) )
1095 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-2.250f/2.75f)*(percent-2.250f/2.75f) ) + .9375f) + lowerValue);
1099 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-2.625f/2.75f)*(percent-2.625f/2.75f) ) + .984375f) + lowerValue);
1108 template<
class Value>
1118 const Key& lowerKey,
const Key& upperKey,
1119 const Value& lowerValue,
const Value& upperValue)
const
1121 if(((key - lowerKey) < (upperKey - lowerKey) * 0.5))
1123 const Float percent =
static_cast<Float
>(((upperKey - lowerKey) - (2 * (key - lowerKey))) / (upperKey - lowerKey));
1125 if( percent < (1/2.75) )
1127 interpVal = (upperValue - lowerValue)*( 7.5625f*percent*percent) + lowerValue;
1129 else if( percent < (2/2.75) )
1131 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-1.500f/2.75f)*(percent-1.500f/2.75f) ) + .75f) + lowerValue) ;
1133 else if( (percent < (2.5/2.75)) )
1135 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-2.250f/2.75f)*(percent-2.250f/2.75f) ) + .9375f) + lowerValue);
1139 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-2.625f/2.75f)*(percent-2.625f/2.75f) ) + .984375f) + lowerValue);
1141 return ((upperValue - lowerValue) - interpVal + lowerValue) * 0.5f + lowerValue;
1145 const Float percent =
static_cast<Float
>((2 * (key - lowerKey) -(upperKey - lowerKey))/ (upperKey - lowerKey));
1147 if( percent < (1/2.75) )
1149 interpVal = (upperValue - lowerValue)*( 7.5625f*percent*percent) + lowerValue;
1151 else if( percent < (2/2.75) )
1153 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-1.500f/2.75f)*(percent-1.500f/2.75f) ) + .75f) + lowerValue) ;
1155 else if( (percent < (2.5/2.75)) )
1157 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-2.250f/2.75f)*(percent-2.250f/2.75f) ) + .9375f) + lowerValue);
1161 interpVal = ( (upperValue - lowerValue)*( (7.5625f*(percent-2.625f/2.75f)*(percent-2.625f/2.75f) ) + .984375f) + lowerValue);
1163 return (interpVal) * 0.5f + (upperValue - lowerValue) * 0.5f + lowerValue;
1171 template<
class Value>
1181 const Key& lowerKey,
const Key& upperKey,
1182 const Value& lowerValue,
const Value& upperValue)
const
1184 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey));
1185 const Value interpVal = (upperValue - lowerValue) * percent * percent*((1.70158f+1)*percent - 1.70158f) + lowerValue;
1193 template<
class Value>
1203 const Key& lowerKey,
const Key& upperKey,
1204 const Value& lowerValue,
const Value& upperValue)
const
1206 const Float percent =
static_cast<Float
>((key - lowerKey) / (upperKey - lowerKey)) - 1;
1207 const Value interpVal = (upperValue - lowerValue) *(percent*percent*((1.70158f+1)*percent + 1.70158f) + 1) + lowerValue;
1215 template<
class Value>
1225 const Key& lowerKey,
const Key& upperKey,
1226 const Value& lowerValue,
const Value& upperValue)
const
1228 Float percent =
static_cast<Float
>((key - lowerKey) / ((upperKey - lowerKey) /2));
1232 interpVal = (upperValue - lowerValue) / 2 * (percent*percent*(3.5949095f*percent - 2.5949095f)) + lowerValue;
1237 interpVal = (upperValue - lowerValue) / 2 * (percent * percent *(3.5949095f*percent + 2.5949095f) + 2) + lowerValue;
1258 inline bool IsNaN(
const double d )
1260 #ifdef __FAST_MATH__
1262 return 0 == std::memcmp( reinterpret_cast<const void*>( &d ), reinterpret_cast<const void*>( &g_nan ),
sizeof(
double ) );
1275 typedef stdortr1::shared_ptr< GlsKeyframeCurve>
Ptr;
1276 typedef stdortr1::shared_ptr<const GlsKeyframeCurve>
PtrConst;
1285 : _interpolator( interpolator ? interpolator : new DefaultInterpolator() )
1286 , _lowerInterpNdx( 0 )
1293 : _interpolator( interpolator ? interpolator : typename
GlsKeyframeInterpolator<Value>::PtrConst(new DefaultInterpolator()) )
1294 , _lowerInterpNdx( 0 )
1300 return _keyframes.size();
1309 return std::make_pair( Detail::g_nan, Detail::g_nan );
1312 return std::make_pair( _keyframes.front().key, _keyframes.back().key );
1322 void AddKeyframe(
const Key& key,
const Value& value,
const Key& tolerance = Detail::g_glsAnimationFloatTolerance )
1324 DistiAssert( !Detail::IsNaN( key ) );
1327 DistiAssert( count != (std::numeric_limits<Size>::max)() );
1331 while( n < count && _keyframes[ n ].key < key )
1337 if( n < count && Equal( _keyframes[ n ].key, key, static_cast<float>( tolerance ) ) )
1340 _keyframes[ n ].value = value;
1345 _keyframes.insert( _keyframes.begin() + n, KeyValue( key, value ) );
1362 if( 0 == count || Detail::IsNaN( key ) )
1367 || Detail::FloatLessThanOrEqualTo( key, _keyframes[0].key ) )
1369 _lowerInterpNdx = 0;
1370 return _keyframes[ 0 ].value;
1372 else if( Detail::FloatGreaterThanOrEqualTo( key, _keyframes[ count - 1 ].key ) )
1374 _lowerInterpNdx = count - 2;
1375 return _keyframes[ count - 1 ].value;
1379 _lowerInterpNdx = ComputeInterpLowerNdx( key, count );
1382 const KeyValue lower = _keyframes[ _lowerInterpNdx ];
1383 const KeyValue upper = _keyframes[ _lowerInterpNdx + 1 ];
1384 const Value value = (*_interpolator)( key, lower.key, upper.key, lower.value, upper.value );
1388 #ifdef GLS_DEBUG // For testing
1389 Size GetLowerInterpNdx()
const {
return _lowerInterpNdx; }
1395 Size ComputeInterpLowerNdx(
const Key& key,
const Size& count )
const
1402 if( key >= _keyframes[ _lowerInterpNdx ].key
1403 && key <= _keyframes[ _lowerInterpNdx + 1 ].key )
1405 return _lowerInterpNdx;
1407 else if( key < _keyframes[ _lowerInterpNdx ].key )
1409 DistiAssert( _lowerInterpNdx != 0 );
1412 Size interpLowerNdx = _lowerInterpNdx - 1;
1413 while( interpLowerNdx != 0 && key < _keyframes[ interpLowerNdx ].key )
1417 return interpLowerNdx;
1421 DistiAssert( _lowerInterpNdx != (count - 2) );
1424 Size interpLowerNdx = _lowerInterpNdx + 1;
1425 while( interpLowerNdx < count - 2 && _keyframes[ interpLowerNdx + 1 ].key < key )
1429 return interpLowerNdx;
1440 KeyValue(
const Key& key_,
const Value& value_ )
1441 : key( key_ ), value( value_ )
1446 std::vector< KeyValue > _keyframes;
1448 mutable Size _lowerInterpNdx;
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:468
Definition: gls_keyframe.h:615
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:715
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:1219
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:1112
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:1223
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:1175
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:1007
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:1220
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:469
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:719
GlsKeyframeCurveBase::Size Size
Alias for easier reading.
Definition: gls_keyframe.h:334
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:596
Detail::FloatSelector< Value >::Type Float
Alias for easier reading.
Definition: gls_keyframe.h:170
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:641
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:694
stdortr1::shared_ptr< const GlsKeyframeCurve > PtrConst
Alias for easier reading.
Definition: gls_keyframe.h:1276
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:835
Definition: gls_keyframe.h:540
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:1037
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:988
GlsGatedInterpolator< std::string > Type
Definition: gls_keyframe.h:1250
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:1179
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:769
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:794
GlsKeyframeInterpolator< GlsQuaternionD >::Value Value
Alias for easier reading.
Definition: gls_keyframe.h:307
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:600
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:984
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:447
Definition: gls_keyframe.h:853
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:910
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:697
Definition: gls_keyframe.h:809
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:490
Class template for keyframe curves of different types (double, Vector, etc.)
Definition: gls_keyframe.h:1272
Definition: gls_keyframe.h:884
Definition: gls_keyframe.h:1003
A helper class for choosing the required floating-point type.
Definition: gls_keyframe.h:109
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:644
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:543
Definition: gls_keyframe.h:765
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:565
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:333
Definition: gls_keyframe.h:300
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:966
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:675
Definition: gls_keyframe.h:593
Definition: gls_keyframe.h:270
virtual ~GlsKeyframeInterpolator()
Destructor.
Definition: gls_keyframe.h:173
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:671
Definition: gls_keyframe.h:1172
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:547
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:812
Definition: gls_keyframe.h:1216
GlsColorInterpolationAdapter()
Constructor which creates a default interpolator.
Definition: gls_keyframe.h:216
stdortr1::shared_ptr< GlsKeyframeCurve > Ptr
Alias for easier reading.
Definition: gls_keyframe.h:1275
An abstract base class for all keyframe interpolators.
Definition: gls_keyframe.h:164
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:1197
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:746
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:273
T Value
The templated type.
Definition: gls_keyframe.h:1277
Definition: gls_keyframe.h:1248
Definition: gls_keyframe.h:443
Value operator()(const Key &key, const Key &, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:276
GlsKeyframeCurveBase::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:168
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:913
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:640
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:1116
Definition: gls_keyframe.h:1033
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:816
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:311
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:619
void AddKeyframe(const Key &key, const Value &value, const Key &tolerance=Detail::g_glsAnimationFloatTolerance)
Definition: gls_keyframe.h:1322
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:888
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:491
T Value
Alias for easier reading.
Definition: gls_keyframe.h:169
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:569
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:1040
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:1074
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:791
std::size_t Size
The size type for sizes and indices.
Definition: gls_keyframe.h:77
virtual Size GetKeyframeCount() const =0
Returns the number of keyframes.
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:985
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:522
Definition: gls_keyframe.h:465
Definition: gls_keyframe.h:928
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:525
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:891
Definition: gls_keyframe.h:637
virtual KeyPair GetMinMaxKeys() const =0
GlsColorInterpolationAdapter(GlsKeyframeInterpolator< double >::PtrConst interpolator)
Definition: gls_keyframe.h:229
Definition: gls_keyframe.h:712
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:963
Definition: gls_keyframe.h:743
Base class for the keyframe curve class template.
Definition: gls_keyframe.h:73
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:962
virtual Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const =0
stdortr1::shared_ptr< GlsKeyframeInterpolator > Ptr
Alias for easier reading.
Definition: gls_keyframe.h:166
Detail::DefaultInterpolator< Value >::Type DefaultInterpolator
The default interpolator for the given Value type.
Definition: gls_keyframe.h:1278
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:521
Definition: gls_keyframe.h:668
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:747
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:1201
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:931
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:195
Definition: gls_keyframe.h:959
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:622
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:750
GlsSphericalLinearInterpolator< GlsQuaternionD > Type
Definition: gls_keyframe.h:1249
GlsKeyframeInterpolator< Vector >::Value Value
Alias for easier reading.
Definition: gls_keyframe.h:332
Definition: gls_keyframe.h:787
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:856
stdortr1::shared_ptr< const GlsKeyframeInterpolator > PtrConst
Alias for easier reading.
Definition: gls_keyframe.h:167
Definition: gls_keyframe.h:1109
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:597
Definition: gls_keyframe.h:831
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:772
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:1006
Definition: gls_keyframe.h:1071
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:887
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:672
Definition: gls_keyframe.h:906
Definition: gls_keyframe.h:1194
GlsSphericalLinearInterpolator()
Constructor.
Definition: gls_keyframe.h:337
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:857
Definition: gls_keyframe.h:487
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:1113
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:716
Definition: gls_keyframe.h:213
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:618
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:860
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:1036
float Type
Definition: gls_keyframe.h:110
GlsKeyframeCurve(typename GlsKeyframeInterpolator< Value >::PtrConst interpolator)
Definition: gls_keyframe.h:1292
std::pair< Key, Key > KeyPair
Alias for easier reading.
Definition: gls_keyframe.h:78
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:813
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:935
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Definition: gls_keyframe.h:348
GlsLinearInterpolator< Value > Type
Definition: gls_keyframe.h:1248
Definition: gls_keyframe.h:690
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:1078
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:450
Value Interpolate(const Key &key) const
Definition: gls_keyframe.h:1358
GlsKeyframeCurveBase::Key Type
Definition: gls_keyframe.h:109
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:693
virtual ~GlsKeyframeCurveBase()
Destructor.
Definition: gls_keyframe.h:81
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:196
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:1075
Size GetKeyframeCount() const
Override from GlsKeyframeCurveBase.
Definition: gls_keyframe.h:1298
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:544
Definition: gls_keyframe.h:518
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:1198
GlsColorInterpolationAdapter(GlsKeyframeInterpolator< double > *const interpolator)
Definition: gls_keyframe.h:222
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:834
Definition: gls_keyframe.h:562
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:446
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:1176
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:566
KeyPair GetMinMaxKeys() const
Override from GlsKeyframeCurveBase.
Definition: gls_keyframe.h:1304
Definition: gls_animation.cpp:64
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:909
Implementation of GlsSphericalLinearInterpolator for quaternions.
Definition: gls_keyframe.h:304
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:199
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:494
Definition: gls_keyframe.h:981
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:472
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:768
glsColor operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const glsColor &lowerValue, const glsColor &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:234
Definition: gls_keyframe.h:192
double Key
The key type (usually time, but not always)
Definition: gls_keyframe.h:76
GlsColorInterpolationAdapter Type
Definition: gls_keyframe.h:1251
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:790
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:838
GlsKeyframeInterpolator< Value >::Float Float
Alias for easier reading.
Definition: gls_keyframe.h:932
GlsKeyframeInterpolator< Value >::Key Key
Alias for easier reading.
Definition: gls_keyframe.h:308
GlsKeyframeCurve(const GlsKeyframeInterpolator< Value > *const interpolator=new DefaultInterpolator())
Definition: gls_keyframe.h:1284
Value operator()(const Key &key, const Key &lowerKey, const Key &upperKey, const Value &lowerValue, const Value &upperValue) const
Overrides GlsKeyframeInterpolator.
Definition: gls_keyframe.h:1010