Implement quadratic interpolation for scalars and vectors

pull/593/head
Capostrophic 4 years ago
parent 35de34c019
commit aa131262ea

@ -26,11 +26,11 @@ enum InterpolationType
template<typename T>
struct KeyT {
T mValue;
T mInTan; // Only for Quadratic interpolation, and never for QuaternionKeyList
T mOutTan; // Only for Quadratic interpolation, and never for QuaternionKeyList
// FIXME: Implement Quadratic and TBC interpolation
// FIXME: Implement TBC interpolation
/*
T mForwardValue; // Only for Quadratic interpolation, and never for QuaternionKeyList
T mBackwardValue; // Only for Quadratic interpolation, and never for QuaternionKeyList
float mTension; // Only for TBC interpolation
float mBias; // Only for TBC interpolation
float mContinuity; // Only for TBC interpolation
@ -136,8 +136,8 @@ private:
static void readQuadratic(NIFStream &nif, KeyT<U> &key)
{
readValue(nif, key);
/*key.mForwardValue = */(nif.*getValue)();
/*key.mBackwardValue = */(nif.*getValue)();
key.mInTan = (nif.*getValue)();
key.mOutTan = (nif.*getValue)();
}
static void readQuadratic(NIFStream &nif, KeyT<osg::Quat> &key)

@ -110,6 +110,24 @@ namespace NifOsg
{
case Nif::InterpolationType_Constant:
return fraction > 0.5f ? b.mValue : a.mValue;
case Nif::InterpolationType_Quadratic:
{
// Using a cubic Hermite spline.
// b1(t) = 2t^3 - 3t^2 + 1
// b2(t) = -2t^3 + 3t^2
// b3(t) = t^3 - 2t^2 + t
// b4(t) = t^3 - t^2
// f(t) = a.mValue * b1(t) + b.mValue * b2(t) + a.mOutTan * b3(t) + b.mInTan * b4(t)
const float t = fraction;
const float t2 = t * t;
const float t3 = t2 * t;
const float b1 = 2.f * t3 - 3.f * t2 + 1;
const float b2 = -2.f * t3 + 3.f * t2;
const float b3 = t3 - 2.f * t2 + t;
const float b4 = t3 - t2;
return a.mValue * b1 + b.mValue * b2 + a.mOutTan * b3 + b.mInTan * b4;
}
// TODO: Implement TBC interpolation
default:
return a.mValue + ((b.mValue - a.mValue) * fraction);
}
@ -120,6 +138,7 @@ namespace NifOsg
{
case Nif::InterpolationType_Constant:
return fraction > 0.5f ? b.mValue : a.mValue;
// TODO: Implement Quadratic and TBC interpolation
default:
{
osg::Quat result;

Loading…
Cancel
Save