2011-03-25 71 views
1

我知道這段代碼只是看起來像一大塊混亂,所以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值可能會出錯,但我希望修復插值問題可能會解決這個問題...

任何幫助將非常感激。

+0

剛剛發現rx_time的值正在改變,以及...開始4.04這是它應該是,然後下降到2.48然後1,並重復該過程...我不能看到即時更改數據的任何地方 – CurtisJC 2011-03-25 13:04:05

回答

0

原來有不少錯誤......但主要的錯誤是與指針有關,我通過給父母,孩子和自己的骨骼ID來修復它。然後,我改變了功能,以取代骨骼id,而不是參考聯合。問題=修正:D

0

在使用start和next的原始值之前,您似乎正在重置電流,如果我已正確讀取代碼,會導致電流大於下一個,導致yor負插值。

+0

當時間流逝的時間大於上次關鍵幀中的時間(重置動畫)時,重置當前的電流...然後,電流總是用於查找程序在哪個關鍵幀上,然後得到開始和下一個值...所以電流應始終在開始和下一個之間。儘管rx_time中的數據出於某種原因正在發生變化,我認爲這些數據使得當前的數據大於下一個數據 – CurtisJC 2011-03-25 17:00:58