2011-03-25 74 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