#include <stdio.h>
#include <maya/MFnAnimCurve.h>
#include <maya/MObject.h>
#include <maya/MPxAnimCurveInterpolator.h>
#include <maya/MTime.h>
#include <maya/MTypeId.h>
#include "interpHalf.h"
interpHalf::interpHalf()
{
sTime = 0.0;
range = 0.0;
}
interpHalf::~interpHalf() {}
void* interpHalf::creator()
{
return new interpHalf();
}
void interpHalf::initialize(
const MObject &animCurve,
unsigned int interval)
{
bool isBeforeHalf = false;
int beforeInd = interval - 1;
if (beforeInd < 0)
beforeInd = 0;
else
{
if (beforeType == MFnAnimCurve::kTangentShared1)
isBeforeHalf = true;
}
if (isBeforeHalf)
beforeVal = 0.5 * curveFn.value(beforeInd) + 0.5 * curveFn.value(interval);
else
beforeVal = curveFn.value(interval);
int afterInd = interval + 1;
if (afterType == MFnAnimCurve::kTangentShared1)
afterVal = 0.5 * curveFn.value(interval) + 0.5 * curveFn.value(afterInd);
else
afterVal = curveFn.value(afterInd);
}
double interpHalf::evaluate(
const MTime &val)
{
double alpha = (sec-sTime) / range;
return (1.0 - alpha) * beforeVal + alpha * afterVal;
}