move interpolation calculation to TInbetween
This commit is contained in:
parent
e7dd1492d7
commit
ab0188ea0f
3 changed files with 51 additions and 22 deletions
|
@ -241,7 +241,8 @@ static void detectCorners(const TStroke *stroke, double minDegree,
|
|||
continue;
|
||||
}
|
||||
|
||||
if (j - 2 >= 0 && (corners.empty() || it == corners.begin() ||
|
||||
if (j - 2 >= 0 &&
|
||||
(corners.empty() || it == corners.begin() ||
|
||||
j - 1 != (*(it - 1)).first) &&
|
||||
j + 1 < (int)quadCount1 &&
|
||||
(corners.empty() || it == corners.end() || j + 1 != (*it).first)) {
|
||||
|
@ -1554,3 +1555,20 @@ void TInbetween::Imp::transferColor(const TVectorImageP &destination) const {
|
|||
TVectorImageP TInbetween::tween(double t) const { return m_imp->tween(t); }
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
||||
double TInbetween::interpolation(double t, enum TweenAlgorithm algorithm) {
|
||||
// in tutte le interpolazioni : s(0) = 0, s(1) = 1
|
||||
switch (algorithm) {
|
||||
case EaseInInterpolation: // s'(1) = 0
|
||||
return t * (2 - t);
|
||||
case EaseOutInterpolation: // s'(0) = 0
|
||||
return t * t;
|
||||
case EaseInOutInterpolation: // s'(0) = s'(1) = 0
|
||||
return t * t * (3 - 2 * t);
|
||||
case LinearInterpolation:
|
||||
default:
|
||||
return t;
|
||||
}
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
|
|
|
@ -24,6 +24,15 @@ class DVAPI TInbetween {
|
|||
std::unique_ptr<Imp> m_imp;
|
||||
|
||||
public:
|
||||
enum TweenAlgorithm {
|
||||
LinearInterpolation,
|
||||
EaseInInterpolation,
|
||||
EaseOutInterpolation,
|
||||
EaseInOutInterpolation
|
||||
};
|
||||
|
||||
static double interpolation(double t, enum TweenAlgorithm);
|
||||
|
||||
TInbetween(const TVectorImageP firstImage, const TVectorImageP lastImage);
|
||||
|
||||
virtual ~TInbetween();
|
||||
|
|
|
@ -2499,25 +2499,27 @@ void FilmstripCmd::inbetweenWithoutUndo(
|
|||
TVectorImageP img1 = sl->getFrame(fid1, false);
|
||||
if (!img0 || !img1) return;
|
||||
|
||||
enum TInbetween::TweenAlgorithm algorithm;
|
||||
switch (interpolation) {
|
||||
case II_Linear:
|
||||
algorithm = TInbetween::LinearInterpolation;
|
||||
break;
|
||||
case II_EaseIn:
|
||||
algorithm = TInbetween::EaseInInterpolation;
|
||||
break;
|
||||
case II_EaseOut:
|
||||
algorithm = TInbetween::EaseOutInterpolation;
|
||||
break;
|
||||
case II_EaseInOut:
|
||||
algorithm = TInbetween::EaseInOutInterpolation;
|
||||
break;
|
||||
}
|
||||
|
||||
TInbetween inbetween(img0, img1);
|
||||
int i;
|
||||
for (i = ia + 1; i < ib; i++) {
|
||||
double t = (double)(i - ia) / (double)(ib - ia);
|
||||
double s = t;
|
||||
// in tutte le interpolazioni : s(0) = 0, s(1) = 1
|
||||
switch (interpolation) {
|
||||
case II_Linear:
|
||||
break;
|
||||
case II_EaseIn:
|
||||
s = t * (2 - t);
|
||||
break; // s'(1) = 0
|
||||
case II_EaseOut:
|
||||
s = t * t;
|
||||
break; // s'(0) = 0
|
||||
case II_EaseInOut:
|
||||
s = t * t * (3 - 2 * t);
|
||||
break; // s'(0) = s'(1) = 0
|
||||
}
|
||||
double s = TInbetween::interpolation(t, algorithm);
|
||||
|
||||
TVectorImageP vi = inbetween.tween(s);
|
||||
sl->setFrame(fids[i], vi);
|
||||
|
|
Loading…
Reference in a new issue