2011-03-25 6 views
1

이 코드는 엄청난 엉망진창처럼 보입니다. 그래서 내가 할 수있는 말을하기 위해 최선을 다했습니다 ... 누군가 정기적으로 골격 애니메이션을 사용한다면, 여기에.부스트를 사용하여 보간 : 타이머와 slerp, quaternions

내가 가진 문제는 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()); 
} 

는 heres는 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

답변

0

꽤 많은 실수가있었습니다 ...하지만 주된 실수는 포인터와 관련이 있습니다. 부모, 어린이 및 그 자체를 위해 뼈대 ID를 부여하여 해결했습니다. 그런 다음 조인트에 대한 참조 대신 뼈 ID를 사용하도록 함수를 변경했습니다. 문제가 = 고정 : D

0

시작과 다음의 원래 값을 사용하기 전에 현재 값을 재설정하는 것 같습니다. 코드를 올바르게 읽었 으면 전류가 다음보다 커야 부정적인 보간으로 이어질 수 있습니다.

+0

경과 된 시간이 마지막 키 프레임의 시간보다 길면 (애니메이션을 재설정하기 위해) 현재 리셋됩니다 ... 그리고 현재는 프로그램이 어느 키 프레임인지 찾기 위해 항상 사용됩니다 시작과 다음 값을 가져옵니다 ... 그래서 현재는 항상 시작과 끝 사이에 있어야합니다. rx_time의 데이터가 어떤 이유로 변경되고 있지만, 나는 현재의 데이터가 다음 데이터보다 더 큰 데이터를 생성한다고 생각합니다. – CurtisJC