Commit 6cba67dc by Kai Westerkamp

fixed splines

parent 87d9d8f0
...@@ -13,7 +13,7 @@ MainWindow::MainWindow(QWidget *parent) : ...@@ -13,7 +13,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(loadMesh, SIGNAL(triggered()), m_centralWidget, SLOT(loadNewMesh())); connect(loadMesh, SIGNAL(triggered()), m_centralWidget, SLOT(loadNewMesh()));
toolBar->addAction(loadMesh); toolBar->addAction(loadMesh);
switchInterpolation = new QAction("Interpolation",this); switchInterpolation = new QAction("Lin Interpol",this);
switchInterpolation->setCheckable(true); switchInterpolation->setCheckable(true);
switchInterpolation->setChecked(false); switchInterpolation->setChecked(false);
connect(switchInterpolation, SIGNAL(triggered(bool)), m_centralWidget, SLOT(setInterpolation(bool))); connect(switchInterpolation, SIGNAL(triggered(bool)), m_centralWidget, SLOT(setInterpolation(bool)));
......
...@@ -523,10 +523,7 @@ QVector3D Mesh::calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeA ...@@ -523,10 +523,7 @@ QVector3D Mesh::calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeA
QVector3D start = convert(keys[index].mValue); QVector3D start = convert(keys[index].mValue);
QVector3D end = convert(keys[index+1].mValue); QVector3D end = convert(keys[index+1].mValue);
if(linear) if(start.distanceToPoint(end) < 0.00001){ // same keyframe
return linInterpolate(start,end,Factor);
if(start.distanceToPoint(end) == 0){ // same keyframse not interpolation
return start; return start;
} }
...@@ -540,14 +537,29 @@ QVector3D Mesh::calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeA ...@@ -540,14 +537,29 @@ QVector3D Mesh::calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeA
case aiAnimBehaviour_LINEAR: // linear interpolate case aiAnimBehaviour_LINEAR: // linear interpolate
return linInterpolate(start,end,Factor); return linInterpolate(start,end,Factor);
case aiAnimBehaviour_DEFAULT: // take default node transformation case aiAnimBehaviour_DEFAULT: // take default node transformation
//TODO
default: default:
return linInterpolate(start,end,Factor); //TODO return linInterpolate(start,end,Factor);
} }
} else if((index+2)== numberOfKeys){ } else if((index+2)== numberOfKeys){
//end switch (nodeAnimation->mPostState) {
return linInterpolate(start,end,Factor); case aiAnimBehaviour_CONSTANT: // nearest Key
return Factor <0.5f ? start : end;
break;
case aiAnimBehaviour_REPEAT: // use start or end
//TODO
case aiAnimBehaviour_LINEAR: // linear interpolate
return linInterpolate(start,end,Factor);
case aiAnimBehaviour_DEFAULT: // take default node transformation
//TODO
default:
return linInterpolate(start,end,Factor);
}
} else{ } else{
if(linear)
return linInterpolate(start,end,Factor);
QVector3D before = convert(keys[index-1].mValue); QVector3D before = convert(keys[index-1].mValue);
QVector3D after = convert(keys[index+2].mValue); QVector3D after = convert(keys[index+2].mValue);
...@@ -564,18 +576,19 @@ QVector3D Mesh::calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeA ...@@ -564,18 +576,19 @@ QVector3D Mesh::calcInterpolatedVectorKey(float AnimTime,const aiNodeAnim *nodeA
} }
QVector3D Mesh::Catmul(QVector3D before, QVector3D start, QVector3D end, QVector3D after,float Factor){ QVector3D Mesh::Catmul(QVector3D P0, QVector3D P1, QVector3D P2, QVector3D P3,float Factor){
float t0 = 0; double t0 = 0;
float t1 = timeCatmul(before,start,t0); double t1 = timeCatmul(P0,P1,t0);
float t2 = timeCatmul(start,end,t1); double t2 = timeCatmul(P1,P2,t1);
float t3 = timeCatmul(end,after,t2); double t3 = timeCatmul(P2,P3,t2);
float t = Factor;//(1-Factor)*t1+Factor*t2; double t = Factor;
t = (1-Factor)*t1+Factor*t2;
//qDebug()<<before<<start<<end<<after; //qDebug()<<before<<start<<end<<after;
//qDebug()<<t0<<t1<<t2<<t3<<t; //qDebug()<<t0<<t1<<t2<<t3<<t;
QVector3D A1 = (t1-t)/(t1-t0)*before + (t-t0)/(t1-t0)*start; QVector3D A1 = (t1-t)/(t1-t0)*P0 + (t-t0)/(t1-t0)*P1;
QVector3D A2 = (t2-t)/(t2-t1)*start + (t-t1)/(t2-t1)*end; QVector3D A2 = (t2-t)/(t2-t1)*P1 + (t-t1)/(t2-t1)*P2;
QVector3D A3 = (t3-t)/(t3-t2)*end + (t-t2)/(t3-t2)*after; QVector3D A3 = (t3-t)/(t3-t2)*P2 + (t-t2)/(t3-t2)*P3;
QVector3D B1 = (t2-t)/(t2-t0)*A1 + (t-t0)/(t2-t0)*A2; QVector3D B1 = (t2-t)/(t2-t0)*A1 + (t-t0)/(t2-t0)*A2;
QVector3D B2 = (t3-t)/(t3-t1)*A2 + (t-t1)/(t3-t1)*A3; QVector3D B2 = (t3-t)/(t3-t1)*A2 + (t-t1)/(t3-t1)*A3;
...@@ -585,9 +598,13 @@ QVector3D Mesh::Catmul(QVector3D before, QVector3D start, QVector3D end, QVector ...@@ -585,9 +598,13 @@ QVector3D Mesh::Catmul(QVector3D before, QVector3D start, QVector3D end, QVector
} }
float Mesh::timeCatmul(QVector3D p1, QVector3D p2, float t_1){ double Mesh::timeCatmul(QVector3D p1, QVector3D p2, double t_1){
float dist = p1.distanceToPoint(p2); double dist = p1.distanceToPoint(p2);
float t = powf(dist,0.5) +t_1; double alpha = 0.0; //uniform
alpha = 0.5; //centripetal
//float alpha = 1.0; //chordal
double t = qPow(dist,alpha) +t_1;
// qDebug()<<dist<<t; // qDebug()<<dist<<t;
return t; return t;
} }
......
...@@ -149,7 +149,7 @@ private: ...@@ -149,7 +149,7 @@ private:
QVector3D linInterpolate(QVector3D start, QVector3D end, float Factor){ return (1.0-Factor)*start + Factor*end;} QVector3D linInterpolate(QVector3D start, QVector3D end, float Factor){ return (1.0-Factor)*start + Factor*end;}
QVector3D Catmul(QVector3D before, QVector3D start, QVector3D end, QVector3D after,float Factor); QVector3D Catmul(QVector3D before, QVector3D start, QVector3D end, QVector3D after,float Factor);
float timeCatmul(QVector3D p1, QVector3D p2, float t_1); double timeCatmul(QVector3D p1, QVector3D p2, double t_1);
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment