CTrackKeyFramerTCB< CKeyT, T > Class Template Reference

#include <track_tcb.h>

Inheritance diagram for CTrackKeyFramerTCB< CKeyT, T >:

CTCBTools< CKeyT, T, TMapTimeCKey >

Detailed Description

template<class CKeyT, class T>
class CTrackKeyFramerTCB< CKeyT, T >

ITrack implementation for TCB keyframer.

Author:
Cyril 'Hulud' Corvazier

Nevrax France

Date:
2001

Definition at line 202 of file track_tcb.h.

Public Member Functions

virtual const IAnimatedValue & getValue () const
 From ITrack.


Protected Types

typedef CKeyT::TValueType TKeyValueType

Protected Member Functions

From ITrackKeyFramer
virtual void compile ()
 compile (precalc).

virtual void evalKey (const CKeyT *previous, const CKeyT *next, TAnimationTime datePrevious, TAnimationTime dateNext, TAnimationTime date)
 evalKey (runtime).


Private Types

typedef TMapTimeCKey::iterator TMapTimeCKeyIterator

Private Member Functions

void compileTCBEase (TMapTimeCKey &mapKey, bool loopMode)
 compute TCB ease information.

void computeFirstKey (CKeyT &keyFirst, CKeyT &keyAfter)
void computeHermiteBasis (float d, float hb[4])
void computeLastKey (CKeyT &keyLast, CKeyT &keyBefore)
void computeTCBFactors (const CKeyT &key, float timeBefore, float time, float timeAfter, float rangeDelta, bool firstKey, bool endKey, bool isLoop, float &ksm, float &ksp, float &kdm, float &kdp)
void computeTCBKey (CKeyT &keyBefore, CKeyT &key, CKeyT &keyAfter, float timeBefore, float time, float timeAfter, float rangeDelta, bool firstKey, bool endKey, bool isLoop)
void computeTCBKeyLinear (CKeyT &key0, CKeyT &key1)
float ease (const CKeyT *key, float d)

Private Attributes

CAnimatedValueBlendable< T > _Value


Member Typedef Documentation

template<class CKeyT, class T>
typedef CKeyT::TValueType CTrackKeyFramerTCB< CKeyT, T >::TKeyValueType [protected]
 

Definition at line 215 of file track_tcb.h.

template<class CKeyT, class T, class TMapTimeCKey>
typedef TMapTimeCKey::iterator CTCBTools< CKeyT, T, TMapTimeCKey >::TMapTimeCKeyIterator [protected, inherited]
 

Definition at line 51 of file track_tcb.h.


Member Function Documentation

template<class CKeyT, class T>
virtual void CTrackKeyFramerTCB< CKeyT, T >::compile  )  [inline, protected, virtual]
 

compile (precalc).

Definition at line 253 of file track_tcb.h.

References CTCBTools< CKeyT, T, TMapTimeCKey >::compileTCBEase(), CTrackKeyFramerTCB< CKeyT, T >::computeFirstKey(), CTrackKeyFramerTCB< CKeyT, T >::computeLastKey(), CTrackKeyFramerTCB< CKeyT, T >::computeTCBKey(), CTrackKeyFramerTCB< CKeyT, T >::computeTCBKeyLinear(), and sint.

00254         {
00255                 ITrackKeyFramer<CKeyT>::compile();
00256 
00257                 // Ease Precompute.
00258                 compileTCBEase(_MapKey, getLoopMode());
00259 
00260 
00261                 // Tangents Precompute.
00262                 sint    nKeys= _MapKey.size();
00263                 if(nKeys<=1)
00264                         return;
00265 
00266                 typename std::map<TAnimationTime, CKeyT>::iterator      it= _MapKey.begin();                            // first key.
00267                 typename std::map<TAnimationTime, CKeyT>::iterator      itNext= it; itNext++;                           // second key.
00268                 typename std::map<TAnimationTime, CKeyT>::iterator      itPrev= _MapKey.end(); itPrev--;        // last key.
00269 
00270                 if(nKeys==2 && !getLoopMode())
00271                 {
00272                         computeTCBKeyLinear( it->second, itNext->second );
00273                 }
00274                 else
00275                 {
00276                         // rangeDelta is the length of effective Range - length of LastKey-FirstKey.
00277                         // NB: if RangeLock, rangeDelta==0.
00278                         float   rangeDelta;
00279                         // NB: _RangeDelta has just been compiled in ITrackKeyFramer<CKeyT>::compile().
00280                         rangeDelta= getCompiledRangeDelta();
00281 
00282                         // Compute all middle keys.
00283                         for(;it!=_MapKey.end();)
00284                         {
00285                                 // Do the first key and the last key only in LoopMode.
00286                                 // NB: we are the last if itNext==_MapKey.begin().
00287                                 if(getLoopMode() || (it!=_MapKey.begin() && itNext!=_MapKey.begin()) )
00288                                 {
00289                                         computeTCBKey(itPrev->second, it->second, itNext->second, 
00290                                                 itPrev->first, it->first, itNext->first, rangeDelta, 
00291                                                 it==_MapKey.begin(), itNext==_MapKey.begin(), getLoopMode());
00292                                 }
00293 
00294                                 // Next key!!
00295                                 itPrev= it;
00296                                 it++;
00297                                 itNext++;
00298                                 // loop.
00299                                 if(itNext==_MapKey.end())
00300                                         itNext= _MapKey.begin();
00301                         }
00302 
00303                         // In not loop mode, compute first and last key, AFTER middle keys computed.
00304                         if(!getLoopMode())
00305                         {
00306                                 typename std::map<TAnimationTime, CKeyT>::iterator      it0= _MapKey.begin();                           // first key.
00307                                 typename std::map<TAnimationTime, CKeyT>::iterator      it1= it0; it1++;                                        // second key.
00308                                 typename std::map<TAnimationTime, CKeyT>::iterator      itLast= _MapKey.end();itLast--;         // last key.
00309                                 typename std::map<TAnimationTime, CKeyT>::iterator      itLastPrev= itLast;itLastPrev--;        // prev of last key.
00310 
00311                                 computeFirstKey(it0->second, it1->second);
00312                                 computeLastKey(itLast->second, itLastPrev->second);
00313                         }
00314                 }
00315         }

template<class CKeyT, class T, class TMapTimeCKey>
void CTCBTools< CKeyT, T, TMapTimeCKey >::compileTCBEase TMapTimeCKey &  mapKey,
bool  loopMode
[inline, protected, inherited]
 

compute TCB ease information.

Definition at line 56 of file track_tcb.h.

Referenced by CTrackKeyFramerTCB< CKeyTCBQuat, NLMISC::CAngleAxis >::compile(), and CTrackKeyFramerTCB< CKeyT, T >::compile().

00057         {
00058                 TMapTimeCKeyIterator    it= mapKey.begin();
00059                 for(;it!=mapKey.end();it++)
00060                 {
00061                         TMapTimeCKeyIterator    next= it;
00062                         next++;
00063 
00064                         // loop mgt. must compute ease from last to first (usefull if _RangeLock is false).
00065                         if(next==mapKey.end() && loopMode && mapKey.size()>1)
00066                                 next= mapKey.begin();
00067 
00068                         // Ease Precompute.
00069                         //=================
00070                         CKeyT   &key= it->second;
00071                         if(next!=mapKey.end())
00072                         {
00073                                 float   e0= it->second.EaseFrom;
00074                                 float   e1= next->second.EaseTo;
00075                                 float   s =  e0 + e1;
00076                                 
00077                                 // "normalize".
00078                                 if (s > 1.0f)
00079                                 {
00080                                         e0 = e0/s;
00081                                         e1 = e1/s;
00082                                 }
00083 
00084                                 // precalc ease factors.
00085                                 key.Ease0= e0;
00086                                 key.Ease1= e1;
00087                                 key.EaseK= 1/(2.0f - e0 - e1);
00088                                 if(e0)
00089                                         key.EaseKOverEase0= key.EaseK / e0;
00090                                 if(e1)
00091                                         key.EaseKOverEase1= key.EaseK / e1;
00092                         }
00093                         else
00094                         {
00095                                 // force ease() to just return d (see ease()).
00096                                 key.EaseK = 0.5f;
00097                         }
00098 
00099                 }
00100         }

template<class CKeyT, class T>
void CTrackKeyFramerTCB< CKeyT, T >::computeFirstKey CKeyT &  keyFirst,
CKeyT &  keyAfter
[inline, private]
 

Definition at line 359 of file track_tcb.h.

Referenced by CTrackKeyFramerTCB< CKeyT, T >::compile().

00360         {
00361                 float tm;
00362                 tm = 0.5f * (1.0f - keyFirst.Tension);
00363                 keyFirst.TanFrom= tm * ((keyAfter.Value - keyFirst.Value) * 3.0f - keyAfter.TanTo);
00364         }

template<class CKeyT, class T, class TMapTimeCKey>
void CTCBTools< CKeyT, T, TMapTimeCKey >::computeHermiteBasis float  d,
float  hb[4]
[inline, protected, inherited]
 

Definition at line 121 of file track_tcb.h.

Referenced by CTrackKeyFramerTCB< CKeyT, T >::evalKey().

00122         {
00123                 float d2,d3,a;
00124                 
00125                 d2 = d*d;
00126                 d3 = d2*d;
00127                 a  = 3.0f*d2 - 2.0f*d3;
00128                 hb[0] = 1.0f - a;
00129                 hb[1] = a;
00130                 hb[2] = d3 - 2.0f*d2 + d;
00131                 hb[3] = d3 - d2;
00132         }

template<class CKeyT, class T>
void CTrackKeyFramerTCB< CKeyT, T >::computeLastKey CKeyT &  keyLast,
CKeyT &  keyBefore
[inline, private]
 

Definition at line 367 of file track_tcb.h.

Referenced by CTrackKeyFramerTCB< CKeyT, T >::compile().

00368         {
00369                 float tm;
00370                 tm = 0.5f * (1.0f - keyLast.Tension);
00371                 keyLast.TanTo= tm * ((keyLast.Value - keyBefore.Value) * 3.0f - keyBefore.TanFrom);
00372         }

template<class CKeyT, class T, class TMapTimeCKey>
void CTCBTools< CKeyT, T, TMapTimeCKey >::computeTCBFactors const CKeyT &  key,
float  timeBefore,
float  time,
float  timeAfter,
float  rangeDelta,
bool  firstKey,
bool  endKey,
bool  isLoop,
float &  ksm,
float &  ksp,
float &  kdm,
float &  kdp
[inline, protected, inherited]
 

Definition at line 136 of file track_tcb.h.

Referenced by CTrackKeyFramerTCB< CKeyTCBQuat, NLMISC::CAngleAxis >::computeTCBKey(), and CTrackKeyFramerTCB< CKeyT, T >::computeTCBKey().

00138         {
00139                 float fp,fn;
00140 
00141                 if(isLoop || (!firstKey && !endKey))
00142                 {
00143                         float   dtm;
00144                         // Compute Time deltas.
00145                         if (firstKey)
00146                         {
00147                                 dtm = 0.5f * (rangeDelta + timeAfter - time);
00148                                 fp = rangeDelta / dtm;
00149                                 fn = (timeAfter - time) / dtm;
00150                         }
00151                         else if (endKey)
00152                         {
00153                                 dtm = 0.5f * (rangeDelta + time - timeBefore);
00154                                 fp = rangeDelta / dtm;
00155                                 fn = (time - timeBefore) / dtm;
00156                         }
00157                         else
00158                         {
00159                                 dtm = 0.5f * (timeAfter - timeBefore);
00160                                 fp = (time - timeBefore) / dtm;
00161                                 fn = (timeAfter - time) / dtm;
00162                         }
00163                         float   c= (float)fabs( key.Continuity );
00164                         fp = fp + c - c * fp;
00165                         fn = fn + c - c * fn;
00166                 }
00167                 else
00168                 {
00169                         // firstkey and lastkey of not loop track.
00170                         fp = 1.0f;
00171                         fn = 1.0f;
00172                 }
00173 
00174                 // Compute tangents factors.
00175                 float   tm,cm,cp,bm,bp,tmcm,tmcp;
00176 
00177                 cm = 1.0f - key.Continuity;
00178                 tm = 0.5f * ( 1.0f - key.Tension );
00179                 cp = 2.0f - cm;
00180                 bm = 1.0f - key.Bias;
00181                 bp = 2.0f - bm;
00182                 tmcm = tm*cm;   tmcp = tm*cp;
00183 
00184                 // tgts factors.
00185                 ksm = tmcm*bp*fp;       ksp = tmcp*bm*fp;
00186                 kdm = tmcp*bp*fn;       kdp = tmcm*bm*fn;
00187 
00188         }

template<class CKeyT, class T>
void CTrackKeyFramerTCB< CKeyT, T >::computeTCBKey CKeyT &  keyBefore,
CKeyT &  key,
CKeyT &  keyAfter,
float  timeBefore,
float  time,
float  timeAfter,
float  rangeDelta,
bool  firstKey,
bool  endKey,
bool  isLoop
[inline, private]
 

Definition at line 326 of file track_tcb.h.

References CTCBTools< CKeyT, T, TMapTimeCKey >::computeTCBFactors().

Referenced by CTrackKeyFramerTCB< CKeyTCBQuat, NLMISC::CAngleAxis >::compile(), and CTrackKeyFramerTCB< CKeyT, T >::compile().

00328         {
00329                 float   ksm,ksp,kdm,kdp;
00330 
00331                 // compute tangents factors.
00332                 computeTCBFactors(key, timeBefore, time, timeAfter, rangeDelta, firstKey, endKey, isLoop, ksm,ksp,kdm,kdp);
00333 
00334                 // Delta.
00335                 TKeyValueType   delm, delp;
00336                 delm = key.Value - keyBefore.Value;
00337                 delp = keyAfter.Value - key.Value;
00338 
00339                 // Tangents.
00340                 key.TanTo       = delm*ksm + delp*ksp;
00341                 key.TanFrom= delm*kdm + delp*kdp;
00342 
00343         }

template<class CKeyT, class T>
void CTrackKeyFramerTCB< CKeyT, T >::computeTCBKeyLinear CKeyT &  key0,
CKeyT &  key1
[inline, private]
 

Definition at line 346 of file track_tcb.h.

Referenced by CTrackKeyFramerTCB< CKeyT, T >::compile().

00347         {
00348                 float f0, f1;
00349                 TKeyValueType   dv;
00350                 
00351                 f0 = 1.0f - key0.Tension;
00352                 f1 = 1.0f - key1.Tension;
00353                 dv = key1.Value - key0.Value;
00354                 key0.TanFrom= dv * f0;
00355                 key1.TanTo= dv * f1;
00356         }

template<class CKeyT, class T, class TMapTimeCKey>
float CTCBTools< CKeyT, T, TMapTimeCKey >::ease const CKeyT *  key,
float  d
[inline, protected, inherited]
 

Definition at line 103 of file track_tcb.h.

Referenced by CTrackKeyFramerTCB< CKeyTCBQuat, NLMISC::CAngleAxis >::evalKey(), and CTrackKeyFramerTCB< CKeyT, T >::evalKey().

00104         {
00105                 if (d==0.0f || d==1.0f) return d;
00106                 // k==0.5f <=> e0+e1 == 0.
00107                 if (key->EaseK == 0.5f) return d;
00108 
00109                 if (d < key->Ease0)
00110                         return key->EaseKOverEase0 * d*d;
00111                 else if (d < 1.0f - key->Ease1)
00112                         return key->EaseK * (2.0f*d - key->Ease0);
00113                 else
00114                 {
00115                         d = 1.0f - d;
00116                         return 1.0f - key->EaseKOverEase1 * d*d;
00117                 }
00118         }

template<class CKeyT, class T>
virtual void CTrackKeyFramerTCB< CKeyT, T >::evalKey const CKeyT *  previous,
const CKeyT *  next,
TAnimationTime  datePrevious,
TAnimationTime  dateNext,
TAnimationTime  date
[inline, protected, virtual]
 

evalKey (runtime).

Definition at line 223 of file track_tcb.h.

References NLMISC::clamp(), CTCBTools< CKeyT, T, TMapTimeCKey >::computeHermiteBasis(), and CTCBTools< CKeyT, T, TMapTimeCKey >::ease().

00226         {
00227                 if(previous && next)
00228                 {
00229                         // lerp from previous to cur.
00230                         date-= datePrevious;
00231                         date*= previous->OODeltaTime;
00232                         NLMISC::clamp(date, 0,1);
00233                         
00234                         date = ease(previous, date);
00235 
00236                         float hb[4];
00237                         computeHermiteBasis(date, hb);
00238                         copyToValue(_Value.Value, 
00239                                 previous->Value*hb[0] + next->Value*hb[1] + 
00240                                 previous->TanFrom*hb[2] + next->TanTo*hb[3]);
00241                 }
00242                 else
00243                 {
00244                         if (previous)
00245                                 copyToValue(_Value.Value, previous->Value);
00246                         else
00247                                 if (next)
00248                                         copyToValue(_Value.Value, next->Value);
00249                 }
00250         }

template<class CKeyT, class T>
virtual const IAnimatedValue& CTrackKeyFramerTCB< CKeyT, T >::getValue  )  const [inline, virtual]
 

From ITrack.

Definition at line 207 of file track_tcb.h.

00208         {
00209                 return _Value;
00210         }


Field Documentation

template<class CKeyT, class T>
CAnimatedValueBlendable<T> CTrackKeyFramerTCB< CKeyT, T >::_Value [private]
 

Definition at line 322 of file track_tcb.h.


The documentation for this class was generated from the following file:
Generated on Tue Mar 16 06:43:54 2004 for NeL by doxygen 1.3.6