#include <track_sampled_quat.h>
Inheritance diagram for NL3D::CTrackSampledQuat:
9 bytes per key is achieved by encoding this way: 1 byte for the length/key time, measured in samples, and not in second (hence we can skip at max 255 keys). 8 byte for a light normalized quaternion: x,y,z,w are stored in 16 bits.
Nevrax France
Definition at line 59 of file track_sampled_quat.h.
Public Member Functions | |
void | build (const std::vector< uint16 > &timeList, const std::vector< CQuat > &keyList, float beginTime, float endTime) |
CTrackSampledQuat () | |
Constructor. | |
virtual std::string | getClassName ()=0 |
NLMISC_DECLARE_CLASS (CTrackSampledQuat) | |
void | setLoopMode (bool mode) |
Change the loop mode. true default. | |
virtual | ~CTrackSampledQuat () |
virtual void | eval (const TAnimationTime &date) |
virtual const IAnimatedValue & | getValue () const |
virtual void | serial (NLMISC::IStream &f) |
Protected Types | |
enum | TEvalType { EvalDiscard, EvalKey0, EvalInterpolate } |
Protected Member Functions | |
void | buildCommon (const std::vector< uint16 > &timeList, float beginTime, float endTime) |
TEvalType | evalTime (const TAnimationTime &date, uint numKeys, uint &keyId0, uint &keyId1, float &interpValue) |
void | serialCommon (NLMISC::IStream &f) |
Protected Attributes | |
float | _BeginTime |
float | _DeltaTime |
float | _EndTime |
NLMISC::CObjectVector< CQuatPack, false > | _Keys |
bool | _LoopMode |
float | _OODeltaTime |
float | _OOTotalRange |
NLMISC::CObjectVector< CTimeBlock > | _TimeBlocks |
float | _TotalRange |
CAnimatedValueQuat | _Value |
|
Definition at line 103 of file track_sampled_common.h.
00103 {EvalDiscard, EvalKey0, EvalInterpolate}; |
|
Constructor.
Definition at line 109 of file track_sampled_quat.cpp.
00110 { 00111 } |
|
Definition at line 114 of file track_sampled_quat.cpp.
00115 { 00116 } |
|
Build the track from a list of CKey. They must be already precompiled. ie they must all lies on the same hemisphere from prec key. nlassert if ! same length.
Definition at line 159 of file track_sampled_quat.cpp. References _Keys, NLMISC::CObjectVector< CTimeBlock >::clear(), NLMISC::CObjectVector< CQuatPack, false >::clear(), nlassert, NLMISC::CObjectVector< CQuatPack, false >::resize(), and uint. Referenced by NL3D::CAnimationOptimizer::optimizeTrack().
00161 { 00162 nlassert( endTime>beginTime || (beginTime==endTime && keyList.size()<=1) ); 00163 nlassert( keyList.size()==timeList.size() ); 00164 uint i; 00165 00166 // reset. 00167 uint numKeys= keyList.size(); 00168 _Keys.clear(); 00169 _TimeBlocks.clear(); 00170 00171 // Build Common time information 00172 CTrackSampledCommon::buildCommon(timeList, beginTime, endTime); 00173 00174 00175 // Compute All Key values. 00176 //=================== 00177 _Keys.resize(numKeys); 00178 for(i=0; i<numKeys;i++) 00179 { 00180 _Keys[i].pack(keyList[i]); 00181 } 00182 00183 } |
|
Build the track time from a list of Keys.
Definition at line 106 of file track_sampled_common.cpp. References NL3D::CTrackSampledCommon::_OODeltaTime, NL3D::CTrackSampledCommon::_TimeBlocks, NLMISC::CObjectVector< CTimeBlock >::clear(), NL3D::CTrackSampledCommon::CTimeBlock::KeyOffset, nlassert, NLMISC::CObjectVector< uint8, false >::resize(), NLMISC::CObjectVector< CTimeBlock >::resize(), sint32, NLMISC::CObjectVector< uint8, false >::size(), NL3D::CTrackSampledCommon::CTimeBlock::TimeOffset, NL3D::CTrackSampledCommon::CTimeBlock::Times, and uint.
00107 { 00108 nlassert( endTime>beginTime || (beginTime==endTime && timeList.size()<=1) ); 00109 uint i; 00110 00111 // reset. 00112 uint numKeys= timeList.size(); 00113 _TimeBlocks.clear(); 00114 00115 // Special case of 0 or 1 key. 00116 //=================== 00117 if(numKeys<=1) 00118 { 00119 _BeginTime= beginTime; 00120 _EndTime= endTime; 00121 _TotalRange= 0; 00122 _OOTotalRange= 0; 00123 _DeltaTime= 0; 00124 _OODeltaTime= 0; 00125 if(numKeys==1) 00126 { 00127 _TimeBlocks.resize(1); 00128 _TimeBlocks[0].TimeOffset= 0; 00129 _TimeBlocks[0].Times.resize(1); 00130 _TimeBlocks[0].Times[0]= 0; 00131 } 00132 00133 return; 00134 } 00135 00136 // Compute All Time blocks. 00137 //=================== 00138 sint32 lastBlockFrame= -1000000; 00139 nlassert(timeList[0] == 0); 00140 // Header info for creating timeBlocks 00141 vector<uint> timeBlockKeyId; 00142 vector<uint> timeBlockNumKeys; 00143 00144 // compute how many time block we need. 00145 for(i=0; i<numKeys; i++) 00146 { 00147 // verify growing order, and time difference. 00148 if(i>0) 00149 { 00150 nlassert(timeList[i]>timeList[i-1]); 00151 nlassert(timeList[i]-timeList[i-1] <= 255 ); 00152 } 00153 // If the current frame is to far from the last TimeBlock frame (or if 1st timeBlock), must create a new timeBlock 00154 if(timeList[i]-lastBlockFrame>255) 00155 { 00156 // create a new timeblock 00157 timeBlockKeyId.push_back(i); 00158 // Add this key to this new time Block (numKey == 1). 00159 timeBlockNumKeys.push_back(1); 00160 lastBlockFrame= timeList[i]; 00161 } 00162 else 00163 { 00164 // Add this key to the timeBlock. 00165 timeBlockNumKeys[timeBlockNumKeys.size()-1]++; 00166 } 00167 } 00168 00169 // Build the timeBlocks. 00170 _TimeBlocks.resize(timeBlockKeyId.size()); 00171 for(i=0; i<timeBlockKeyId.size(); i++) 00172 { 00173 CTimeBlock &timeBlock= _TimeBlocks[i]; 00174 uint firstKeyId= timeBlockKeyId[i]; 00175 uint numKeys= timeBlockNumKeys[i]; 00176 // compute the offset time and key 00177 timeBlock.KeyOffset= firstKeyId; 00178 timeBlock.TimeOffset= timeList[firstKeyId]; 00179 // create array of key 00180 timeBlock.Times.resize(numKeys); 00181 for(uint j=0;j<timeBlock.Times.size(); j++) 00182 { 00183 // get the key time and make it local to the timeBlock. 00184 timeBlock.Times[j]= timeList[firstKeyId+j] - timeBlock.TimeOffset; 00185 } 00186 } 00187 00188 // Compute other params 00189 //=================== 00190 _BeginTime= beginTime; 00191 _EndTime= endTime; 00192 // compute deltatime for a frame to an other 00193 uint totalFrameCount= timeList[numKeys-1] - timeList[0]; 00194 nlassert(totalFrameCount>0); 00195 _DeltaTime= (_EndTime-_BeginTime) / totalFrameCount; 00196 _OODeltaTime= (float)(1.0 / _DeltaTime); 00197 // Compute range of anim 00198 _TotalRange= _EndTime-_BeginTime; 00199 _OOTotalRange= float(1.0/_TotalRange); 00200 00201 } |
|
Evaluation of the value of the track for this time. The result is internaly stored to simplify access at the polymorphic values. To get the value, call ITrack::getValue(). Implements NL3D::ITrack. Definition at line 186 of file track_sampled_quat.cpp. References _Keys, NL3D::CTrackSampledCommon::evalTime(), nlstop, NLMISC::CObjectVector< CQuatPack, false >::size(), NL3D::TAnimationTime, uint, NL3D::CTrackSampledQuat::CQuatPack::unpack(), and NL3D::CAnimatedValueBlendable< T >::Value.
00187 { 00188 // Eval time, and get key interpolation info 00189 uint keyId0; 00190 uint keyId1; 00191 float interpValue; 00192 TEvalType evalType= evalTime(date, _Keys.size(), keyId0, keyId1, interpValue); 00193 00194 // Discard? 00195 if( evalType==EvalDiscard ) 00196 return; 00197 // One Key? easy, and quit. 00198 else if( evalType==EvalKey0 ) 00199 { 00200 _Keys[keyId0].unpack(_Value.Value); 00201 } 00202 // interpolate 00203 else if( evalType==EvalInterpolate ) 00204 { 00205 CQuatPack valueKey0= _Keys[keyId0]; 00206 CQuatPack valueKey1= _Keys[keyId1]; 00207 00208 // If the 2 keys have same value, just unpack. 00209 if(valueKey0 == valueKey1) 00210 { 00211 valueKey0.unpack(_Value.Value); 00212 } 00213 // else interpolate 00214 else 00215 { 00216 // unpack key value. 00217 CQuat quat0, quat1; 00218 valueKey0.unpack(quat0); 00219 valueKey1.unpack(quat1); 00220 00221 // interpolate 00222 _Value.Value= CQuat::slerp(quat0, quat1, interpValue); 00223 } 00224 } 00225 else 00226 { 00227 nlstop; 00228 } 00229 00230 } |
|
Definition at line 211 of file track_sampled_common.cpp. References NL3D::CTrackSampledCommon::_OODeltaTime, NL3D::CTrackSampledCommon::_TimeBlocks, NLMISC::clamp(), NL3D::CTrackSampledCommon::EvalDiscard, NL3D::CTrackSampledCommon::EvalInterpolate, NL3D::CTrackSampledCommon::EvalKey0, NLMISC::CObjectVector< uint8, false >::getPtr(), NLMISC::CObjectVector< CTimeBlock >::getPtr(), NL3D::CTrackSampledCommon::CTimeBlock::KeyOffset, nlassert, NLMISC::searchLowerBound(), sint, NLMISC::CObjectVector< uint8, false >::size(), NLMISC::CObjectVector< CTimeBlock >::size(), t, NL3D::TAnimationTime, NL3D::CTrackSampledCommon::CTimeBlock::TimeOffset, NL3D::CTrackSampledCommon::CTimeBlock::Times, uint, and uint8. Referenced by NL3D::CTrackSampledVector::eval(), and eval().
00212 { 00213 // Empty? quit 00214 if(numKeys==0) 00215 return EvalDiscard; 00216 00217 // One Key? easy, and quit. 00218 if(numKeys==1) 00219 { 00220 keyId0= 0; 00221 return EvalKey0; 00222 } 00223 00224 // manage Loop 00225 //===================== 00226 float localTime; 00227 if(_LoopMode) 00228 { 00229 nlassert(_TotalRange>0); 00230 // get relative to BeginTime. 00231 localTime= date-_BeginTime; 00232 00233 // force us to be in interval [0, _TotalRange[. 00234 if( localTime<0 || localTime>=_TotalRange ) 00235 { 00236 double d= localTime*_OOTotalRange; 00237 00238 // floor(d) is the truncated number of loops. 00239 d= localTime- floor(d)*_TotalRange; 00240 localTime= (float)d; 00241 00242 // For precision problems, ensure correct range. 00243 if(localTime<0 || localTime >= _TotalRange) 00244 localTime= 0; 00245 } 00246 00247 } 00248 else 00249 { 00250 // get relative to BeginTime. 00251 localTime= date-_BeginTime; 00252 } 00253 00254 00255 // Find the first key before localTime 00256 //===================== 00257 // get the frame in the track. 00258 sint frame= (sint)floor(localTime*_OODeltaTime); 00259 // clamp to uint16 00260 clamp(frame, 0, 65535); 00261 00262 // Search the TimeBlock. 00263 CTimeBlock keyTB; 00264 keyTB.TimeOffset= frame; 00265 uint tbId; 00266 tbId= searchLowerBound(_TimeBlocks.getPtr(), _TimeBlocks.size(), keyTB); 00267 00268 // get this timeBlock. 00269 CTimeBlock &timeBlock= _TimeBlocks[tbId]; 00270 // get frame relative to this timeBlock. 00271 sint frameRel= frame-timeBlock.TimeOffset; 00272 // clamp to uint8 00273 clamp(frameRel, 0, 255); 00274 // get the key in this timeBlock. 00275 uint keyIdRel; 00276 keyIdRel= searchLowerBound(timeBlock.Times.getPtr(), timeBlock.Times.size(), (uint8)frameRel); 00277 00278 // Get the Frame and Value of Key0. 00279 uint frameKey0= timeBlock.TimeOffset + timeBlock.Times[keyIdRel]; 00280 // this is the key to evaluate 00281 keyId0= timeBlock.KeyOffset + keyIdRel; 00282 00283 00284 // Interpolate with next key 00285 //===================== 00286 00287 // If not the last Key 00288 if(keyId0<numKeys-1) 00289 { 00290 // Get the next key. 00291 keyId1= keyId0+1; 00292 uint frameKey1; 00293 // If last key of the timeBlock, get the first time of the next timeBlock. 00294 if( keyIdRel+1 >= timeBlock.Times.size() ) 00295 { 00296 nlassert(tbId+1<_TimeBlocks.size()); 00297 frameKey1= _TimeBlocks[tbId+1].TimeOffset; 00298 } 00299 else 00300 { 00301 frameKey1= timeBlock.TimeOffset + timeBlock.Times[keyIdRel+1]; 00302 } 00303 00304 // unpack time. 00305 float time0= frameKey0*_DeltaTime; 00306 float time1= frameKey1*_DeltaTime; 00307 00308 // interpolate. 00309 float t= (localTime-time0); 00310 // If difference is one frame, optimize. 00311 if(frameKey1-frameKey0==1) 00312 t*= _OODeltaTime; 00313 else 00314 t/= (time1-time0); 00315 clamp(t, 0.f, 1.f); 00316 00317 // store this interp value. 00318 interpValue= t; 00319 00320 return EvalInterpolate; 00321 } 00322 // else (last key of anim), just eval this key. 00323 return EvalKey0; 00324 } |
|
Get the begin time of the track Implements NL3D::UTrack. Definition at line 67 of file track_sampled_common.cpp. References NL3D::TAnimationTime.
00068 { 00069 return _BeginTime; 00070 } |
|
Implemented in NLAIAGENT::CNumericIndex, NLAIC::IPointerGestion, NLAIC::CIdentType, and CAutomataDesc. Referenced by NLMISC::CClassRegistry::checkObject(), and NL3D::GetTextureSize(). |
|
Get the end time of the track Implements NL3D::UTrack. Definition at line 73 of file track_sampled_common.cpp. References NL3D::TAnimationTime.
00074 { 00075 return _EndTime; 00076 } |
|
get LoopMode. 2 mode only: "constant" (<=>false), and "loop" (<=> true). NB: same mode if time < getBeginTIme() and if time > getEndTime() Implements NL3D::ITrack. Definition at line 61 of file track_sampled_common.cpp.
00062 { 00063 return _LoopMode; 00064 } |
|
Get the track current value.
Implements NL3D::ITrack. Definition at line 119 of file track_sampled_quat.cpp.
00120 { 00121 return _Value; 00122 } |
|
Interplation a bool value. You should be sure that the track you use to interpolate your value is a bool track! An assertion will be raised in debug if the type is wrong.
Implements NL3D::UTrack. Definition at line 202 of file track.cpp. References NL3D::CAnimatedValueBool, NL3D::ITrack::eval(), NL3D::ITrack::getValue(), NL3D_HAUTO_UTRACK_INTERPOLATE, res, NL3D::TAnimationTime, and value.
00203 { 00204 NL3D_HAUTO_UTRACK_INTERPOLATE; 00205 00206 // Evaluate it 00207 eval (time); 00208 00209 // Get a pointer on the value 00210 const CAnimatedValueBool *value=dynamic_cast<const CAnimatedValueBool*>(&getValue ()); 00211 00212 // Type is good ? 00213 if (value) 00214 { 00215 // Ok, return the value 00216 res=value->Value; 00217 return true; 00218 } 00219 else 00220 // No, return false 00221 return false; 00222 } |
|
Interplation a string value. You should be sure that the track you use to interpolate your value is a string track! An assertion will be raised in debug if the type is wrong.
Implements NL3D::UTrack. Definition at line 178 of file track.cpp. References NL3D::CAnimatedValueString, NL3D::ITrack::eval(), NL3D::ITrack::getValue(), NL3D_HAUTO_UTRACK_INTERPOLATE, res, NL3D::TAnimationTime, and value.
00179 { 00180 NL3D_HAUTO_UTRACK_INTERPOLATE; 00181 00182 // Evaluate it 00183 eval (time); 00184 00185 // Get a pointer on the value 00186 const CAnimatedValueString *value=dynamic_cast<const CAnimatedValueString*>(&getValue ()); 00187 00188 // Type is good ? 00189 if (value) 00190 { 00191 // Ok, return the value 00192 res=value->Value; 00193 return true; 00194 } 00195 else 00196 // No, return false 00197 return false; 00198 } |
|
Interplation a CQuat value. You should be sure that the track you use to interpolate your value is a CQuat track! An assertion will be raised in debug if the type is wrong.
Implements NL3D::UTrack. Definition at line 154 of file track.cpp. References NL3D::CAnimatedValueQuat, NL3D::ITrack::eval(), NL3D::ITrack::getValue(), NL3D_HAUTO_UTRACK_INTERPOLATE, res, NL3D::TAnimationTime, and value.
00155 { 00156 NL3D_HAUTO_UTRACK_INTERPOLATE; 00157 00158 // Evaluate it 00159 eval (time); 00160 00161 // Get a pointer on the value 00162 const CAnimatedValueQuat *value=dynamic_cast<const CAnimatedValueQuat*>(&getValue ()); 00163 00164 // Type is good ? 00165 if (value) 00166 { 00167 // Ok, return the value 00168 res=value->Value; 00169 return true; 00170 } 00171 else 00172 // No, return false 00173 return false; 00174 } |
|
Interplation a CVector value. You should be sure that the track you use to interpolate your value is a CVector track! An assertion will be raised in debug if the type is wrong.
Implements NL3D::UTrack. Definition at line 130 of file track.cpp. References NL3D::CAnimatedValueVector, NL3D::ITrack::eval(), NL3D::ITrack::getValue(), NL3D_HAUTO_UTRACK_INTERPOLATE, res, NL3D::TAnimationTime, and value.
00131 { 00132 NL3D_HAUTO_UTRACK_INTERPOLATE; 00133 00134 // Evaluate it 00135 eval (time); 00136 00137 // Get a pointer on the value 00138 const CAnimatedValueVector *value=dynamic_cast<const CAnimatedValueVector*>(&getValue ()); 00139 00140 // Type is good ? 00141 if (value) 00142 { 00143 // Ok, return the value 00144 res=value->Value; 00145 return true; 00146 } 00147 else 00148 // No, return false 00149 return false; 00150 } |
|
Interplation a CRGBA value. You should be sure that the track you use to interpolate your value is an CRGBA track! An assertion will be raised in debug if the type is wrong.
Implements NL3D::UTrack. Definition at line 106 of file track.cpp. References NL3D::CAnimatedValueRGBA, NL3D::ITrack::eval(), NL3D::ITrack::getValue(), NL3D_HAUTO_UTRACK_INTERPOLATE, res, NL3D::TAnimationTime, and value.
00107 { 00108 NL3D_HAUTO_UTRACK_INTERPOLATE; 00109 00110 // Evaluate it 00111 eval (time); 00112 00113 // Get a pointer on the value 00114 const CAnimatedValueRGBA *value=dynamic_cast<const CAnimatedValueRGBA*>(&getValue ()); 00115 00116 // Type is good ? 00117 if (value) 00118 { 00119 // Ok, return the value 00120 res=value->Value; 00121 return true; 00122 } 00123 else 00124 // No, return false 00125 return false; 00126 } |
|
Interplation an integer value. You should be sure that the track you use to interpolate your value is an integer track! An assertion will be raised in debug if the type is wrong.
Implements NL3D::UTrack. Definition at line 82 of file track.cpp. References NL3D::CAnimatedValueInt, NL3D::ITrack::eval(), NL3D::ITrack::getValue(), NL3D_HAUTO_UTRACK_INTERPOLATE, res, sint32, NL3D::TAnimationTime, and value.
00083 { 00084 NL3D_HAUTO_UTRACK_INTERPOLATE; 00085 00086 // Evaluate it 00087 eval (time); 00088 00089 // Get a pointer on the value 00090 const CAnimatedValueInt *value=dynamic_cast<const CAnimatedValueInt*>(&getValue ()); 00091 00092 // Type is good ? 00093 if (value) 00094 { 00095 // Ok, return the value 00096 res=value->Value; 00097 return true; 00098 } 00099 else 00100 // No, return false 00101 return false; 00102 } |
|
Interplation a float value. You should be sure that the track you use to interpolate your value is a float track! An assertion will be raised in debug if the type is wrong.
Implements NL3D::UTrack. |
|
|
|
Implements NLMISC::IStreamable. Definition at line 125 of file track_sampled_quat.cpp. References _Keys, NLMISC::IStream::serial(), NLMISC::IStream::serialVersion(), and sint.
00126 { 00127 /* 00128 Version 1: 00129 - split class with base CTrackSampledCommon (must add a version in it). 00130 Version 0: 00131 - base version. 00132 */ 00133 sint ver= f.serialVersion(1); 00134 00135 if( ver<=0 ) 00136 { 00137 // serial Time infos, directly in CTrackSampledCommon 00138 f.serial(_LoopMode); 00139 f.serial(_BeginTime); 00140 f.serial(_EndTime) ; 00141 f.serial(_TotalRange); 00142 f.serial(_OOTotalRange); 00143 f.serial(_DeltaTime); 00144 f.serial(_OODeltaTime); 00145 f.serial(_TimeBlocks); 00146 } 00147 else 00148 { 00149 // serial Time infos. 00150 CTrackSampledCommon::serialCommon(f); 00151 } 00152 00153 // serial Keys. 00154 f.serial(_Keys); 00155 00156 } |
|
Definition at line 90 of file track_sampled_common.cpp. References NL3D::CTrackSampledCommon::_OODeltaTime, NL3D::CTrackSampledCommon::_TimeBlocks, NLMISC::IStream::serial(), and NLMISC::IStream::serialVersion().
|
|
Change the loop mode. true default.
Definition at line 204 of file track_sampled_common.cpp. Referenced by NL3D::CAnimationOptimizer::optimizeTrack().
00205 { 00206 _LoopMode= mode; 00207 } |
|
Definition at line 68 of file track_sampled_common.h. |
|
Definition at line 73 of file track_sampled_common.h. |
|
Definition at line 69 of file track_sampled_common.h. |
|
Definition at line 131 of file track_sampled_quat.h. |
|
Definition at line 67 of file track_sampled_common.h. |
|
Definition at line 74 of file track_sampled_common.h. Referenced by NL3D::CTrackSampledCommon::buildCommon(), NL3D::CTrackSampledCommon::evalTime(), and NL3D::CTrackSampledCommon::serialCommon(). |
|
Definition at line 71 of file track_sampled_common.h. |
|
Definition at line 98 of file track_sampled_common.h. Referenced by NL3D::CTrackSampledCommon::buildCommon(), NL3D::CTrackSampledCommon::evalTime(), and NL3D::CTrackSampledCommon::serialCommon(). |
|
Definition at line 70 of file track_sampled_common.h. |
|
Definition at line 128 of file track_sampled_quat.h. |