Jump to content

  • Log In with Google      Sign In   
  • Create Account

Problem with Hermite Interpolation in skinning mesh


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
No replies to this topic

#1 khanhhh89   Members   -  Reputation: 102

Like
0Likes
Like

Posted 04 February 2014 - 07:20 PM

I'm trying to implement an skinning mesh and I use Hermite Interpolation for evaulating frame's position. When I use the normal interpolation: t1*p1 + (1-t1)*p2, it run well, but  when I change to Hermite Interpolation, the mesh seems to run in the horizontal direction as it is shown in the following video.
 
This is my source code and I hope you can help me put the video and the source together, and provide some suggestions about the problem.
 
 1. Setup tangent
 
     for (int k = 0; k < numPositionKeys; k++)
{
// make the curve tangents looped
int k0 = k - 1;
if (k0 < 0)
k0 = numPositionKeys - 1;
int k1 = k;
int k2 = k + 1;
if (k2 >= numPositionKeys)
k2 = 0;

// calculate the tangent, which is the vector from key[k - 1] to key[k + 1]
float tangent[3];
tangent[0] = (joint->positionKeys[k2].key[0] - joint->positionKeys[k0].key[0]);
tangent[1] = (joint->positionKeys[k2].key[1] - joint->positionKeys[k0].key[1]);
tangent[2] = (joint->positionKeys[k2].key[2] - joint->positionKeys[k0].key[2]);

// weight the incoming and outgoing tangent by their time to avoid changes in speed, if the keys are not within the same interval
float dt1 = joint->positionKeys[k1].time - joint->positionKeys[k0].time;
float dt2 = joint->positionKeys[k2].time - joint->positionKeys[k1].time;
float dt = dt1 + dt2;

joint->tangents[k1].tangentIn[0] = tangent[0] * dt1 / dt;
joint->tangents[k1].tangentIn[1] = tangent[1] * dt1 / dt;
joint->tangents[k1].tangentIn[2] = tangent[2] * dt1 / dt;

joint->tangents[k1].tangentOut[0] = tangent[0] * dt2 / dt;
joint->tangents[k1].tangentOut[1] = tangent[1] * dt2 / dt;
joint->tangents[k1].tangentOut[2] = tangent[2] * dt2 / dt;
}
 
 2. Interpolating frame's position
 
int i1 = -1;
int i2 = -1;

// Find two keys, where frame is in between for the position channel
for(int i = 0; i < FramePosition.size()-1; i++){

if(m_fAnimationTime >= FramePosition[i].m_fTimeStamp && m_fAnimationTime < FramePosition[i+1].m_fTimeStamp){
i1 = i;
i2 = i+1;
break;
}
}
if(i1 == -1 || i2 ==-1){
//Either take the first 
if(m_fAnimationTime < m_vStates.front().m_fTimeStamp)
position = FramePosition.front();

//Or the last key
else if (m_fAnimationTime >= m_vStates.back().m_fTimeStamp)
position = FramePosition.back();
}else{

//Perform interpolation between the current frame and the next frame
//to find the current position.
            //Using i1 and i2 here to get position1, tangent1, position2, tangent2
Vector3f tangentOut1 = ...[i1]
Vector3f tangentIn2 = ...[i2]
Vector3f position1 = ...[i1];
Vector3f position2 = ...[i2];

float t = (m_fAnimationTime - m_fTimeStamp1)/(m_fTimeStamp2 - m_fTimeStamp1);
float t2 = t*t;
float t3 = t2*t;

// calculate Hermite basis
float h1 =  2.0f * t3 - 3.0f * t2 + 1.0f;
float h2 = -2.0f * t3 + 3.0f * t2;
float h3 =         t3 - 2.0f * t2 + t;
float h4 =         t3 -        t2;

            //And finally, interpolating...
position = h1 * position1 + h3 * tangentOut1 + h2 * position2 + h4 * tangentIn2;

}

 



Sponsor:



Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS