我知道这段代码只是看起来像一大块混乱,所以iv'e尽我所能评论我可以...如果任何人经常骨骼动画im希望你看到什么去这里。插值使用升压:定时器和斯勒普,四元数
im问题是float interp = (next-current)/(next-start);
没有返回什么期望,例如,值大于1和负值......我猜这是动画没有被显示,没有其他潜在错误的全部原因。如果有任何明显的突出,请让我知道。
m_animations
存储关节的所有关键帧信息。
void Animation::getRotation(Joint& J) {
int i=0,j=0; //i for bone to animation j for which keyframe in animation
float start, next, current = m_time.elapsed(); //storing time elapsed to keep it the same thoughout method to avoid errors
for (i=0; i<m_animations.size(); i++) {
if(m_animations[i].m_bname == J.name) //finds which bone is being animated
break;
} //retrieve the correct 'anim' for Joint
if (current > m_animations[i].rx_time[m_animations[i].rx_time.size()-1]) { //checks to see if end of animation
m_time.restart();
current = m_time.elapsed(); //resets the animation at its end
}
for (j=0; j<m_animations[i].rx_time.size()-1; j++) {
if(m_animations[i].rx_time[j] >= next && next < m_animations[i].rx_time[j+1]) { //finds the keyframe
start = m_animations[i].rx_time[j]; //start time of current frame
next = m_animations[i].rx_time[j+1]; //end time of current frame
break;
}
}
cout << start <<" "<< current <<" "<< m_time.elapsed() <<" "<< next << endl;
//Get start and end quaternions for slerp
Rotation3 Rj(m_animations[i].rx_angle[j], m_animations[i].ry_angle[j], m_animations[i].rz_angle[j], J.translation);
J.quat = Rj.GetQuat(); //rotating to
Rotation3 R = Rotation3(m_animations[i].rx_angle[j+1], m_animations[i].ry_angle[j+1], m_animations[i].rz_angle[j+1], J.translation);
Quat4 q = R.GetQuat(); //rotating from
float interp = (next-current)/(next-start); //find interpolation point
Quat4 slerp = Slerp(J.quat, q, interp); //sphereical linear interpolation
R = Rotation3(slerp,J.translation);
J.rotation.PasteRotation(R.GetRotationMatrix());
}
此外,如果它有助于继承人调用getRotation更新骨架功能
void Animation::update_skeleton(Joint& J) {
getRotation(J);
J.world.PasteTranslation(J.translation); //world becomes translation matrix
J.world *= J.rotation;
if(J.pName != "") {
J.world = Mat4(J.parent->world) *= J.world; //as not to overwrite the parents world matrix
}
J.translation = J.world.ExtractTranslation();
for(int i=0; i<J.children.size(); i++) {
update_skeleton(*J.children[i]);
}
}
而且当我运行我的程序,这似乎是因为如果只有一个关节...所以即时猜测在getRotation期间J.translation
值可能会出错,但我希望修复插值问题可能会解决这个问题...
任何帮助将非常感激。
刚刚发现rx_time的值正在改变,以及...开始4.04这是它应该是,然后下降到2.48然后1,并重复该过程...我不能看到即时更改数据的任何地方 – CurtisJC 2011-03-25 13:04:05