move interpolation calculation to TInbetween
This commit is contained in:
parent
e7dd1492d7
commit
ab0188ea0f
3 changed files with 51 additions and 22 deletions
|
@ -229,8 +229,8 @@ static void detectCorners(const TStroke *stroke, double minDegree,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const double ratioLen = 2.5;
|
const double ratioLen = 2.5;
|
||||||
const double ratioAngle = 0.2;
|
const double ratioAngle = 0.2;
|
||||||
std::vector<std::pair<int, double>>::iterator it = corners.begin();
|
std::vector<std::pair<int, double>>::iterator it = corners.begin();
|
||||||
|
|
||||||
for (j = 1; j < (int)quadCount1;
|
for (j = 1; j < (int)quadCount1;
|
||||||
|
@ -241,8 +241,9 @@ static void detectCorners(const TStroke *stroke, double minDegree,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j - 2 >= 0 && (corners.empty() || it == corners.begin() ||
|
if (j - 2 >= 0 &&
|
||||||
j - 1 != (*(it - 1)).first) &&
|
(corners.empty() || it == corners.begin() ||
|
||||||
|
j - 1 != (*(it - 1)).first) &&
|
||||||
j + 1 < (int)quadCount1 &&
|
j + 1 < (int)quadCount1 &&
|
||||||
(corners.empty() || it == corners.end() || j + 1 != (*it).first)) {
|
(corners.empty() || it == corners.end() || j + 1 != (*it).first)) {
|
||||||
speed1 = stroke->getChunk(j - 2)->getSpeed(1);
|
speed1 = stroke->getChunk(j - 2)->getSpeed(1);
|
||||||
|
@ -255,7 +256,7 @@ static void detectCorners(const TStroke *stroke, double minDegree,
|
||||||
if (tan1 * tan2 < 0) {
|
if (tan1 * tan2 < 0) {
|
||||||
angle = 180 - asin(tcrop(vectorialProduct, -1.0, 1.0)) * M_180_PI;
|
angle = 180 - asin(tcrop(vectorialProduct, -1.0, 1.0)) * M_180_PI;
|
||||||
|
|
||||||
metaCornerLen = ratioLen * (stroke->getChunk(j - 1)->getLength() +
|
metaCornerLen = ratioLen * (stroke->getChunk(j - 1)->getLength() +
|
||||||
stroke->getChunk(j)->getLength());
|
stroke->getChunk(j)->getLength());
|
||||||
partialLen = 0;
|
partialLen = 0;
|
||||||
bool goodAngle = false;
|
bool goodAngle = false;
|
||||||
|
@ -1480,8 +1481,8 @@ TVectorImageP TInbetween::Imp::tween(double t) const {
|
||||||
len1 += step1;
|
len1 += step1;
|
||||||
len2 += step2;
|
len2 += step2;
|
||||||
}
|
}
|
||||||
point2 = subStroke2->getThickPointAtLength(totalLen2);
|
point2 = subStroke2->getThickPointAtLength(totalLen2);
|
||||||
point2 = TThickPoint(m_transformation[i].m_inverse *
|
point2 = TThickPoint(m_transformation[i].m_inverse *
|
||||||
subStroke2->getThickPointAtLength(totalLen2),
|
subStroke2->getThickPointAtLength(totalLen2),
|
||||||
point2.thick);
|
point2.thick);
|
||||||
finalPoint = subStroke1->getThickPointAtLength(totalLen1) * (1 - t) +
|
finalPoint = subStroke1->getThickPointAtLength(totalLen1) * (1 - t) +
|
||||||
|
@ -1554,3 +1555,20 @@ void TInbetween::Imp::transferColor(const TVectorImageP &destination) const {
|
||||||
TVectorImageP TInbetween::tween(double t) const { return m_imp->tween(t); }
|
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;
|
std::unique_ptr<Imp> m_imp;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
enum TweenAlgorithm {
|
||||||
|
LinearInterpolation,
|
||||||
|
EaseInInterpolation,
|
||||||
|
EaseOutInterpolation,
|
||||||
|
EaseInOutInterpolation
|
||||||
|
};
|
||||||
|
|
||||||
|
static double interpolation(double t, enum TweenAlgorithm);
|
||||||
|
|
||||||
TInbetween(const TVectorImageP firstImage, const TVectorImageP lastImage);
|
TInbetween(const TVectorImageP firstImage, const TVectorImageP lastImage);
|
||||||
|
|
||||||
virtual ~TInbetween();
|
virtual ~TInbetween();
|
||||||
|
|
|
@ -2499,25 +2499,27 @@ void FilmstripCmd::inbetweenWithoutUndo(
|
||||||
TVectorImageP img1 = sl->getFrame(fid1, false);
|
TVectorImageP img1 = sl->getFrame(fid1, false);
|
||||||
if (!img0 || !img1) return;
|
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);
|
TInbetween inbetween(img0, img1);
|
||||||
int i;
|
int i;
|
||||||
for (i = ia + 1; i < ib; i++) {
|
for (i = ia + 1; i < ib; i++) {
|
||||||
double t = (double)(i - ia) / (double)(ib - ia);
|
double t = (double)(i - ia) / (double)(ib - ia);
|
||||||
double s = t;
|
double s = TInbetween::interpolation(t, algorithm);
|
||||||
// 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
|
|
||||||
}
|
|
||||||
|
|
||||||
TVectorImageP vi = inbetween.tween(s);
|
TVectorImageP vi = inbetween.tween(s);
|
||||||
sl->setFrame(fids[i], vi);
|
sl->setFrame(fids[i], vi);
|
||||||
|
|
Loading…
Reference in a new issue