#include "TKArray.h"#include "vfile.h"Go to the source code of this file.
|
|
Definition at line 49 of file vkframe.h. Referenced by gePath_PathToVKInterpolation().
00050 {
00051 VKFRAME_LINEAR,
00052 VKFRAME_HERMITE,
00053 VKFRAME_HERMITE_ZERO_DERIV,
00054 } geVKFrame_InterpolationType;
|
|
||||||||||||||||
|
Referenced by gePath_CreateFromBinaryFile(). |
|
||||||||||||||||
|
Referenced by gePath_CreateFromFile(). |
|
|
Definition at line 83 of file vkframe.c. References GENESISCC, and geTKArray_Create(). Referenced by gePath_ReadChannel_F0_(), and gePath_SetupTranslationKeyList().
00085 {
00086 return geTKArray_Create(sizeof(geVKFrame_Hermite) );
00087 }
|
|
||||||||||||||||||||
|
Definition at line 194 of file vkframe.c. References geFloat, GENESISCC, geVec3d_AddScaled(), geVec3d_Scale(), and NULL.
00203 {
00204 geVec3d *Vec1,*Vec2;
00205 geVec3d *VNew = (geVec3d *)Result;
00206
00207 assert( Result != NULL );
00208 assert( KF1 != NULL );
00209 assert( KF2 != NULL );
00210
00211 assert( T >= (geFloat)0.0f );
00212 assert( T <= (geFloat)1.0f );
00213
00214 if ( KF1 == KF2 )
00215 {
00216 *VNew = ((geVKFrame_Hermite *)KF1)->Key.V;
00217 return;
00218 }
00219
00220 Vec1 = &( ((geVKFrame_Hermite *)KF1)->Key.V);
00221 Vec2 = &( ((geVKFrame_Hermite *)KF2)->Key.V);
00222
00223 {
00224 geFloat t2; // T sqaured
00225 geFloat t3; // T cubed
00226 geFloat H1,H2,H3,H4; // hermite basis function coefficients
00227
00228 t2 = T * T;
00229 t3 = t2 * T;
00230
00231 H2 = -(t3 + t3) + t2*3.0f;
00232 H1 = 1.0f - H2;
00233 H4 = t3 - t2;
00234 H3 = H4 - t2 + T; //t3 - 2.0f * t2 + t;
00235
00236 geVec3d_Scale(Vec1,H1,VNew);
00237 geVec3d_AddScaled(VNew,Vec2,H2,VNew);
00238 geVec3d_AddScaled(VNew,&( ((geVKFrame_Hermite *)KF1)->DDerivative),H3,VNew);
00239 geVec3d_AddScaled(VNew,&( ((geVKFrame_Hermite *)KF2)->SDerivative),H4,VNew);
00240 }
00241 }
|
|
||||||||||||
|
Definition at line 426 of file vkframe.c. References CHECK_FOR_READ, geVKFrame_Hermite::DDerivative, ERR_PATH_FILE_READ, ERR_PATH_FILE_VERSION, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_Add, GENESISCC, geVFile_GetS(), geVFile_Read(), geVKFrame_Hermite::Key, NULL, geVKFrame_Hermite::SDerivative, uint32, geVKFrame::V, VKFRAME_HERMITE_ASCII_FILE, geVec3d::X, geVec3d::Y, and geVec3d::Z. Referenced by gePath_ReadChannel_F0_().
00427 {
00428 uint32 u;
00429 char HermiteString[128];
00430 geVKFrame_Hermite* pHermite = (geVKFrame_Hermite*)geVKFrame;
00431
00432 assert( pFile != NULL );
00433 assert( geVKFrame != NULL );
00434
00435 // Read the format/version flag
00436 if(geVFile_Read(pFile, &u, sizeof(u)) == GE_FALSE)
00437 {
00438 geErrorLog_Add(ERR_PATH_FILE_READ, NULL);
00439 return GE_FALSE;
00440 }
00441
00442 if(u != VKFRAME_HERMITE_ASCII_FILE)
00443 {
00444 geErrorLog_Add(ERR_PATH_FILE_VERSION, NULL);
00445 return GE_FALSE;
00446 }
00447
00448 if (geVFile_GetS(pFile, HermiteString, sizeof(HermiteString)) == GE_FALSE)
00449 {
00450 geErrorLog_Add(ERR_PATH_FILE_READ, NULL);
00451 return GE_FALSE;
00452 }
00453 u = sscanf(HermiteString, "%f %f %f %f %f %f %f %f %f\n", &pHermite->Key.V.X,
00454 &pHermite->Key.V.Y,
00455 &pHermite->Key.V.Z,
00456 &pHermite->SDerivative.X,
00457 &pHermite->SDerivative.Y,
00458 &pHermite->SDerivative.Z,
00459 &pHermite->DDerivative.X,
00460 &pHermite->DDerivative.Y,
00461 &pHermite->DDerivative.Z);
00462 CHECK_FOR_READ(u, 9);
00463
00464 return GE_TRUE;
00465 }
|
|
||||||||||||||||
|
Definition at line 244 of file vkframe.c. References count, geVKFrame_Hermite::DDerivative, GE_FALSE, GE_TRUE, geFloat, GENESISCC, geTKArray_Element(), geTKArray_ElementSize(), geTKArray_NumElements(), geVec3d_Clear(), geVec3d_Copy(), geVec3d_Scale(), geVec3d_Subtract(), geVKFrame_Hermite::Key, NULL, geVKFrame_Hermite::SDerivative, geVKFrame::Time, V1, and V2. Referenced by gePath_Recompute(), geVKFrame_CreateFromBinaryFile(), and geVKFrame_CreateFromFile().
00249 {
00250 // compute the incoming and outgoing derivatives at each keyframe
00251 int i;
00252 geVec3d V0,V1,V2;
00253 geFloat Time0, Time1, Time2, N0, N1, N0N1;
00254 geVKFrame_Hermite *TK;
00255 geVKFrame_Hermite *Vector= NULL;
00256 int count;
00257 int Index0,Index1,Index2;
00258
00259 assert( KeyList != NULL );
00260 assert( sizeof(geVKFrame_Hermite) == geTKArray_ElementSize(KeyList) );
00261
00262
00263 // Compute derivatives at the keyframe points:
00264 // The derivative is the average of the source chord p[i]-p[i-1]
00265 // and the destination chord p[i+1]-p[i]
00266 // (where i is Index1 in this function)
00267 // D = 1/2 * ( p[i+1]-p[i-1] ) = 1/2 *( (p[i+1]-p[i]) + (p[i]-p[i-1]) )
00268 // The very first and last chords are simply the
00269 // destination and source derivative.
00270 // These 'averaged' D's are adjusted for variences in the time scale
00271 // between the Keyframes. To do this, the derivative at each keyframe
00272 // is split into two parts, an incoming ('source' DS)
00273 // and an outgoing ('destination' DD) derivative.
00274 // DD[i] = DD[i] * 2 * N[i] / ( N[i-1] + N[i] )
00275 // DS[i] = DS[i] * 2 * N[i-1]/ ( N[i-1] + N[i] )
00276 // where N[i] is time between keyframes i and i+1
00277 // Since the chord dealt with on a given chord between key[i] and key[i+1], only
00278 // one of the derivates are needed for each keyframe. For key[i] the outgoing
00279 // derivative at is needed (DD[i]). For key[i+1], the incoming derivative
00280 // is needed (DS[i+1]) ( note that (1/2) * 2 = 1 )
00281 count = geTKArray_NumElements(KeyList);
00282 if (count > 0)
00283 {
00284 Vector = (geVKFrame_Hermite *)geTKArray_Element(KeyList,0);
00285 }
00286
00287 if (ZeroDerivative!=GE_FALSE)
00288 { // in this case, just bang all derivatives to zero.
00289 for (i =0; i< count; i++)
00290 {
00291 TK = &(Vector[i]);
00292 geVec3d_Clear(&(TK->DDerivative));
00293 geVec3d_Clear(&(TK->SDerivative));
00294 }
00295 return;
00296 }
00297
00298 if (count < 3)
00299 {
00300 Looped = GE_FALSE;
00301 // cant compute slopes without a closed loop:
00302 // so compute slopes as if it is not closed.
00303 }
00304 for (i =0; i< count; i++)
00305 {
00306 TK = &(Vector[i]);
00307 Index0 = i-1;
00308 Index1 = i;
00309 Index2 = i+1;
00310
00311 Time1 = Vector[Index1].Key.Time;
00312 if (Index1 == 0)
00313 {
00314 if (Looped != GE_TRUE)
00315 {
00316 Index0 = 0;
00317 Time0 = Vector[Index0].Key.Time;
00318 }
00319 else
00320 {
00321 Index0 = count-2;
00322 Time0 = Time1 - (Vector[count-1].Key.Time - Vector[count-2].Key.Time);
00323 }
00324 }
00325 else
00326 {
00327 Time0 = Vector[Index0].Key.Time;
00328 }
00329
00330
00331 if (Index2 == count)
00332 {
00333 if (Looped != GE_TRUE)
00334 {
00335 Index2 = count-1;
00336 Time2 = Vector[Index2].Key.Time;
00337 }
00338 else
00339 {
00340 Index2 = 1;
00341 Time2 = Time1 + (Vector[1].Key.Time - Vector[0].Key.Time);
00342 }
00343 }
00344 else
00345 {
00346 Time2 = Vector[Index2].Key.Time;
00347 }
00348
00349 V0 = Vector[Index0].Key.V;
00350 V1 = Vector[Index1].Key.V;
00351 V2 = Vector[Index2].Key.V;
00352
00353 N0 = (Time1 - Time0);
00354 N1 = (Time2 - Time1);
00355 N0N1 = N0 + N1;
00356
00357 if (( Looped != GE_TRUE) && (Index1 == 0) )
00358 {
00359 geVec3d_Subtract(&V2,&V1,&(TK->SDerivative));
00360 geVec3d_Copy( &(TK->SDerivative), &(TK->DDerivative));
00361 }
00362 else if (( Looped != GE_TRUE) && (Index1 == count-1))
00363 {
00364 geVec3d_Subtract(&V1,&V0,&(TK->SDerivative));
00365 geVec3d_Copy( &(TK->SDerivative), &(TK->DDerivative));
00366 }
00367 else
00368 {
00369 geVec3d Slope;
00370 geVec3d_Subtract(&V2,&V0,&Slope);
00371 geVec3d_Scale(&Slope, (N1 / N0N1), &(TK->DDerivative));
00372 geVec3d_Scale(&Slope, (N0 / N0N1), &(TK->SDerivative));
00373 }
00374 }
00375 }
|
|
||||||||||||||||||||
|
Definition at line 90 of file vkframe.c. References ERR_VKARRAY_INSERT, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_Add, GENESISCC, geTKArray_Element(), geTKArray_ElementSize(), geTKArray_Insert(), NULL, geVKFrame::V, and V. Referenced by gePath_CreateCopy(), and gePath_InsertKeyframe().
00096 {
00097 assert( KeyList != NULL );
00098 assert( *KeyList != NULL );
00099 assert( V != NULL );
00100 assert( sizeof(geVKFrame_Hermite) == geTKArray_ElementSize(*KeyList)
00101 || sizeof(geVKFrame_Linear) == geTKArray_ElementSize(*KeyList) );
00102
00103 if (geTKArray_Insert(KeyList, Time, Index) == GE_FALSE)
00104 {
00105 geErrorLog_Add(ERR_VKARRAY_INSERT, NULL);
00106 return GE_FALSE;
00107 }
00108 else
00109 {
00110 geVKFrame *KF;
00111 KF = (geVKFrame *)geTKArray_Element(*KeyList,*Index);
00112 KF->V = *V;
00113 return GE_TRUE;
00114 }
00115 }
|
|
|
Definition at line 76 of file vkframe.c. References GENESISCC, and geTKArray_Create(). Referenced by gePath_ReadChannel_F0_(), and gePath_SetupTranslationKeyList().
00078 {
00079 return geTKArray_Create(sizeof(geVKFrame_Linear) );
00080 }
|
|
||||||||||||||||||||
|
Definition at line 158 of file vkframe.c. References geFloat, GENESISCC, LINEAR_BLEND, NULL, geVec3d::X, geVec3d::Y, and geVec3d::Z.
00167 {
00168 geVec3d *Vec1,*Vec2;
00169 geVec3d *VNew = (geVec3d *)Result;
00170
00171 assert( Result != NULL );
00172 assert( KF1 != NULL );
00173 assert( KF2 != NULL );
00174
00175 assert( T >= (geFloat)0.0f );
00176 assert( T <= (geFloat)1.0f );
00177
00178 if ( KF1 == KF2 )
00179 {
00180 *VNew = ((geVKFrame_Linear *)KF1)->Key.V;
00181 return;
00182 }
00183
00184 Vec1 = &( ((geVKFrame_Linear *)KF1)->Key.V);
00185 Vec2 = &( ((geVKFrame_Linear *)KF2)->Key.V);
00186
00187 VNew->X = LINEAR_BLEND(Vec1->X,Vec2->X,T);
00188 VNew->Y = LINEAR_BLEND(Vec1->Y,Vec2->Y,T);
00189 VNew->Z = LINEAR_BLEND(Vec1->Z,Vec2->Z,T);
00190 }
|
|
||||||||||||
|
Definition at line 389 of file vkframe.c. References CHECK_FOR_READ, ERR_PATH_FILE_READ, ERR_PATH_FILE_VERSION, GE_FALSE, GE_TRUE, geBoolean, geErrorLog_Add, GENESISCC, geVFile_GetS(), geVFile_Read(), geVKFrame_Linear::Key, NULL, uint32, geVKFrame::V, VKFRAME_LINEAR_ASCII_FILE, geVec3d::X, geVec3d::Y, and geVec3d::Z. Referenced by gePath_ReadChannel_F0_().
00390 {
00391 uint32 u;
00392 char KeyString[64];
00393 geVKFrame_Linear* pLinear = (geVKFrame_Linear*)geVKFrame;
00394
00395 assert( pFile != NULL );
00396 assert( geVKFrame != NULL );
00397
00398 // Read the format/version flag
00399 if(geVFile_Read(pFile, &u, sizeof(u)) == GE_FALSE)
00400 {
00401 geErrorLog_Add(ERR_PATH_FILE_READ, NULL);
00402 return GE_FALSE;
00403 }
00404
00405 if(u != VKFRAME_LINEAR_ASCII_FILE)
00406 {
00407 geErrorLog_Add(ERR_PATH_FILE_VERSION, NULL);
00408 return GE_FALSE;
00409 }
00410
00411 if (geVFile_GetS(pFile, KeyString, sizeof(KeyString)) == GE_FALSE)
00412 {
00413 geErrorLog_Add(ERR_PATH_FILE_READ, NULL);
00414 return GE_FALSE;
00415 }
00416
00417 u = sscanf(KeyString, "%f %f %f\n", &pLinear->Key.V.X,
00418 &pLinear->Key.V.Y,
00419 &pLinear->Key.V.Z);
00420 CHECK_FOR_READ(u, 3);
00421
00422 return GE_TRUE;
00423 }
|
|
||||||||||||||||
|
Definition at line 139 of file vkframe.c. References GENESISCC, geTKArray_Element(), geTKArray_ElementSize(), geTKArray_NumElements(), NULL, geVKFrame::V, and V. Referenced by gePath_ModifyKeyframe().
00144 {
00145 geVKFrame *KF;
00146 assert( KeyList != NULL );
00147 assert( V != NULL );
00148 assert( Index < geTKArray_NumElements(KeyList) );
00149 assert( Index >= 0 );
00150 assert( sizeof(geVKFrame_Hermite) == geTKArray_ElementSize(KeyList)
00151 || sizeof(geVKFrame_Linear) == geTKArray_ElementSize(KeyList) );
00152
00153 KF = (geVKFrame *)geTKArray_Element(KeyList,Index);
00154 KF->V = *V;
00155 }
|
|
||||||||||||||||||||
|
Definition at line 117 of file vkframe.c. References GENESISCC, geTKArray_Element(), geTKArray_ElementSize(), geTKArray_NumElements(), NULL, geVKFrame::Time, geVKFrame::V, and V. Referenced by gePath_CreateCopy(), and gePath_GetKeyframe().
00123 {
00124 geVKFrame *KF;
00125 assert( KeyList != NULL );
00126 assert( Time != NULL );
00127 assert( V != NULL );
00128 assert( Index < geTKArray_NumElements(KeyList) );
00129 assert( Index >= 0 );
00130 assert( sizeof(geVKFrame_Hermite) == geTKArray_ElementSize(KeyList)
00131 || sizeof(geVKFrame_Linear) == geTKArray_ElementSize(KeyList) );
00132
00133 KF = (geVKFrame *)geTKArray_Element(KeyList,Index);
00134 *Time = KF->Time;
00135 *V = KF->V;
00136 }
|
|
||||||||||||||||||||
|
Referenced by gePath_WriteToBinaryFile(). |
|
||||||||||||||||||||
|
Referenced by gePath_WriteToFile(). |
1.3.2