#include "orfilterresample_filter.h"
#define FBTIME_POS_INFINITE FBTime( kLongLong( K_LONGLONG( 0x7fffffffffffffff )))
#define FBTIME_NEG_INFINITE FBTime( kLongLong( K_LONGLONG( 0x7fffffffffffffff )))
static const char* ORFilterErrorTable [ORFilterResample::eErrorCount] =
{
"No key",
"Left unchanged"
};
#define ORFILTERRESAMPLE__CLASS ORFilterResample
#define ORFILTERRESAMPLE__NAME "OR - Resample"
#define ORFILTERRESAMPLE__LABEL "OR - Resample"
#define ORFILTERRESAMPLE__DESC "OR - Resample Filter"
#define ORFILTERRESAMPLE__TYPE kFBFilterNumber | kFBFilterVector
#define ORFILTERRESAMPLE__ERRTABLE ORFilterErrorTable
#define ORFILTERRESAMPLE__ERRCOUNT ORFilterResample::eErrorCount
ORFILTERRESAMPLE__NAME,
ORFILTERRESAMPLE__LABEL,
ORFILTERRESAMPLE__TYPE,
ORFILTERRESAMPLE__ERRTABLE,
ORFILTERRESAMPLE__ERRCOUNT,
bool ORFilterResample::FBCreate()
{
Reset ();
return true;
}
void ORFilterResample::FBDestroy()
{
}
bool ORFilterResample::Apply( FBAnimationNode* pNode, bool pRecursive )
{
return FBFilter::Apply( pNode, pRecursive );
}
bool ORFilterResample::Apply( FBFCurve* pCurve )
{
FBTime lEvalTime;
FBTime lEvalStep;
double lValue;
if( mResampleRate != 0 )
{
lCurve = new FBFCurve;
lEvalStep.SetSecondDouble( 1.0 / mResampleRate );
if( FBTIME_NEG_INFINITE != Start &&
FBTIME_POS_INFINITE != Stop &&
FBTime( Start ) < FBTime( Stop ))
{
lEvalTime = Start;
while( lEvalTime <= Stop )
{
lValue = pCurve->Evaluate( lEvalTime );
lCurve->KeyAdd( lEvalTime, lValue );
lEvalTime += lEvalStep;
}
pCurve->Keys.RemoveAll();
for( i=0; i<lCurve->Keys.GetCount(); i++ )
{
lValue = lCurve->Keys[
i].Value;
lEvalTime = lCurve->Keys[
i].Time;
pCurve->KeyAdd( lEvalTime, lValue );
}
}
delete lCurve;
}
return FBFilter::Apply( pCurve );
}
void ORFilterResample::Reset()
{
FBFilter::Reset();
mResampleRate = 30.0;
}