• Create Account

### #Actualkeym

Posted 13 February 2013 - 06:04 AM

I'm interpolating in object space. Does this require rebuilding bone positions from hierarchy as well?

And my SLERP looks like this:

quaternion quaternion::slerp(quaternion q1, quaternion q2, float percent)
{
quaternion result;

float dot = q1.dotProduct(q2);              //Dot product - the cosine of the angle between 2 quats
if(dot < -1) dot = -1;                      //Clamp value to [-1,1], just to be sure
if(dot > 1) dot = 1;

if(dot < 0)                                  //If cos(angle) is <0 we negate the quaternion and dotp.
{                                            //(Go with smaller rotation)
q2=-q2;
dot=-dot;
}

if(dot > 0.99 && dot < 1.01)                 //If dotp is close to 1, do Lerp
{
result = q1 + ((q2 - q1) * percent);
result.normalize();
return result;
}

if(percent < 0.01)                           //If percent is close to 0, return quat1
{
result = q1;
return result;
}

if(percent > 0.99)                           //If percent is close to 1, return quat2
{
result=q2;
return result;
}

float a = acos(dot);                         //Get angle between quats
result = (q1 * (sin((1.0 - percent) * a) / sin(a))) +  ((q2 * sin(percent * a)) / sin(a));
return result;
}


### #2keym

Posted 13 February 2013 - 06:02 AM

I'm interpolating in object space. Does this require rebuilding bone positions from hierarchy as well?

And my SLERP looks like this:

quaternion quaternion::slerp(quaternion q1, quaternion q2, float percent)
{
quaternion result;

float dot = q1.dotProduct(q2);              //Dot product - the cosine of the angle between 2 quats
if(dot < -1) dot = -1;                      //Clamp value to [-1,1], just to be sure
if(dot > 1) dot = 1;

if(dot < 0)                                  //If cos(angle) is <0 we negate the quaternion and dotp.
{                                            //(Go with smaller rotation)
q2=-q2;
dot=-dot;
}

if(dot > 0.99 && dot < 1.01)
{   //Lerp
result = q1 + ((q2 - q1) * percent);
result.normalize();
return result;
}

if(percent < 0.01)            //If percent is close to 0, return quat1
{result = q1;
return result;}

if(percent > 0.99)            //If percent is close to 1, return quat2
{
result=q2;
return result;
}

float a = acos(dot);          //Get angle between quats
result = (q1 * (sin((1.0 - percent) * a) / sin(a))) +  ((q2 * sin(percent * a)) / sin(a));
return result;
}


### #1keym

Posted 13 February 2013 - 04:45 AM

I'm interpolating in object space. Does this require rebuilding bone positions from hierarchy as well?

PARTNERS