我知道這段代碼只是看起來像一大塊混亂,所以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